##// END OF EJS Templates
docs: added admin task for bulk editing permissions.
marcink -
r4326:818f6cb9 default
parent child Browse files
Show More
@@ -1,61 +1,104 b''
1 1 .. _repo-admin-tasks:
2 2
3 3 Common Admin Tasks for Repositories
4 4 -----------------------------------
5 5
6 6
7 7 Manually Force Delete Repository
8 8 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9 9
10 10 In case of attached forks or pull-requests repositories should be archived.
11 11 Here is how to force delete a repository and remove all dependent objects
12 12
13 13
14 14 .. code-block:: bash
15 15 :dedent: 1
16 16
17 17 # starts the ishell interactive prompt
18 18 $ rccontrol ishell enterprise-1
19 19
20 20 .. code-block:: python
21 21 :dedent: 1
22 22
23 23 In [4]: from rhodecode.model.repo import RepoModel
24 24 In [3]: repo = Repository.get_by_repo_name('test_repos/repo_with_prs')
25 25 In [5]: RepoModel().delete(repo, forks='detach', pull_requests='delete')
26 26 In [6]: Session().commit()
27 27
28 28
29 29 Below is a fully automated example to force delete repositories reading from a
30 30 file where each line is a repository name. This can be executed via simple CLI command
31 31 without entering the interactive shell.
32 32
33 33 Save the below content as a file named `repo_delete_task.py`
34 34
35 35
36 36 .. code-block:: python
37 37 :dedent: 1
38 38
39 39 from rhodecode.model.db import *
40 40 from rhodecode.model.repo import RepoModel
41 41 with open('delete_repos.txt', 'rb') as f:
42 42 # read all lines from file
43 43 repos = f.readlines()
44 44 for repo_name in repos:
45 45 repo_name = repo_name.strip() # cleanup the name just in case
46 46 repo = Repository.get_by_repo_name(repo_name)
47 47 if not repo:
48 48 raise Exception('Repo with name {} not found'.format(repo_name))
49 49 RepoModel().delete(repo, forks='detach', pull_requests='delete')
50 50 Session().commit()
51 51 print('Removed repository {}'.format(repo_name))
52 52
53 53
54 54 The code above will read the names of repositories from a file called `delete_repos.txt`
55 55 Each lines should represent a single name e.g `repo_name_1` or `repo_group/repo_name_2`
56 56
57 57 Run this line from CLI to execute the code from the `repo_delete_task.py` file and
58 58 exit the ishell after the execution::
59 59
60 60 echo "%run repo_delete_task.py" | rccontrol ishell enterprise-1
61 61
62
63
64
65 Bulk edit permissions for all repositories or groups
66 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67
68 In case when a permissions should be applied in bulk here are two ways to apply
69 the permissions onto *all* repositories and/or repository groups.
70
71 1) Start by running the interactive ishell interface
72
73 .. code-block:: bash
74 :dedent: 1
75
76 # starts the ishell interactive prompt
77 $ rccontrol ishell enterprise-1
78
79
80 2a) Add user called 'admin' into all repositories with write permission.
81 Permissions can be also `repository.read`, `repository.admin`, `repository.none`
82
83 .. code-block:: python
84 :dedent: 1
85
86 In [1]: from rhodecode.model.repo import RepoModel
87 In [2]: user = User.get_by_username('admin')
88 In [3]: permission_name = 'repository.write'
89 In [4]: for repo in Repository.get_all():
90 ...: RepoModel().grant_user_permission(repo, user, permission_name)
91 ...: Session().commit()
92
93 2b) Add user called 'admin' into all repository groups with write permission.
94 Permissions can be also can be `group.read`, `group.admin`, `group.none`
95
96 .. code-block:: python
97 :dedent: 1
98
99 In [1]: from rhodecode.model.repo import RepoModel
100 In [2]: user = User.get_by_username('admin')
101 In [3]: permission_name = 'group.write'
102 In [4]: for repo_group in RepoGroup.get_all():
103 ...: RepoGroupModel().grant_user_permission(repo_group, user, permission_name)
104 ...: Session().commit() No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now