##// 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 .. _repo-admin-tasks:
1 .. _repo-admin-tasks:
2
2
3 Common Admin Tasks for Repositories
3 Common Admin Tasks for Repositories
4 -----------------------------------
4 -----------------------------------
5
5
6
6
7 Manually Force Delete Repository
7 Manually Force Delete Repository
8 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9
9
10 In case of attached forks or pull-requests repositories should be archived.
10 In case of attached forks or pull-requests repositories should be archived.
11 Here is how to force delete a repository and remove all dependent objects
11 Here is how to force delete a repository and remove all dependent objects
12
12
13
13
14 .. code-block:: bash
14 .. code-block:: bash
15 :dedent: 1
15 :dedent: 1
16
16
17 # starts the ishell interactive prompt
17 # starts the ishell interactive prompt
18 $ rccontrol ishell enterprise-1
18 $ rccontrol ishell enterprise-1
19
19
20 .. code-block:: python
20 .. code-block:: python
21 :dedent: 1
21 :dedent: 1
22
22
23 In [4]: from rhodecode.model.repo import RepoModel
23 In [4]: from rhodecode.model.repo import RepoModel
24 In [3]: repo = Repository.get_by_repo_name('test_repos/repo_with_prs')
24 In [3]: repo = Repository.get_by_repo_name('test_repos/repo_with_prs')
25 In [5]: RepoModel().delete(repo, forks='detach', pull_requests='delete')
25 In [5]: RepoModel().delete(repo, forks='detach', pull_requests='delete')
26 In [6]: Session().commit()
26 In [6]: Session().commit()
27
27
28
28
29 Below is a fully automated example to force delete repositories reading from a
29 Below is a fully automated example to force delete repositories reading from a
30 file where each line is a repository name. This can be executed via simple CLI command
30 file where each line is a repository name. This can be executed via simple CLI command
31 without entering the interactive shell.
31 without entering the interactive shell.
32
32
33 Save the below content as a file named `repo_delete_task.py`
33 Save the below content as a file named `repo_delete_task.py`
34
34
35
35
36 .. code-block:: python
36 .. code-block:: python
37 :dedent: 1
37 :dedent: 1
38
38
39 from rhodecode.model.db import *
39 from rhodecode.model.db import *
40 from rhodecode.model.repo import RepoModel
40 from rhodecode.model.repo import RepoModel
41 with open('delete_repos.txt', 'rb') as f:
41 with open('delete_repos.txt', 'rb') as f:
42 # read all lines from file
42 # read all lines from file
43 repos = f.readlines()
43 repos = f.readlines()
44 for repo_name in repos:
44 for repo_name in repos:
45 repo_name = repo_name.strip() # cleanup the name just in case
45 repo_name = repo_name.strip() # cleanup the name just in case
46 repo = Repository.get_by_repo_name(repo_name)
46 repo = Repository.get_by_repo_name(repo_name)
47 if not repo:
47 if not repo:
48 raise Exception('Repo with name {} not found'.format(repo_name))
48 raise Exception('Repo with name {} not found'.format(repo_name))
49 RepoModel().delete(repo, forks='detach', pull_requests='delete')
49 RepoModel().delete(repo, forks='detach', pull_requests='delete')
50 Session().commit()
50 Session().commit()
51 print('Removed repository {}'.format(repo_name))
51 print('Removed repository {}'.format(repo_name))
52
52
53
53
54 The code above will read the names of repositories from a file called `delete_repos.txt`
54 The code above will read the names of repositories from a file called `delete_repos.txt`
55 Each lines should represent a single name e.g `repo_name_1` or `repo_group/repo_name_2`
55 Each lines should represent a single name e.g `repo_name_1` or `repo_group/repo_name_2`
56
56
57 Run this line from CLI to execute the code from the `repo_delete_task.py` file and
57 Run this line from CLI to execute the code from the `repo_delete_task.py` file and
58 exit the ishell after the execution::
58 exit the ishell after the execution::
59
59
60 echo "%run repo_delete_task.py" | rccontrol ishell enterprise-1
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