# HG changeset patch # User RhodeCode Admin # Date 2022-10-06 08:26:05 # Node ID c2cdde730d13085cd7305c643705d465f44f7b01 # Parent 8a7a9443f58b14d1c691d57a24284b76dae179a4 docs: added new admin trick to bulk change owner of repository diff --git a/docs/admin/system_admin/admin-tricks.rst b/docs/admin/system_admin/admin-tricks.rst --- a/docs/admin/system_admin/admin-tricks.rst +++ b/docs/admin/system_admin/admin-tricks.rst @@ -262,3 +262,39 @@ ishell interface should be used. In [1]: repo = Repository.get_by_repo_name('SOME_REPO_NAME') In [2]: repo.archived = False In [3]: Session().add(repo);Session().commit() + + + + +Bulk change repository owner +^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Here's how one can change an owner of repository for an user who has been de activated. +Settings a new owner can be done via ishell for all repositories that past owner had. + +do run this script the interactive ishell interface should be used. + +.. code-block:: bash + + # Open iShell from the terminal + $ rccontrol ishell enterprise-1/community-1 + + +.. code-block:: python + + from rhodecode.model.db import User, Repository, Session + from rhodecode.model.permission import PermissionModel + + # replace old-owner and new-owner with your exact users + old_owner = User.get_by_username('old-owner') + new_owner = User.get_by_username('new-owner') + + # list of users we need to "flush" permissions + affected_user_ids = [new_owner.user_id, old_owner.user_id] + + for repo in Repository.get_all_repos(user_id=old_owner.user_id): + repo.user = new_owner + Session().add(repo) + Session().commit() + + PermissionModel().trigger_permission_flush(affected_user_ids)