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