##// END OF EJS Templates
protected againts changing default user.
marcink -
r314:0d26d46b default
parent child Browse files
Show More
@@ -26,9 +26,12 b' Model for users'
26
26
27 from pylons_app.model.db import User
27 from pylons_app.model.db import User
28 from pylons_app.model.meta import Session
28 from pylons_app.model.meta import Session
29 from pylons.i18n.translation import _
29 import logging
30 import logging
30 log = logging.getLogger(__name__)
31 log = logging.getLogger(__name__)
31
32
33 class DefaultUserException(Exception):pass
34
32 class UserModel(object):
35 class UserModel(object):
33
36
34 def __init__(self):
37 def __init__(self):
@@ -53,6 +56,10 b' class UserModel(object):'
53 def update(self, id, form_data):
56 def update(self, id, form_data):
54 try:
57 try:
55 new_user = self.sa.query(User).get(id)
58 new_user = self.sa.query(User).get(id)
59 if new_user.username == 'default':
60 raise DefaultUserException(
61 _("You can't Edit this user since it's"
62 " crucial for entire application"))
56 for k, v in form_data.items():
63 for k, v in form_data.items():
57 if k == 'new_password' and v != '':
64 if k == 'new_password' and v != '':
58
65
@@ -68,8 +75,15 b' class UserModel(object):'
68 raise
75 raise
69
76
70 def delete(self, id):
77 def delete(self, id):
78
71 try:
79 try:
72 self.sa.delete(self.sa.query(User).get(id))
80
81 user = self.sa.query(User).get(id)
82 if user.username == 'default':
83 raise DefaultUserException(
84 _("You can't remove this user since it's"
85 " crucial for entire application"))
86 self.sa.delete(user)
73 self.sa.commit()
87 self.sa.commit()
74 except Exception as e:
88 except Exception as e:
75 log.error(e)
89 log.error(e)
General Comments 0
You need to be logged in to leave comments. Login now