Show More
@@ -79,6 +79,7 b' def _cruserhook(*args, **kwargs):' | |||||
79 | :param password: |
|
79 | :param password: | |
80 | :param emails: |
|
80 | :param emails: | |
81 | :param inherit_default_permissions: |
|
81 | :param inherit_default_permissions: | |
|
82 | :param created_by: | |||
82 | """ |
|
83 | """ | |
83 | return 0 |
|
84 | return 0 | |
84 | CREATE_USER_HOOK = _cruserhook |
|
85 | CREATE_USER_HOOK = _cruserhook | |
@@ -138,6 +139,7 b' def _dluserhook(*args, **kwargs):' | |||||
138 | :param password: |
|
139 | :param password: | |
139 | :param emails: |
|
140 | :param emails: | |
140 | :param inherit_default_permissions: |
|
141 | :param inherit_default_permissions: | |
|
142 | :param deleted_by: | |||
141 | """ |
|
143 | """ | |
142 | return 0 |
|
144 | return 0 | |
143 | DELETE_USER_HOOK = _dluserhook |
|
145 | DELETE_USER_HOOK = _dluserhook |
@@ -252,7 +252,7 b' def log_create_repository(repository_dic' | |||||
252 | return 0 |
|
252 | return 0 | |
253 |
|
253 | |||
254 |
|
254 | |||
255 | def log_create_user(user_dict, **kwargs): |
|
255 | def log_create_user(user_dict, created_by, **kwargs): | |
256 | """ |
|
256 | """ | |
257 | Post create user Hook. This is a dummy function for admins to re-use |
|
257 | Post create user Hook. This is a dummy function for admins to re-use | |
258 | if needed. It's taken from rhodecode-extensions module and executed |
|
258 | if needed. It's taken from rhodecode-extensions module and executed | |
@@ -286,7 +286,7 b' def log_create_user(user_dict, **kwargs)' | |||||
286 | from rhodecode import EXTENSIONS |
|
286 | from rhodecode import EXTENSIONS | |
287 | callback = getattr(EXTENSIONS, 'CREATE_USER_HOOK', None) |
|
287 | callback = getattr(EXTENSIONS, 'CREATE_USER_HOOK', None) | |
288 | if isfunction(callback): |
|
288 | if isfunction(callback): | |
289 | return callback(**user_dict) |
|
289 | return callback(created_by=created_by, **user_dict) | |
290 |
|
290 | |||
291 | return 0 |
|
291 | return 0 | |
292 |
|
292 | |||
@@ -329,7 +329,7 b' def log_delete_repository(repository_dic' | |||||
329 | return 0 |
|
329 | return 0 | |
330 |
|
330 | |||
331 |
|
331 | |||
332 | def log_delete_user(user_dict, **kwargs): |
|
332 | def log_delete_user(user_dict, deleted_by, **kwargs): | |
333 | """ |
|
333 | """ | |
334 | Post delete user Hook. This is a dummy function for admins to re-use |
|
334 | Post delete user Hook. This is a dummy function for admins to re-use | |
335 | if needed. It's taken from rhodecode-extensions module and executed |
|
335 | if needed. It's taken from rhodecode-extensions module and executed | |
@@ -363,7 +363,7 b' def log_delete_user(user_dict, **kwargs)' | |||||
363 | from rhodecode import EXTENSIONS |
|
363 | from rhodecode import EXTENSIONS | |
364 | callback = getattr(EXTENSIONS, 'DELETE_USER_HOOK', None) |
|
364 | callback = getattr(EXTENSIONS, 'DELETE_USER_HOOK', None) | |
365 | if isfunction(callback): |
|
365 | if isfunction(callback): | |
366 | return callback(**user_dict) |
|
366 | return callback(deleted_by=deleted_by, **user_dict) | |
367 |
|
367 | |||
368 | return 0 |
|
368 | return 0 | |
369 |
|
369 |
@@ -33,7 +33,7 b' from pylons.i18n.translation import _' | |||||
33 | from sqlalchemy.exc import DatabaseError |
|
33 | from sqlalchemy.exc import DatabaseError | |
34 | from sqlalchemy.orm import joinedload |
|
34 | from sqlalchemy.orm import joinedload | |
35 |
|
35 | |||
36 | from rhodecode.lib.utils2 import safe_unicode, generate_api_key |
|
36 | from rhodecode.lib.utils2 import safe_unicode, generate_api_key, get_current_rhodecode_user | |
37 | from rhodecode.lib.caching_query import FromCache |
|
37 | from rhodecode.lib.caching_query import FromCache | |
38 | from rhodecode.model import BaseModel |
|
38 | from rhodecode.model import BaseModel | |
39 | from rhodecode.model.db import User, UserRepoToPerm, Repository, Permission, \ |
|
39 | from rhodecode.model.db import User, UserRepoToPerm, Repository, Permission, \ | |
@@ -81,7 +81,9 b' class UserModel(BaseModel):' | |||||
81 | def get_by_api_key(self, api_key, cache=False): |
|
81 | def get_by_api_key(self, api_key, cache=False): | |
82 | return User.get_by_api_key(api_key, cache) |
|
82 | return User.get_by_api_key(api_key, cache) | |
83 |
|
83 | |||
84 | def create(self, form_data): |
|
84 | def create(self, form_data, cur_user=None): | |
|
85 | if not cur_user: | |||
|
86 | cur_user = getattr(get_current_rhodecode_user(), 'username', '?') | |||
85 | from rhodecode.lib.auth import get_crypt_password |
|
87 | from rhodecode.lib.auth import get_crypt_password | |
86 | try: |
|
88 | try: | |
87 | new_user = User() |
|
89 | new_user = User() | |
@@ -96,14 +98,14 b' class UserModel(BaseModel):' | |||||
96 | self.sa.add(new_user) |
|
98 | self.sa.add(new_user) | |
97 |
|
99 | |||
98 | from rhodecode.lib.hooks import log_create_user |
|
100 | from rhodecode.lib.hooks import log_create_user | |
99 | log_create_user(new_user.get_dict()) |
|
101 | log_create_user(new_user.get_dict(), cur_user) | |
100 | return new_user |
|
102 | return new_user | |
101 | except Exception: |
|
103 | except Exception: | |
102 | log.error(traceback.format_exc()) |
|
104 | log.error(traceback.format_exc()) | |
103 | raise |
|
105 | raise | |
104 |
|
106 | |||
105 | def create_or_update(self, username, password, email, firstname='', |
|
107 | def create_or_update(self, username, password, email, firstname='', | |
106 | lastname='', active=True, admin=False, ldap_dn=None): |
|
108 | lastname='', active=True, admin=False, ldap_dn=None, cur_user=None): | |
107 | """ |
|
109 | """ | |
108 | Creates a new instance if not found, or updates current one |
|
110 | Creates a new instance if not found, or updates current one | |
109 |
|
111 | |||
@@ -117,6 +119,8 b' class UserModel(BaseModel):' | |||||
117 | :param admin: |
|
119 | :param admin: | |
118 | :param ldap_dn: |
|
120 | :param ldap_dn: | |
119 | """ |
|
121 | """ | |
|
122 | if not cur_user: | |||
|
123 | cur_user = getattr(get_current_rhodecode_user(), 'username', '?') | |||
120 |
|
124 | |||
121 | from rhodecode.lib.auth import get_crypt_password |
|
125 | from rhodecode.lib.auth import get_crypt_password | |
122 |
|
126 | |||
@@ -147,19 +151,21 b' class UserModel(BaseModel):' | |||||
147 |
|
151 | |||
148 | if not edit: |
|
152 | if not edit: | |
149 | from rhodecode.lib.hooks import log_create_user |
|
153 | from rhodecode.lib.hooks import log_create_user | |
150 | log_create_user(new_user.get_dict()) |
|
154 | log_create_user(new_user.get_dict(), cur_user) | |
151 | return new_user |
|
155 | return new_user | |
152 | except (DatabaseError,): |
|
156 | except (DatabaseError,): | |
153 | log.error(traceback.format_exc()) |
|
157 | log.error(traceback.format_exc()) | |
154 | raise |
|
158 | raise | |
155 |
|
159 | |||
156 | def create_for_container_auth(self, username, attrs): |
|
160 | def create_for_container_auth(self, username, attrs, cur_user=None): | |
157 | """ |
|
161 | """ | |
158 | Creates the given user if it's not already in the database |
|
162 | Creates the given user if it's not already in the database | |
159 |
|
163 | |||
160 | :param username: |
|
164 | :param username: | |
161 | :param attrs: |
|
165 | :param attrs: | |
162 | """ |
|
166 | """ | |
|
167 | if not cur_user: | |||
|
168 | cur_user = getattr(get_current_rhodecode_user(), 'username', '?') | |||
163 | if self.get_by_username(username, case_insensitive=True) is None: |
|
169 | if self.get_by_username(username, case_insensitive=True) is None: | |
164 |
|
170 | |||
165 | # autogenerate email for container account without one |
|
171 | # autogenerate email for container account without one | |
@@ -178,7 +184,7 b' class UserModel(BaseModel):' | |||||
178 | self.sa.add(new_user) |
|
184 | self.sa.add(new_user) | |
179 |
|
185 | |||
180 | from rhodecode.lib.hooks import log_create_user |
|
186 | from rhodecode.lib.hooks import log_create_user | |
181 | log_create_user(new_user.get_dict()) |
|
187 | log_create_user(new_user.get_dict(), cur_user) | |
182 | return new_user |
|
188 | return new_user | |
183 | except (DatabaseError,): |
|
189 | except (DatabaseError,): | |
184 | log.error(traceback.format_exc()) |
|
190 | log.error(traceback.format_exc()) | |
@@ -188,7 +194,7 b' class UserModel(BaseModel):' | |||||
188 | ' for container auth.', username) |
|
194 | ' for container auth.', username) | |
189 | return None |
|
195 | return None | |
190 |
|
196 | |||
191 | def create_ldap(self, username, password, user_dn, attrs): |
|
197 | def create_ldap(self, username, password, user_dn, attrs, cur_user=None): | |
192 | """ |
|
198 | """ | |
193 | Checks if user is in database, if not creates this user marked |
|
199 | Checks if user is in database, if not creates this user marked | |
194 | as ldap user |
|
200 | as ldap user | |
@@ -198,6 +204,8 b' class UserModel(BaseModel):' | |||||
198 | :param user_dn: |
|
204 | :param user_dn: | |
199 | :param attrs: |
|
205 | :param attrs: | |
200 | """ |
|
206 | """ | |
|
207 | if not cur_user: | |||
|
208 | cur_user = getattr(get_current_rhodecode_user(), 'username', '?') | |||
201 | from rhodecode.lib.auth import get_crypt_password |
|
209 | from rhodecode.lib.auth import get_crypt_password | |
202 | log.debug('Checking for such ldap account in RhodeCode database') |
|
210 | log.debug('Checking for such ldap account in RhodeCode database') | |
203 | if self.get_by_username(username, case_insensitive=True) is None: |
|
211 | if self.get_by_username(username, case_insensitive=True) is None: | |
@@ -221,7 +229,7 b' class UserModel(BaseModel):' | |||||
221 | self.sa.add(new_user) |
|
229 | self.sa.add(new_user) | |
222 |
|
230 | |||
223 | from rhodecode.lib.hooks import log_create_user |
|
231 | from rhodecode.lib.hooks import log_create_user | |
224 | log_create_user(new_user.get_dict()) |
|
232 | log_create_user(new_user.get_dict(), cur_user) | |
225 | return new_user |
|
233 | return new_user | |
226 | except (DatabaseError,): |
|
234 | except (DatabaseError,): | |
227 | log.error(traceback.format_exc()) |
|
235 | log.error(traceback.format_exc()) | |
@@ -307,7 +315,9 b' class UserModel(BaseModel):' | |||||
307 | log.error(traceback.format_exc()) |
|
315 | log.error(traceback.format_exc()) | |
308 | raise |
|
316 | raise | |
309 |
|
317 | |||
310 | def delete(self, user): |
|
318 | def delete(self, user, cur_user=None): | |
|
319 | if not cur_user: | |||
|
320 | cur_user = getattr(get_current_rhodecode_user(), 'username', '?') | |||
311 | user = self._get_user(user) |
|
321 | user = self._get_user(user) | |
312 |
|
322 | |||
313 | try: |
|
323 | try: | |
@@ -326,7 +336,7 b' class UserModel(BaseModel):' | |||||
326 | self.sa.delete(user) |
|
336 | self.sa.delete(user) | |
327 |
|
337 | |||
328 | from rhodecode.lib.hooks import log_delete_user |
|
338 | from rhodecode.lib.hooks import log_delete_user | |
329 | log_delete_user(user.get_dict()) |
|
339 | log_delete_user(user.get_dict(), cur_user) | |
330 | except Exception: |
|
340 | except Exception: | |
331 | log.error(traceback.format_exc()) |
|
341 | log.error(traceback.format_exc()) | |
332 | raise |
|
342 | raise |
General Comments 0
You need to be logged in to leave comments.
Login now