##// END OF EJS Templates
permissions: flush permissions on owner changes for repo and repo groups.
milka -
r4662:2b36afd5 default
parent child Browse files
Show More
@@ -46,6 +46,7 b' from rhodecode.model.db import ('
46 Session, Repository, UserRepoToPerm, UserGroupRepoToPerm,
46 Session, Repository, UserRepoToPerm, UserGroupRepoToPerm,
47 UserRepoGroupToPerm, UserGroupRepoGroupToPerm, User, Permission,
47 UserRepoGroupToPerm, UserGroupRepoGroupToPerm, User, Permission,
48 Statistics, UserGroup, RepoGroup, RepositoryField, UserLog)
48 Statistics, UserGroup, RepoGroup, RepositoryField, UserLog)
49 from rhodecode.model.permission import PermissionModel
49 from rhodecode.model.settings import VcsSettingsModel
50 from rhodecode.model.settings import VcsSettingsModel
50
51
51 log = logging.getLogger(__name__)
52 log = logging.getLogger(__name__)
@@ -422,8 +423,15 b' class RepoModel(BaseModel):'
422 try:
423 try:
423 cur_repo = self._get_repo(repo)
424 cur_repo = self._get_repo(repo)
424 source_repo_name = cur_repo.repo_name
425 source_repo_name = cur_repo.repo_name
426
427 affected_user_ids = []
425 if 'user' in kwargs:
428 if 'user' in kwargs:
426 cur_repo.user = User.get_by_username(kwargs['user'])
429 old_owner_id = cur_repo.user.user_id
430 new_owner = User.get_by_username(kwargs['user'])
431 cur_repo.user = new_owner
432
433 if old_owner_id != new_owner.user_id:
434 affected_user_ids = [new_owner.user_id, old_owner_id]
427
435
428 if 'repo_group' in kwargs:
436 if 'repo_group' in kwargs:
429 cur_repo.group = RepoGroup.get(kwargs['repo_group'])
437 cur_repo.group = RepoGroup.get(kwargs['repo_group'])
@@ -474,6 +482,9 b' class RepoModel(BaseModel):'
474 self._rename_filesystem_repo(
482 self._rename_filesystem_repo(
475 old=source_repo_name, new=new_name)
483 old=source_repo_name, new=new_name)
476
484
485 if affected_user_ids:
486 PermissionModel().trigger_permission_flush(affected_user_ids)
487
477 return cur_repo
488 return cur_repo
478 except Exception:
489 except Exception:
479 log.error(traceback.format_exc())
490 log.error(traceback.format_exc())
@@ -39,6 +39,7 b' from rhodecode.model import BaseModel'
39 from rhodecode.model.db import (_hash_key, func, or_, in_filter_generator,
39 from rhodecode.model.db import (_hash_key, func, or_, in_filter_generator,
40 Session, RepoGroup, UserRepoGroupToPerm, User, Permission, UserGroupRepoGroupToPerm,
40 Session, RepoGroup, UserRepoGroupToPerm, User, Permission, UserGroupRepoGroupToPerm,
41 UserGroup, Repository)
41 UserGroup, Repository)
42 from rhodecode.model.permission import PermissionModel
42 from rhodecode.model.settings import VcsSettingsModel, SettingsModel
43 from rhodecode.model.settings import VcsSettingsModel, SettingsModel
43 from rhodecode.lib.caching_query import FromCache
44 from rhodecode.lib.caching_query import FromCache
44 from rhodecode.lib.utils2 import action_logger_generic
45 from rhodecode.lib.utils2 import action_logger_generic
@@ -531,8 +532,14 b' class RepoGroupModel(BaseModel):'
531
532
532 new_path = repo_group.full_path
533 new_path = repo_group.full_path
533
534
535 affected_user_ids = []
534 if 'user' in form_data:
536 if 'user' in form_data:
535 repo_group.user = User.get_by_username(form_data['user'])
537 old_owner_id = repo_group.user.user_id
538 new_owner = User.get_by_username(form_data['user'])
539 repo_group.user = new_owner
540
541 if old_owner_id != new_owner.user_id:
542 affected_user_ids = [new_owner.user_id, old_owner_id]
536
543
537 self.sa.add(repo_group)
544 self.sa.add(repo_group)
538
545
@@ -566,6 +573,9 b' class RepoGroupModel(BaseModel):'
566 # Trigger update event.
573 # Trigger update event.
567 events.trigger(events.RepoGroupUpdateEvent(repo_group))
574 events.trigger(events.RepoGroupUpdateEvent(repo_group))
568
575
576 if affected_user_ids:
577 PermissionModel().trigger_permission_flush(affected_user_ids)
578
569 return repo_group
579 return repo_group
570 except Exception:
580 except Exception:
571 log.error(traceback.format_exc())
581 log.error(traceback.format_exc())
General Comments 0
You need to be logged in to leave comments. Login now