Mercurial > kallithea
comparison rhodecode/model/user.py @ 1594:9dae92a65e40 beta
fixes #288
- added group management into non admin repo settings form
- fixes also issues with groups after API codes merge
- all tests passes ok.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 24 Oct 2011 22:40:43 +0200 |
parents | 92a4f7c496a5 |
children | 9353189b7675 b8cde49f5e5b 95c3e33ef32e |
comparison
equal
deleted
inserted
replaced
1593:92a4f7c496a5 | 1594:9dae92a65e40 |
---|---|
47 'repository.write': 3, | 47 'repository.write': 3, |
48 'repository.admin': 3} | 48 'repository.admin': 3} |
49 | 49 |
50 | 50 |
51 class UserModel(BaseModel): | 51 class UserModel(BaseModel): |
52 def get(self, user_id, cache = False): | 52 def get(self, user_id, cache=False): |
53 user = self.sa.query(User) | 53 user = self.sa.query(User) |
54 if cache: | 54 if cache: |
55 user = user.options(FromCache("sql_cache_short", | 55 user = user.options(FromCache("sql_cache_short", |
56 "get_user_%s" % user_id)) | 56 "get_user_%s" % user_id)) |
57 return user.get(user_id) | 57 return user.get(user_id) |
58 | 58 |
59 def get_by_username(self, username, cache = False, case_insensitive = False): | 59 def get_by_username(self, username, cache=False, case_insensitive=False): |
60 | 60 |
61 if case_insensitive: | 61 if case_insensitive: |
62 user = self.sa.query(User).filter(User.username.ilike(username)) | 62 user = self.sa.query(User).filter(User.username.ilike(username)) |
63 else: | 63 else: |
64 user = self.sa.query(User)\ | 64 user = self.sa.query(User)\ |
66 if cache: | 66 if cache: |
67 user = user.options(FromCache("sql_cache_short", | 67 user = user.options(FromCache("sql_cache_short", |
68 "get_user_%s" % username)) | 68 "get_user_%s" % username)) |
69 return user.scalar() | 69 return user.scalar() |
70 | 70 |
71 def get_by_api_key(self, api_key, cache = False): | 71 def get_by_api_key(self, api_key, cache=False): |
72 | 72 |
73 user = self.sa.query(User)\ | 73 user = self.sa.query(User)\ |
74 .filter(User.api_key == api_key) | 74 .filter(User.api_key == api_key) |
75 if cache: | 75 if cache: |
76 user = user.options(FromCache("sql_cache_short", | 76 user = user.options(FromCache("sql_cache_short", |
94 | 94 |
95 def create_ldap(self, username, password, user_dn, attrs): | 95 def create_ldap(self, username, password, user_dn, attrs): |
96 """ | 96 """ |
97 Checks if user is in database, if not creates this user marked | 97 Checks if user is in database, if not creates this user marked |
98 as ldap user | 98 as ldap user |
99 | |
99 :param username: | 100 :param username: |
100 :param password: | 101 :param password: |
101 :param user_dn: | 102 :param user_dn: |
102 :param attrs: | 103 :param attrs: |
103 """ | 104 """ |
104 from rhodecode.lib.auth import get_crypt_password | 105 from rhodecode.lib.auth import get_crypt_password |
105 log.debug('Checking for such ldap account in RhodeCode database') | 106 log.debug('Checking for such ldap account in RhodeCode database') |
106 if self.get_by_username(username, case_insensitive = True) is None: | 107 if self.get_by_username(username, case_insensitive=True) is None: |
107 try: | 108 try: |
108 new_user = User() | 109 new_user = User() |
109 # add ldap account always lowercase | 110 # add ldap account always lowercase |
110 new_user.username = username.lower() | 111 new_user.username = username.lower() |
111 new_user.password = get_crypt_password(password) | 112 new_user.password = get_crypt_password(password) |
150 self.sa.rollback() | 151 self.sa.rollback() |
151 raise | 152 raise |
152 | 153 |
153 def update(self, user_id, form_data): | 154 def update(self, user_id, form_data): |
154 try: | 155 try: |
155 user = self.get(user_id, cache = False) | 156 user = self.get(user_id, cache=False) |
156 if user.username == 'default': | 157 if user.username == 'default': |
157 raise DefaultUserException( | 158 raise DefaultUserException( |
158 _("You can't Edit this user since it's" | 159 _("You can't Edit this user since it's" |
159 " crucial for entire application")) | 160 " crucial for entire application")) |
160 | 161 |
172 self.sa.rollback() | 173 self.sa.rollback() |
173 raise | 174 raise |
174 | 175 |
175 def update_my_account(self, user_id, form_data): | 176 def update_my_account(self, user_id, form_data): |
176 try: | 177 try: |
177 user = self.get(user_id, cache = False) | 178 user = self.get(user_id, cache=False) |
178 if user.username == 'default': | 179 if user.username == 'default': |
179 raise DefaultUserException( | 180 raise DefaultUserException( |
180 _("You can't Edit this user since it's" | 181 _("You can't Edit this user since it's" |
181 " crucial for entire application")) | 182 " crucial for entire application")) |
182 for k, v in form_data.items(): | 183 for k, v in form_data.items(): |
194 self.sa.rollback() | 195 self.sa.rollback() |
195 raise | 196 raise |
196 | 197 |
197 def delete(self, user_id): | 198 def delete(self, user_id): |
198 try: | 199 try: |
199 user = self.get(user_id, cache = False) | 200 user = self.get(user_id, cache=False) |
200 if user.username == 'default': | 201 if user.username == 'default': |
201 raise DefaultUserException( | 202 raise DefaultUserException( |
202 _("You can't remove this user since it's" | 203 _("You can't remove this user since it's" |
203 " crucial for entire application")) | 204 " crucial for entire application")) |
204 if user.repositories: | 205 if user.repositories: |
220 | 221 |
221 def reset_password(self, data): | 222 def reset_password(self, data): |
222 from rhodecode.lib.celerylib import tasks, run_task | 223 from rhodecode.lib.celerylib import tasks, run_task |
223 run_task(tasks.reset_user_password, data['email']) | 224 run_task(tasks.reset_user_password, data['email']) |
224 | 225 |
225 def fill_data(self, auth_user, user_id = None, api_key = None): | 226 def fill_data(self, auth_user, user_id=None, api_key=None): |
226 """ | 227 """ |
227 Fetches auth_user by user_id,or api_key if present. | 228 Fetches auth_user by user_id,or api_key if present. |
228 Fills auth_user attributes with those taken from database. | 229 Fills auth_user attributes with those taken from database. |
229 Additionally set's is_authenitated if lookup fails | 230 Additionally set's is_authenitated if lookup fails |
230 present in database | 231 present in database |
266 user.permissions['global'] = set() | 267 user.permissions['global'] = set() |
267 | 268 |
268 #====================================================================== | 269 #====================================================================== |
269 # fetch default permissions | 270 # fetch default permissions |
270 #====================================================================== | 271 #====================================================================== |
271 default_user = self.get_by_username('default', cache = True) | 272 default_user = self.get_by_username('default', cache=True) |
272 | 273 |
273 default_perms = self.sa.query(RepoToPerm, Repository, Permission)\ | 274 default_perms = self.sa.query(RepoToPerm, Repository, Permission)\ |
274 .join((Repository, RepoToPerm.repository_id == | 275 .join((Repository, RepoToPerm.repository_id == |
275 Repository.repo_id))\ | 276 Repository.repo_id))\ |
276 .join((Permission, RepoToPerm.permission_id == | 277 .join((Permission, RepoToPerm.permission_id == |
384 if PERM_WEIGHTS[p] > PERM_WEIGHTS[cur_perm]: | 385 if PERM_WEIGHTS[p] > PERM_WEIGHTS[cur_perm]: |
385 user.permissions['repositories'][perm.UsersGroupRepoToPerm. | 386 user.permissions['repositories'][perm.UsersGroupRepoToPerm. |
386 repository.repo_name] = p | 387 repository.repo_name] = p |
387 | 388 |
388 return user | 389 return user |
390 |