##// END OF EJS Templates
fix(docs): fixed docs build
super-admin -
r5241:d4beb7f7 default
parent child Browse files
Show More
@@ -1,118 +1,119 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 62
63 63
64 64
65 65 Bulk edit permissions for all repositories or groups
66 66 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67 67
68 68 In case when a permissions should be applied in bulk here are two ways to apply
69 69 the permissions onto *all* repositories and/or repository groups.
70 70
71 71 1) Start by running the interactive ishell interface
72 72
73 73 .. code-block:: bash
74 74 :dedent: 1
75 75
76 76 # starts the ishell interactive prompt
77 77 $ rccontrol ishell enterprise-1
78 78
79 79
80 80 2a) Add user called 'admin' into all repositories with write permission.
81 81 Permissions can be also `repository.read`, `repository.admin`, `repository.none`
82 82
83
83 84 .. code-block:: python
84 :dedent: 1
85 :dedent:
85 86
86 87 In [1]: from rhodecode.model.repo import RepoModel
87 88 In [2]: user = User.get_by_username('admin')
88 89 In [3]: permission_name = 'repository.write'
89 90 In [4]: for repo in Repository.get_all():
90 91 ...: RepoModel().grant_user_permission(repo, user, permission_name)
91 92 ...: Session().commit()
92 93
93 94 2b) Add user called 'admin' into all repository groups with write permission.
94 95 Permissions can be also can be `group.read`, `group.admin`, `group.none`
95 96
96 97 .. code-block:: python
97 :dedent: 1
98 :dedent:
98 99
99 100 In [1]: from rhodecode.model.repo import RepoModel
100 101 In [2]: user = User.get_by_username('admin')
101 102 In [3]: permission_name = 'group.write'
102 103 In [4]: for repo_group in RepoGroup.get_all():
103 104 ...: RepoGroupModel().grant_user_permission(repo_group, user, permission_name)
104 105 ...: Session().commit()
105 106
106 107
107 108 Delete a problematic pull request
108 109 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
109 110
110 111 .. code-block:: python
111 :dedent: 1
112 :dedent:
112 113
113 114 In [1]: from rhodecode.model.pull_request import PullRequestModel
114 115 In [2]: pullrequest_id = 123
115 116 In [3]: pr = PullRequest.get(pullrequest_id)
116 117 In [4]: super_admin = User.get_first_super_admin()
117 118 In [5]: PullRequestModel().delete(pr, super_admin)
118 119 In [6]: Session().commit()
General Comments 0
You need to be logged in to leave comments. Login now