Show More
@@ -1,174 +1,174 b'' | |||||
1 | ========= |
|
1 | ========= | |
2 | RhodeCode |
|
2 | RhodeCode | |
3 | ========= |
|
3 | ========= | |
4 |
|
4 | |||
5 | About |
|
5 | About | |
6 | ----- |
|
6 | ----- | |
7 |
|
7 | |||
8 | ``RhodeCode`` is a fast and powerful management tool for Mercurial_ and GIT_ |
|
8 | ``RhodeCode`` is a fast and powerful management tool for Mercurial_ and GIT_ | |
9 | with a built in push/pull server and full text search and code-review. |
|
9 | with a built in push/pull server and full text search and code-review. | |
10 | It works on http/https and has a built in permission/authentication system with |
|
10 | It works on http/https and has a built in permission/authentication system with | |
11 | the ability to authenticate via LDAP or ActiveDirectory. RhodeCode also provides |
|
11 | the ability to authenticate via LDAP or ActiveDirectory. RhodeCode also provides | |
12 | simple API so it's easy integrable with existing external systems. |
|
12 | simple API so it's easy integrable with existing external systems. | |
13 |
|
13 | |||
14 | RhodeCode is similar in some respects to github_ or bitbucket_, |
|
14 | RhodeCode is similar in some respects to github_ or bitbucket_, | |
15 | however RhodeCode can be run as standalone hosted application on your own server. |
|
15 | however RhodeCode can be run as standalone hosted application on your own server. | |
16 | It is open source and donation ware and focuses more on providing a customized, |
|
16 | It is open source and donation ware and focuses more on providing a customized, | |
17 | self administered interface for Mercurial_ and GIT_ repositories. |
|
17 | self administered interface for Mercurial_ and GIT_ repositories. | |
18 | RhodeCode works on *nix systems and Windows it is powered by a vcs_ library |
|
18 | RhodeCode works on *nix systems and Windows it is powered by a vcs_ library | |
19 | that Lukasz Balcerzak and Marcin Kuzminski created to handle multiple |
|
19 | that Lukasz Balcerzak and Marcin Kuzminski created to handle multiple | |
20 | different version control systems. |
|
20 | different version control systems. | |
21 |
|
21 | |||
22 | RhodeCode uses `PEP386 versioning http://www.python.org/dev/peps/pep-0386/`_ |
|
22 | RhodeCode uses `PEP386 versioning http://www.python.org/dev/peps/pep-0386/`_ | |
23 |
|
23 | |||
24 | Installation |
|
24 | Installation | |
25 | ------------ |
|
25 | ------------ | |
26 | Stable releases of RhodeCode are best installed via:: |
|
26 | Stable releases of RhodeCode are best installed via:: | |
27 |
|
27 | |||
28 | easy_install rhodecode |
|
28 | easy_install rhodecode | |
29 |
|
29 | |||
30 | Or:: |
|
30 | Or:: | |
31 |
|
31 | |||
32 | pip install rhodecode |
|
32 | pip install rhodecode | |
33 |
|
33 | |||
34 | Detailed instructions and links may be found on the Installation page. |
|
34 | Detailed instructions and links may be found on the Installation page. | |
35 |
|
35 | |||
36 | Please visit http://packages.python.org/RhodeCode/installation.html for |
|
36 | Please visit http://packages.python.org/RhodeCode/installation.html for | |
37 | more details |
|
37 | more details | |
38 |
|
38 | |||
39 | RhodeCode demo |
|
39 | RhodeCode demo | |
40 | -------------- |
|
40 | -------------- | |
41 |
|
41 | |||
42 | http://demo.rhodecode.org |
|
42 | http://demo.rhodecode.org | |
43 |
|
43 | |||
44 | The default access is anonymous but you can login to an administrative account |
|
44 | The default access is anonymous but you can login to an administrative account | |
45 | using the following credentials: |
|
45 | using the following credentials: | |
46 |
|
46 | |||
47 | - username: demo |
|
47 | - username: demo | |
48 | - password: demo12 |
|
48 | - password: demo12 | |
49 |
|
49 | |||
50 | Source code |
|
50 | Source code | |
51 | ----------- |
|
51 | ----------- | |
52 |
|
52 | |||
53 | The latest sources can be obtained from official RhodeCode instance |
|
53 | The latest sources can be obtained from official RhodeCode instance | |
54 | https://secure.rhodecode.org |
|
54 | https://secure.rhodecode.org | |
55 |
|
55 | |||
56 |
|
56 | |||
57 | MIRRORS: |
|
57 | MIRRORS: | |
58 |
|
58 | |||
59 | Issue tracker and sources at bitbucket_ |
|
59 | Issue tracker and sources at bitbucket_ | |
60 |
|
60 | |||
61 | http://bitbucket.org/marcinkuzminski/rhodecode |
|
61 | http://bitbucket.org/marcinkuzminski/rhodecode | |
62 |
|
62 | |||
63 | Sources at github_ |
|
63 | Sources at github_ | |
64 |
|
64 | |||
65 | https://github.com/marcinkuzminski/rhodecode |
|
65 | https://github.com/marcinkuzminski/rhodecode | |
66 |
|
66 | |||
67 |
|
67 | |||
68 | RhodeCode Features |
|
68 | RhodeCode Features | |
69 | ------------------ |
|
69 | ------------------ | |
70 |
|
70 | |||
71 | - Has its own middleware to handle mercurial_ protocol requests. |
|
71 | - Has its own middleware to handle mercurial_ protocol requests. | |
72 | Each request can be logged and authenticated. |
|
72 | Each request can be logged and authenticated. | |
73 | - Runs on threads unlike hgweb. You can make multiple pulls/pushes simultaneous. |
|
73 | - Runs on threads unlike hgweb. You can make multiple pulls/pushes simultaneous. | |
74 | Supports http/https and LDAP |
|
74 | Supports http/https and LDAP | |
75 | - Full permissions (private/read/write/admin) and authentication per project. |
|
75 | - Full permissions (private/read/write/admin) and authentication per project. | |
76 | One account for web interface and mercurial_ push/pull/clone operations. |
|
76 | One account for web interface and mercurial_ push/pull/clone operations. | |
77 | - Have built in users groups for easier permission management |
|
77 | - Have built in users groups for easier permission management | |
78 | - Repository groups let you group repos and manage them easier. |
|
78 | - Repository groups let you group repos and manage them easier. | |
79 | - Users can fork other users repo. RhodeCode have also compare view to see |
|
79 | - Users can fork other users repo. RhodeCode have also compare view to see | |
80 | combined changeset for all changeset made within single push. |
|
80 | combined changeset for all changeset made within single push. | |
81 | - Build in commit-api let's you add, edit and commit files right from RhodeCode |
|
81 | - Build in commit-api let's you add, edit and commit files right from RhodeCode | |
82 | interface using simple editor or upload form for binaries. |
|
82 | interface using simple editor or upload form for binaries. | |
83 | - Mako templates let's you customize the look and feel of the application. |
|
83 | - Mako templates let's you customize the look and feel of the application. | |
84 | - Beautiful diffs, annotations and source code browsing all colored by pygments. |
|
84 | - Beautiful diffs, annotations and source code browsing all colored by pygments. | |
85 | Raw diffs are made in git-diff format, including git_ binary-patches |
|
85 | Raw diffs are made in git-diff format, including git_ binary-patches | |
86 | - Mercurial_ branch graph and yui-flot powered graphs with zooming and statistics |
|
86 | - Mercurial_ branch graph and yui-flot powered graphs with zooming and statistics | |
87 | - Admin interface with user/permission management. Admin activity journal, logs |
|
87 | - Admin interface with user/permission management. Admin activity journal, logs | |
88 | pulls, pushes, forks, registrations and other actions made by all users. |
|
88 | pulls, pushes, forks, registrations and other actions made by all users. | |
89 | - Server side forks. It is possible to fork a project and modify it freely |
|
89 | - Server side forks. It is possible to fork a project and modify it freely | |
90 | without breaking the main repository. You can even write Your own hooks |
|
90 | without breaking the main repository. You can even write Your own hooks | |
91 | and install them |
|
91 | and install them | |
92 | - code review with notification system, inline commenting, all parsed using |
|
92 | - code review with notification system, inline commenting, all parsed using | |
93 | rst syntax |
|
93 | rst syntax | |
94 | - rst and markdown README support for repositories |
|
94 | - rst and markdown README support for repositories | |
95 | - Full text search powered by Whoosh on the source files, and file names. |
|
95 | - Full text search powered by Whoosh on the source files, and file names. | |
96 | Build in indexing daemons, with optional incremental index build |
|
96 | Build in indexing daemons, with optional incremental index build | |
97 | (no external search servers required all in one application) |
|
97 | (no external search servers required all in one application) | |
98 | - Setup project descriptions and info inside built in db for easy, non |
|
98 | - Setup project descriptions and info inside built in db for easy, non | |
99 | file-system operations |
|
99 | file-system operations | |
100 | - Intelligent cache with invalidation after push or project change, provides |
|
100 | - Intelligent cache with invalidation after push or project change, provides | |
101 | high performance and always up to date data. |
|
101 | high performance and always up to date data. | |
102 | - Rss / atom feeds, gravatar support, download sources as zip/tar/gz |
|
102 | - Rss / atom feeds, gravatar support, download sources as zip/tar/gz | |
103 |
- |
|
103 | - Optional async tasks for speed and performance using celery_ | |
104 | - Backup scripts can do backup of whole app and send it over scp to desired |
|
104 | - Backup scripts can do backup of whole app and send it over scp to desired | |
105 | location |
|
105 | location | |
106 | - Based on pylons / sqlalchemy / sqlite / whoosh / vcs |
|
106 | - Based on pylons / sqlalchemy / sqlite / whoosh / vcs | |
107 |
|
107 | |||
108 |
|
108 | |||
109 | Incoming / Plans |
|
109 | Incoming / Plans | |
110 | ---------------- |
|
110 | ---------------- | |
111 |
|
111 | |||
112 | - Finer granular permissions per branch, repo group or subrepo |
|
112 | - Finer granular permissions per branch, repo group or subrepo | |
113 | - pull requests and web based merges |
|
113 | - pull requests and web based merges | |
114 | - per line file history |
|
114 | - per line file history | |
115 | - SSH based authentication with server side key management |
|
115 | - SSH based authentication with server side key management | |
116 | - Commit based built in wiki system |
|
116 | - Commit based built in wiki system | |
117 | - More statistics and graph (global annotation + some more statistics) |
|
117 | - More statistics and graph (global annotation + some more statistics) | |
118 | - Other advancements as development continues (or you can of course make |
|
118 | - Other advancements as development continues (or you can of course make | |
119 | additions and or requests) |
|
119 | additions and or requests) | |
120 |
|
120 | |||
121 | License |
|
121 | License | |
122 | ------- |
|
122 | ------- | |
123 |
|
123 | |||
124 | ``RhodeCode`` is released under the GPLv3 license. |
|
124 | ``RhodeCode`` is released under the GPLv3 license. | |
125 |
|
125 | |||
126 |
|
126 | |||
127 | Getting help |
|
127 | Getting help | |
128 | ------------ |
|
128 | ------------ | |
129 |
|
129 | |||
130 | Listed bellow are various support resources that should help. |
|
130 | Listed bellow are various support resources that should help. | |
131 |
|
131 | |||
132 | .. note:: |
|
132 | .. note:: | |
133 |
|
133 | |||
134 | Please try to read the documentation before posting any issues |
|
134 | Please try to read the documentation before posting any issues | |
135 |
|
135 | |||
136 | - Join the `Google group <http://groups.google.com/group/rhodecode>`_ and ask |
|
136 | - Join the `Google group <http://groups.google.com/group/rhodecode>`_ and ask | |
137 | any questions. |
|
137 | any questions. | |
138 |
|
138 | |||
139 | - Open an issue at `issue tracker <http://bitbucket.org/marcinkuzminski/rhodecode/issues>`_ |
|
139 | - Open an issue at `issue tracker <http://bitbucket.org/marcinkuzminski/rhodecode/issues>`_ | |
140 |
|
140 | |||
141 |
|
141 | |||
142 | - Join #rhodecode on FreeNode (irc.freenode.net) |
|
142 | - Join #rhodecode on FreeNode (irc.freenode.net) | |
143 | or use http://webchat.freenode.net/?channels=rhodecode for web access to irc. |
|
143 | or use http://webchat.freenode.net/?channels=rhodecode for web access to irc. | |
144 |
|
144 | |||
145 | - You can also follow me on twitter **@marcinkuzminski** where i often post some |
|
145 | - You can also follow me on twitter **@marcinkuzminski** where i often post some | |
146 | news about RhodeCode |
|
146 | news about RhodeCode | |
147 |
|
147 | |||
148 |
|
148 | |||
149 | Online documentation |
|
149 | Online documentation | |
150 | -------------------- |
|
150 | -------------------- | |
151 |
|
151 | |||
152 | Online documentation for the current version of RhodeCode is available at |
|
152 | Online documentation for the current version of RhodeCode is available at | |
153 | - http://packages.python.org/RhodeCode/ |
|
153 | - http://packages.python.org/RhodeCode/ | |
154 | - http://rhodecode.readthedocs.org/en/latest/index.html |
|
154 | - http://rhodecode.readthedocs.org/en/latest/index.html | |
155 |
|
155 | |||
156 | You may also build the documentation for yourself - go into ``docs/`` and run:: |
|
156 | You may also build the documentation for yourself - go into ``docs/`` and run:: | |
157 |
|
157 | |||
158 | make html |
|
158 | make html | |
159 |
|
159 | |||
160 | (You need to have sphinx_ installed to build the documentation. If you don't |
|
160 | (You need to have sphinx_ installed to build the documentation. If you don't | |
161 | have sphinx_ installed you can install it via the command: |
|
161 | have sphinx_ installed you can install it via the command: | |
162 | ``easy_install sphinx``) |
|
162 | ``easy_install sphinx``) | |
163 |
|
163 | |||
164 | .. _virtualenv: http://pypi.python.org/pypi/virtualenv |
|
164 | .. _virtualenv: http://pypi.python.org/pypi/virtualenv | |
165 | .. _python: http://www.python.org/ |
|
165 | .. _python: http://www.python.org/ | |
166 | .. _sphinx: http://sphinx.pocoo.org/ |
|
166 | .. _sphinx: http://sphinx.pocoo.org/ | |
167 | .. _mercurial: http://mercurial.selenic.com/ |
|
167 | .. _mercurial: http://mercurial.selenic.com/ | |
168 | .. _bitbucket: http://bitbucket.org/ |
|
168 | .. _bitbucket: http://bitbucket.org/ | |
169 | .. _github: http://github.com/ |
|
169 | .. _github: http://github.com/ | |
170 | .. _subversion: http://subversion.tigris.org/ |
|
170 | .. _subversion: http://subversion.tigris.org/ | |
171 | .. _git: http://git-scm.com/ |
|
171 | .. _git: http://git-scm.com/ | |
172 | .. _celery: http://celeryproject.org/ |
|
172 | .. _celery: http://celeryproject.org/ | |
173 | .. _Sphinx: http://sphinx.pocoo.org/ |
|
173 | .. _Sphinx: http://sphinx.pocoo.org/ | |
174 | .. _vcs: http://pypi.python.org/pypi/vcs No newline at end of file |
|
174 | .. _vcs: http://pypi.python.org/pypi/vcs |
@@ -1,646 +1,650 b'' | |||||
1 | .. _api: |
|
1 | .. _api: | |
2 |
|
2 | |||
3 | === |
|
3 | === | |
4 | API |
|
4 | API | |
5 | === |
|
5 | === | |
6 |
|
6 | |||
7 |
|
7 | |||
8 | Starting from RhodeCode version 1.2 a simple API was implemented. |
|
8 | Starting from RhodeCode version 1.2 a simple API was implemented. | |
9 | There's a single schema for calling all api methods. API is implemented |
|
9 | There's a single schema for calling all api methods. API is implemented | |
10 | with JSON protocol both ways. An url to send API request in RhodeCode is |
|
10 | with JSON protocol both ways. An url to send API request in RhodeCode is | |
11 | <your_server>/_admin/api |
|
11 | <your_server>/_admin/api | |
12 |
|
12 | |||
13 | API ACCESS FOR WEB VIEWS |
|
13 | API ACCESS FOR WEB VIEWS | |
14 | ++++++++++++++++++++++++ |
|
14 | ++++++++++++++++++++++++ | |
15 |
|
15 | |||
16 | API access can also be turned on for each web view in RhodeCode that is |
|
16 | API access can also be turned on for each web view in RhodeCode that is | |
17 | decorated with `@LoginRequired` decorator. To enable API access simple change |
|
17 | decorated with `@LoginRequired` decorator. To enable API access simple change | |
18 | the standard login decorator to `@LoginRequired(api_access=True)`. |
|
18 | the standard login decorator to `@LoginRequired(api_access=True)`. | |
19 | After this change, a rhodecode view can be accessed without login by adding a |
|
19 | After this change, a rhodecode view can be accessed without login by adding a | |
20 | GET parameter `?api_key=<api_key>` to url. By default this is only |
|
20 | GET parameter `?api_key=<api_key>` to url. By default this is only | |
21 | enabled on RSS/ATOM feed views. |
|
21 | enabled on RSS/ATOM feed views. | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | API ACCESS |
|
24 | API ACCESS | |
25 | ++++++++++ |
|
25 | ++++++++++ | |
26 |
|
26 | |||
27 | All clients are required to send JSON-RPC spec JSON data:: |
|
27 | All clients are required to send JSON-RPC spec JSON data:: | |
28 |
|
28 | |||
29 | { |
|
29 | { | |
30 | "id:"<id>", |
|
30 | "id:"<id>", | |
31 | "api_key":"<api_key>", |
|
31 | "api_key":"<api_key>", | |
32 | "method":"<method_name>", |
|
32 | "method":"<method_name>", | |
33 | "args":{"<arg_key>":"<arg_val>"} |
|
33 | "args":{"<arg_key>":"<arg_val>"} | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | Example call for autopulling remotes repos using curl:: |
|
36 | Example call for autopulling remotes repos using curl:: | |
37 | curl https://server.com/_admin/api -X POST -H 'content-type:text/plain' --data-binary '{"id":1,"api_key":"xe7cdb2v278e4evbdf5vs04v832v0efvcbcve4a3","method":"pull","args":{"repo":"CPython"}}' |
|
37 | curl https://server.com/_admin/api -X POST -H 'content-type:text/plain' --data-binary '{"id":1,"api_key":"xe7cdb2v278e4evbdf5vs04v832v0efvcbcve4a3","method":"pull","args":{"repo":"CPython"}}' | |
38 |
|
38 | |||
39 | Simply provide |
|
39 | Simply provide | |
40 | - *id* A value of any type, which is used to match the response with the request that it is replying to. |
|
40 | - *id* A value of any type, which is used to match the response with the request that it is replying to. | |
41 | - *api_key* for access and permission validation. |
|
41 | - *api_key* for access and permission validation. | |
42 | - *method* is name of method to call |
|
42 | - *method* is name of method to call | |
43 | - *args* is an key:value list of arguments to pass to method |
|
43 | - *args* is an key:value list of arguments to pass to method | |
44 |
|
44 | |||
45 | .. note:: |
|
45 | .. note:: | |
46 |
|
46 | |||
47 | api_key can be found in your user account page |
|
47 | api_key can be found in your user account page | |
48 |
|
48 | |||
49 |
|
49 | |||
50 | RhodeCode API will return always a JSON-RPC response:: |
|
50 | RhodeCode API will return always a JSON-RPC response:: | |
51 |
|
51 | |||
52 | { |
|
52 | { | |
53 | "id":<id>, # matching id sent by request |
|
53 | "id":<id>, # matching id sent by request | |
54 | "result": "<result>"|null, # JSON formatted result, null if any errors |
|
54 | "result": "<result>"|null, # JSON formatted result, null if any errors | |
55 | "error": "null"|<error_message> # JSON formatted error (if any) |
|
55 | "error": "null"|<error_message> # JSON formatted error (if any) | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | All responses from API will be `HTTP/1.0 200 OK`, if there's an error while |
|
58 | All responses from API will be `HTTP/1.0 200 OK`, if there's an error while | |
59 | calling api *error* key from response will contain failure description |
|
59 | calling api *error* key from response will contain failure description | |
60 | and result will be null. |
|
60 | and result will be null. | |
61 |
|
61 | |||
62 | API METHODS |
|
62 | API METHODS | |
63 | +++++++++++ |
|
63 | +++++++++++ | |
64 |
|
64 | |||
65 |
|
65 | |||
66 | pull |
|
66 | pull | |
67 | ---- |
|
67 | ---- | |
68 |
|
68 | |||
69 | Pulls given repo from remote location. Can be used to automatically keep |
|
69 | Pulls given repo from remote location. Can be used to automatically keep | |
70 | remote repos up to date. This command can be executed only using api_key |
|
70 | remote repos up to date. This command can be executed only using api_key | |
71 | belonging to user with admin rights |
|
71 | belonging to user with admin rights | |
72 |
|
72 | |||
73 | INPUT:: |
|
73 | INPUT:: | |
74 |
|
74 | |||
75 | id : <id_for_response> |
|
75 | id : <id_for_response> | |
76 | api_key : "<api_key>" |
|
76 | api_key : "<api_key>" | |
77 | method : "pull" |
|
77 | method : "pull" | |
78 | args : { |
|
78 | args : { | |
79 | "repo_name" : "<reponame>" |
|
79 | "repo_name" : "<reponame>" | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | OUTPUT:: |
|
82 | OUTPUT:: | |
83 |
|
83 | |||
84 | result : "Pulled from <reponame>" |
|
84 | result : "Pulled from <reponame>" | |
85 | error : null |
|
85 | error : null | |
86 |
|
86 | |||
87 |
|
87 | |||
88 | get_user |
|
88 | get_user | |
89 | -------- |
|
89 | -------- | |
90 |
|
90 | |||
91 | Get's an user by username or user_id, Returns empty result if user is not found. |
|
91 | Get's an user by username or user_id, Returns empty result if user is not found. | |
92 | This command can be executed only using api_key belonging to user with admin |
|
92 | This command can be executed only using api_key belonging to user with admin | |
93 | rights. |
|
93 | rights. | |
94 |
|
94 | |||
95 |
|
95 | |||
96 | INPUT:: |
|
96 | INPUT:: | |
97 |
|
97 | |||
98 | id : <id_for_response> |
|
98 | id : <id_for_response> | |
99 | api_key : "<api_key>" |
|
99 | api_key : "<api_key>" | |
100 | method : "get_user" |
|
100 | method : "get_user" | |
101 | args : { |
|
101 | args : { | |
102 | "userid" : "<username or user_id>" |
|
102 | "userid" : "<username or user_id>" | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | OUTPUT:: |
|
105 | OUTPUT:: | |
106 |
|
106 | |||
107 | result: None if user does not exist or |
|
107 | result: None if user does not exist or | |
108 | { |
|
108 | { | |
109 | "id" : "<id>", |
|
109 | "id" : "<id>", | |
110 | "username" : "<username>", |
|
110 | "username" : "<username>", | |
111 | "firstname": "<firstname>", |
|
111 | "firstname": "<firstname>", | |
112 | "lastname" : "<lastname>", |
|
112 | "lastname" : "<lastname>", | |
113 | "email" : "<email>", |
|
113 | "email" : "<email>", | |
114 | "active" : "<bool>", |
|
114 | "active" : "<bool>", | |
115 | "admin" :Β "<bool>", |
|
115 | "admin" :Β "<bool>", | |
116 | "ldap_dn" : "<ldap_dn>" |
|
116 | "ldap_dn" : "<ldap_dn>" | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | error: null |
|
119 | error: null | |
120 |
|
120 | |||
121 |
|
121 | |||
122 | get_users |
|
122 | get_users | |
123 | --------- |
|
123 | --------- | |
124 |
|
124 | |||
125 | Lists all existing users. This command can be executed only using api_key |
|
125 | Lists all existing users. This command can be executed only using api_key | |
126 | belonging to user with admin rights. |
|
126 | belonging to user with admin rights. | |
127 |
|
127 | |||
128 |
|
128 | |||
129 | INPUT:: |
|
129 | INPUT:: | |
130 |
|
130 | |||
131 | id : <id_for_response> |
|
131 | id : <id_for_response> | |
132 | api_key : "<api_key>" |
|
132 | api_key : "<api_key>" | |
133 | method : "get_users" |
|
133 | method : "get_users" | |
134 | args : { } |
|
134 | args : { } | |
135 |
|
135 | |||
136 | OUTPUT:: |
|
136 | OUTPUT:: | |
137 |
|
137 | |||
138 | result: [ |
|
138 | result: [ | |
139 | { |
|
139 | { | |
140 | "id" : "<id>", |
|
140 | "id" : "<id>", | |
141 | "username" : "<username>", |
|
141 | "username" : "<username>", | |
142 | "firstname": "<firstname>", |
|
142 | "firstname": "<firstname>", | |
143 | "lastname" : "<lastname>", |
|
143 | "lastname" : "<lastname>", | |
144 | "email" : "<email>", |
|
144 | "email" : "<email>", | |
145 | "active" : "<bool>", |
|
145 | "active" : "<bool>", | |
146 | "admin" :Β "<bool>", |
|
146 | "admin" :Β "<bool>", | |
147 | "ldap_dn" : "<ldap_dn>" |
|
147 | "ldap_dn" : "<ldap_dn>" | |
148 | }, |
|
148 | }, | |
149 | β¦ |
|
149 | β¦ | |
150 | ] |
|
150 | ] | |
151 | error: null |
|
151 | error: null | |
152 |
|
152 | |||
153 |
|
153 | |||
154 | create_user |
|
154 | create_user | |
155 | ----------- |
|
155 | ----------- | |
156 |
|
156 | |||
157 | Creates new user. This command can |
|
157 | Creates new user. This command can | |
158 | be executed only using api_key belonging to user with admin rights. |
|
158 | be executed only using api_key belonging to user with admin rights. | |
159 |
|
159 | |||
160 |
|
160 | |||
161 | INPUT:: |
|
161 | INPUT:: | |
162 |
|
162 | |||
163 | id : <id_for_response> |
|
163 | id : <id_for_response> | |
164 | api_key : "<api_key>" |
|
164 | api_key : "<api_key>" | |
165 | method : "create_user" |
|
165 | method : "create_user" | |
166 | args : { |
|
166 | args : { | |
167 | "username" : "<username>", |
|
167 | "username" : "<username>", | |
168 | "password" : "<password>", |
|
168 | "password" : "<password>", | |
169 | "email" : "<useremail>", |
|
169 | "email" : "<useremail>", | |
170 | "firstname" : "<firstname> = None", |
|
170 | "firstname" : "<firstname> = None", | |
171 | "lastname" : "<lastname> = None", |
|
171 | "lastname" : "<lastname> = None", | |
172 | "active" : "<bool> = True", |
|
172 | "active" : "<bool> = True", | |
173 | "admin" : "<bool> = False", |
|
173 | "admin" : "<bool> = False", | |
174 | "ldap_dn" : "<ldap_dn> = None" |
|
174 | "ldap_dn" : "<ldap_dn> = None" | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | OUTPUT:: |
|
177 | OUTPUT:: | |
178 |
|
178 | |||
179 | result: { |
|
179 | result: { | |
180 | "id" : "<new_user_id>", |
|
180 | "id" : "<new_user_id>", | |
181 | "msg" : "created new user <username>" |
|
181 | "msg" : "created new user <username>" | |
182 | } |
|
182 | } | |
183 | error: null |
|
183 | error: null | |
184 |
|
184 | |||
185 |
|
185 | |||
186 | update_user |
|
186 | update_user | |
187 | ----------- |
|
187 | ----------- | |
188 |
|
188 | |||
189 | updates current one if such user exists. This command can |
|
189 | updates current one if such user exists. This command can | |
190 | be executed only using api_key belonging to user with admin rights. |
|
190 | be executed only using api_key belonging to user with admin rights. | |
191 |
|
191 | |||
192 |
|
192 | |||
193 | INPUT:: |
|
193 | INPUT:: | |
194 |
|
194 | |||
195 | id : <id_for_response> |
|
195 | id : <id_for_response> | |
196 | api_key : "<api_key>" |
|
196 | api_key : "<api_key>" | |
197 | method : "update_user" |
|
197 | method : "update_user" | |
198 | args : { |
|
198 | args : { | |
199 | "userid" : "<user_id or username>", |
|
199 | "userid" : "<user_id or username>", | |
200 | "username" : "<username>", |
|
200 | "username" : "<username>", | |
201 | "password" : "<password>", |
|
201 | "password" : "<password>", | |
202 | "email" : "<useremail>", |
|
202 | "email" : "<useremail>", | |
203 | "firstname" : "<firstname>", |
|
203 | "firstname" : "<firstname>", | |
204 | "lastname" : "<lastname>", |
|
204 | "lastname" : "<lastname>", | |
205 | "active" : "<bool>", |
|
205 | "active" : "<bool>", | |
206 | "admin" : "<bool>", |
|
206 | "admin" : "<bool>", | |
207 | "ldap_dn" : "<ldap_dn>" |
|
207 | "ldap_dn" : "<ldap_dn>" | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | OUTPUT:: |
|
210 | OUTPUT:: | |
211 |
|
211 | |||
212 | result: { |
|
212 | result: { | |
213 | "id" : "<edited_user_id>", |
|
213 | "id" : "<edited_user_id>", | |
214 | "msg" : "updated user <username>" |
|
214 | "msg" : "updated user <username>" | |
215 | } |
|
215 | } | |
216 | error: null |
|
216 | error: null | |
217 |
|
217 | |||
218 |
|
218 | |||
219 | get_users_group |
|
219 | get_users_group | |
220 | --------------- |
|
220 | --------------- | |
221 |
|
221 | |||
222 | Gets an existing users group. This command can be executed only using api_key |
|
222 | Gets an existing users group. This command can be executed only using api_key | |
223 | belonging to user with admin rights. |
|
223 | belonging to user with admin rights. | |
224 |
|
224 | |||
225 |
|
225 | |||
226 | INPUT:: |
|
226 | INPUT:: | |
227 |
|
227 | |||
228 | id : <id_for_response> |
|
228 | id : <id_for_response> | |
229 | api_key : "<api_key>" |
|
229 | api_key : "<api_key>" | |
230 | method : "get_users_group" |
|
230 | method : "get_users_group" | |
231 | args : { |
|
231 | args : { | |
232 | "group_name" : "<name>" |
|
232 | "group_name" : "<name>" | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | OUTPUT:: |
|
235 | OUTPUT:: | |
236 |
|
236 | |||
237 | result : None if group not exist |
|
237 | result : None if group not exist | |
238 | { |
|
238 | { | |
239 | "id" : "<id>", |
|
239 | "id" : "<id>", | |
240 | "group_name" : "<groupname>", |
|
240 | "group_name" : "<groupname>", | |
241 | "active": "<bool>", |
|
241 | "active": "<bool>", | |
242 | "members" : [ |
|
242 | "members" : [ | |
243 | { "id" : "<userid>", |
|
243 | { "id" : "<userid>", | |
244 | "username" : "<username>", |
|
244 | "username" : "<username>", | |
245 | "firstname": "<firstname>", |
|
245 | "firstname": "<firstname>", | |
246 | "lastname" : "<lastname>", |
|
246 | "lastname" : "<lastname>", | |
247 | "email" : "<email>", |
|
247 | "email" : "<email>", | |
248 | "active" : "<bool>", |
|
248 | "active" : "<bool>", | |
249 | "admin" :Β "<bool>", |
|
249 | "admin" :Β "<bool>", | |
250 | "ldap" : "<ldap_dn>" |
|
250 | "ldap" : "<ldap_dn>" | |
251 | }, |
|
251 | }, | |
252 | β¦ |
|
252 | β¦ | |
253 | ] |
|
253 | ] | |
254 | } |
|
254 | } | |
255 | error : null |
|
255 | error : null | |
256 |
|
256 | |||
257 |
|
257 | |||
258 | get_users_groups |
|
258 | get_users_groups | |
259 | ---------------- |
|
259 | ---------------- | |
260 |
|
260 | |||
261 | Lists all existing users groups. This command can be executed only using |
|
261 | Lists all existing users groups. This command can be executed only using | |
262 | api_key belonging to user with admin rights. |
|
262 | api_key belonging to user with admin rights. | |
263 |
|
263 | |||
264 |
|
264 | |||
265 | INPUT:: |
|
265 | INPUT:: | |
266 |
|
266 | |||
267 | id : <id_for_response> |
|
267 | id : <id_for_response> | |
268 | api_key : "<api_key>" |
|
268 | api_key : "<api_key>" | |
269 | method : "get_users_groups" |
|
269 | method : "get_users_groups" | |
270 | args : { } |
|
270 | args : { } | |
271 |
|
271 | |||
272 | OUTPUT:: |
|
272 | OUTPUT:: | |
273 |
|
273 | |||
274 | result : [ |
|
274 | result : [ | |
275 | { |
|
275 | { | |
276 | "id" : "<id>", |
|
276 | "id" : "<id>", | |
277 | "group_name" : "<groupname>", |
|
277 | "group_name" : "<groupname>", | |
278 | "active": "<bool>", |
|
278 | "active": "<bool>", | |
279 | "members" : [ |
|
279 | "members" : [ | |
280 | { |
|
280 | { | |
281 | "id" : "<userid>", |
|
281 | "id" : "<userid>", | |
282 | "username" : "<username>", |
|
282 | "username" : "<username>", | |
283 | "firstname": "<firstname>", |
|
283 | "firstname": "<firstname>", | |
284 | "lastname" : "<lastname>", |
|
284 | "lastname" : "<lastname>", | |
285 | "email" : "<email>", |
|
285 | "email" : "<email>", | |
286 | "active" : "<bool>", |
|
286 | "active" : "<bool>", | |
287 | "admin" :Β "<bool>", |
|
287 | "admin" :Β "<bool>", | |
288 | "ldap" : "<ldap_dn>" |
|
288 | "ldap" : "<ldap_dn>" | |
289 | }, |
|
289 | }, | |
290 | β¦ |
|
290 | β¦ | |
291 | ] |
|
291 | ] | |
292 | } |
|
292 | } | |
293 | ] |
|
293 | ] | |
294 | error : null |
|
294 | error : null | |
295 |
|
295 | |||
296 |
|
296 | |||
297 | create_users_group |
|
297 | create_users_group | |
298 | ------------------ |
|
298 | ------------------ | |
299 |
|
299 | |||
300 | Creates new users group. This command can be executed only using api_key |
|
300 | Creates new users group. This command can be executed only using api_key | |
301 | belonging to user with admin rights |
|
301 | belonging to user with admin rights | |
302 |
|
302 | |||
303 |
|
303 | |||
304 | INPUT:: |
|
304 | INPUT:: | |
305 |
|
305 | |||
306 | id : <id_for_response> |
|
306 | id : <id_for_response> | |
307 | api_key : "<api_key>" |
|
307 | api_key : "<api_key>" | |
308 | method : "create_users_group" |
|
308 | method : "create_users_group" | |
309 | args: { |
|
309 | args: { | |
310 | "group_name": "<groupname>", |
|
310 | "group_name": "<groupname>", | |
311 | "active":"<bool> = True" |
|
311 | "active":"<bool> = True" | |
312 | } |
|
312 | } | |
313 |
|
313 | |||
314 | OUTPUT:: |
|
314 | OUTPUT:: | |
315 |
|
315 | |||
316 | result: { |
|
316 | result: { | |
317 | "id": "<newusersgroupid>", |
|
317 | "id": "<newusersgroupid>", | |
318 | "msg": "created new users group <groupname>" |
|
318 | "msg": "created new users group <groupname>" | |
319 | } |
|
319 | } | |
320 | error: null |
|
320 | error: null | |
321 |
|
321 | |||
322 |
|
322 | |||
323 | add_user_to_users_group |
|
323 | add_user_to_users_group | |
324 | ----------------------- |
|
324 | ----------------------- | |
325 |
|
325 | |||
326 | Adds a user to a users group. If user exists in that group success will be |
|
326 | Adds a user to a users group. If user exists in that group success will be | |
327 | `false`. This command can be executed only using api_key |
|
327 | `false`. This command can be executed only using api_key | |
328 | belonging to user with admin rights |
|
328 | belonging to user with admin rights | |
329 |
|
329 | |||
330 |
|
330 | |||
331 | INPUT:: |
|
331 | INPUT:: | |
332 |
|
332 | |||
333 | id : <id_for_response> |
|
333 | id : <id_for_response> | |
334 | api_key : "<api_key>" |
|
334 | api_key : "<api_key>" | |
335 | method : "add_user_users_group" |
|
335 | method : "add_user_users_group" | |
336 | args: { |
|
336 | args: { | |
337 | "group_name" : "<groupname>", |
|
337 | "group_name" : "<groupname>", | |
338 | "username" : "<username>" |
|
338 | "username" : "<username>" | |
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 | OUTPUT:: |
|
341 | OUTPUT:: | |
342 |
|
342 | |||
343 | result: { |
|
343 | result: { | |
344 | "id": "<newusersgroupmemberid>", |
|
344 | "id": "<newusersgroupmemberid>", | |
345 | "success": True|False # depends on if member is in group |
|
345 | "success": True|False # depends on if member is in group | |
346 | "msg": "added member <username> to users group <groupname> | |
|
346 | "msg": "added member <username> to users group <groupname> | | |
347 | User is already in that group" |
|
347 | User is already in that group" | |
348 | } |
|
348 | } | |
349 | error: null |
|
349 | error: null | |
350 |
|
350 | |||
351 |
|
351 | |||
352 | remove_user_from_users_group |
|
352 | remove_user_from_users_group | |
353 | ---------------------------- |
|
353 | ---------------------------- | |
354 |
|
354 | |||
355 | Removes a user from a users group. If user is not in given group success will |
|
355 | Removes a user from a users group. If user is not in given group success will | |
356 | be `false`. This command can be executed only |
|
356 | be `false`. This command can be executed only | |
357 | using api_key belonging to user with admin rights |
|
357 | using api_key belonging to user with admin rights | |
358 |
|
358 | |||
359 |
|
359 | |||
360 | INPUT:: |
|
360 | INPUT:: | |
361 |
|
361 | |||
362 | id : <id_for_response> |
|
362 | id : <id_for_response> | |
363 | api_key : "<api_key>" |
|
363 | api_key : "<api_key>" | |
364 | method : "remove_user_from_users_group" |
|
364 | method : "remove_user_from_users_group" | |
365 | args: { |
|
365 | args: { | |
366 | "group_name" : "<groupname>", |
|
366 | "group_name" : "<groupname>", | |
367 | "username" : "<username>" |
|
367 | "username" : "<username>" | |
368 | } |
|
368 | } | |
369 |
|
369 | |||
370 | OUTPUT:: |
|
370 | OUTPUT:: | |
371 |
|
371 | |||
372 | result: { |
|
372 | result: { | |
373 | "success": True|False, # depends on if member is in group |
|
373 | "success": True|False, # depends on if member is in group | |
374 | "msg": "removed member <username> from users group <groupname> | |
|
374 | "msg": "removed member <username> from users group <groupname> | | |
375 | User wasn't in group" |
|
375 | User wasn't in group" | |
376 | } |
|
376 | } | |
377 | error: null |
|
377 | error: null | |
378 |
|
378 | |||
379 |
|
379 | |||
380 | get_repo |
|
380 | get_repo | |
381 | -------- |
|
381 | -------- | |
382 |
|
382 | |||
383 |
Gets an existing repository by it's name or repository_id. |
|
383 | Gets an existing repository by it's name or repository_id. Members will return | |
|
384 | either users_group or user associated to that repository. This command can | |||
384 | be executed only using api_key belonging to user with admin rights. |
|
385 | be executed only using api_key belonging to user with admin rights. | |
385 |
|
386 | |||
386 |
|
387 | |||
387 | INPUT:: |
|
388 | INPUT:: | |
388 |
|
389 | |||
389 | id : <id_for_response> |
|
390 | id : <id_for_response> | |
390 | api_key : "<api_key>" |
|
391 | api_key : "<api_key>" | |
391 | method : "get_repo" |
|
392 | method : "get_repo" | |
392 | args: { |
|
393 | args: { | |
393 | "repoid" : "<reponame or repo_id>" |
|
394 | "repoid" : "<reponame or repo_id>" | |
394 | } |
|
395 | } | |
395 |
|
396 | |||
396 | OUTPUT:: |
|
397 | OUTPUT:: | |
397 |
|
398 | |||
398 | result: None if repository does not exist or |
|
399 | result: None if repository does not exist or | |
399 | { |
|
400 | { | |
400 | "id" : "<id>", |
|
401 | "id" : "<id>", | |
401 | "repo_name" : "<reponame>" |
|
402 | "repo_name" : "<reponame>" | |
402 | "type" : "<type>", |
|
403 | "type" : "<type>", | |
403 | "description" : "<description>", |
|
404 | "description" : "<description>", | |
404 | "members" : [ |
|
405 | "members" : [ | |
405 |
{ |
|
406 | { | |
|
407 | "type": "user", | |||
|
408 | "id" : "<userid>", | |||
406 | "username" : "<username>", |
|
409 | "username" : "<username>", | |
407 | "firstname": "<firstname>", |
|
410 | "firstname": "<firstname>", | |
408 | "lastname" : "<lastname>", |
|
411 | "lastname" : "<lastname>", | |
409 | "email" : "<email>", |
|
412 | "email" : "<email>", | |
410 | "active" : "<bool>", |
|
413 | "active" : "<bool>", | |
411 | "admin" :Β "<bool>", |
|
414 | "admin" :Β "<bool>", | |
412 | "ldap" : "<ldap_dn>", |
|
415 | "ldap" : "<ldap_dn>", | |
413 | "permission" : "repository.(read|write|admin)" |
|
416 | "permission" : "repository.(read|write|admin)" | |
414 | }, |
|
417 | }, | |
415 | β¦ |
|
418 | β¦ | |
416 | { |
|
419 | { | |
|
420 | "type": "users_group", | |||
417 | "id" : "<usersgroupid>", |
|
421 | "id" : "<usersgroupid>", | |
418 | "name" : "<usersgroupname>", |
|
422 | "name" : "<usersgroupname>", | |
419 | "active": "<bool>", |
|
423 | "active": "<bool>", | |
420 | "permission" : "repository.(read|write|admin)" |
|
424 | "permission" : "repository.(read|write|admin)" | |
421 | }, |
|
425 | }, | |
422 | β¦ |
|
426 | β¦ | |
423 | ] |
|
427 | ] | |
424 | } |
|
428 | } | |
425 | error: null |
|
429 | error: null | |
426 |
|
430 | |||
427 |
|
431 | |||
428 | get_repos |
|
432 | get_repos | |
429 | --------- |
|
433 | --------- | |
430 |
|
434 | |||
431 | Lists all existing repositories. This command can be executed only using api_key |
|
435 | Lists all existing repositories. This command can be executed only using api_key | |
432 | belonging to user with admin rights |
|
436 | belonging to user with admin rights | |
433 |
|
437 | |||
434 |
|
438 | |||
435 | INPUT:: |
|
439 | INPUT:: | |
436 |
|
440 | |||
437 | id : <id_for_response> |
|
441 | id : <id_for_response> | |
438 | api_key : "<api_key>" |
|
442 | api_key : "<api_key>" | |
439 | method : "get_repos" |
|
443 | method : "get_repos" | |
440 | args: { } |
|
444 | args: { } | |
441 |
|
445 | |||
442 | OUTPUT:: |
|
446 | OUTPUT:: | |
443 |
|
447 | |||
444 | result: [ |
|
448 | result: [ | |
445 | { |
|
449 | { | |
446 | "id" : "<id>", |
|
450 | "id" : "<id>", | |
447 | "repo_name" : "<reponame>" |
|
451 | "repo_name" : "<reponame>" | |
448 | "type" : "<type>", |
|
452 | "type" : "<type>", | |
449 | "description" : "<description>" |
|
453 | "description" : "<description>" | |
450 | }, |
|
454 | }, | |
451 | β¦ |
|
455 | β¦ | |
452 | ] |
|
456 | ] | |
453 | error: null |
|
457 | error: null | |
454 |
|
458 | |||
455 |
|
459 | |||
456 | get_repo_nodes |
|
460 | get_repo_nodes | |
457 | -------------- |
|
461 | -------------- | |
458 |
|
462 | |||
459 | returns a list of nodes and it's children in a flat list for a given path |
|
463 | returns a list of nodes and it's children in a flat list for a given path | |
460 | at given revision. It's possible to specify ret_type to show only `files` or |
|
464 | at given revision. It's possible to specify ret_type to show only `files` or | |
461 | `dirs`. This command can be executed only using api_key belonging to user |
|
465 | `dirs`. This command can be executed only using api_key belonging to user | |
462 | with admin rights |
|
466 | with admin rights | |
463 |
|
467 | |||
464 |
|
468 | |||
465 | INPUT:: |
|
469 | INPUT:: | |
466 |
|
470 | |||
467 | id : <id_for_response> |
|
471 | id : <id_for_response> | |
468 | api_key : "<api_key>" |
|
472 | api_key : "<api_key>" | |
469 | method : "get_repo_nodes" |
|
473 | method : "get_repo_nodes" | |
470 | args: { |
|
474 | args: { | |
471 | "repo_name" : "<reponame>", |
|
475 | "repo_name" : "<reponame>", | |
472 | "revision" : "<revision>", |
|
476 | "revision" : "<revision>", | |
473 | "root_path" : "<root_path>", |
|
477 | "root_path" : "<root_path>", | |
474 | "ret_type" : "<ret_type>" = 'all' |
|
478 | "ret_type" : "<ret_type>" = 'all' | |
475 | } |
|
479 | } | |
476 |
|
480 | |||
477 | OUTPUT:: |
|
481 | OUTPUT:: | |
478 |
|
482 | |||
479 | result: [ |
|
483 | result: [ | |
480 | { |
|
484 | { | |
481 | "name" : "<name>" |
|
485 | "name" : "<name>" | |
482 | "type" : "<type>", |
|
486 | "type" : "<type>", | |
483 | }, |
|
487 | }, | |
484 | β¦ |
|
488 | β¦ | |
485 | ] |
|
489 | ] | |
486 | error: null |
|
490 | error: null | |
487 |
|
491 | |||
488 |
|
492 | |||
489 | create_repo |
|
493 | create_repo | |
490 | ----------- |
|
494 | ----------- | |
491 |
|
495 | |||
492 | Creates a repository. This command can be executed only using api_key |
|
496 | Creates a repository. This command can be executed only using api_key | |
493 | belonging to user with admin rights. |
|
497 | belonging to user with admin rights. | |
494 | If repository name contains "/", all needed repository groups will be created. |
|
498 | If repository name contains "/", all needed repository groups will be created. | |
495 | For example "foo/bar/baz" will create groups "foo", "bar" (with "foo" as parent), |
|
499 | For example "foo/bar/baz" will create groups "foo", "bar" (with "foo" as parent), | |
496 | and create "baz" repository with "bar" as group. |
|
500 | and create "baz" repository with "bar" as group. | |
497 |
|
501 | |||
498 |
|
502 | |||
499 | INPUT:: |
|
503 | INPUT:: | |
500 |
|
504 | |||
501 | id : <id_for_response> |
|
505 | id : <id_for_response> | |
502 | api_key : "<api_key>" |
|
506 | api_key : "<api_key>" | |
503 | method : "create_repo" |
|
507 | method : "create_repo" | |
504 | args: { |
|
508 | args: { | |
505 | "repo_name" : "<reponame>", |
|
509 | "repo_name" : "<reponame>", | |
506 | "owner_name" : "<ownername>", |
|
510 | "owner_name" : "<ownername>", | |
507 | "description" : "<description> = ''", |
|
511 | "description" : "<description> = ''", | |
508 | "repo_type" : "<type> = 'hg'", |
|
512 | "repo_type" : "<type> = 'hg'", | |
509 | "private" : "<bool> = False", |
|
513 | "private" : "<bool> = False", | |
510 | "clone_uri" : "<clone_uri> = None", |
|
514 | "clone_uri" : "<clone_uri> = None", | |
511 | } |
|
515 | } | |
512 |
|
516 | |||
513 | OUTPUT:: |
|
517 | OUTPUT:: | |
514 |
|
518 | |||
515 | result: { |
|
519 | result: { | |
516 | "id": "<newrepoid>", |
|
520 | "id": "<newrepoid>", | |
517 | "msg": "Created new repository <reponame>", |
|
521 | "msg": "Created new repository <reponame>", | |
518 | } |
|
522 | } | |
519 | error: null |
|
523 | error: null | |
520 |
|
524 | |||
521 |
|
525 | |||
522 | delete_repo |
|
526 | delete_repo | |
523 | ----------- |
|
527 | ----------- | |
524 |
|
528 | |||
525 | Deletes a repository. This command can be executed only using api_key |
|
529 | Deletes a repository. This command can be executed only using api_key | |
526 | belonging to user with admin rights. |
|
530 | belonging to user with admin rights. | |
527 |
|
531 | |||
528 |
|
532 | |||
529 | INPUT:: |
|
533 | INPUT:: | |
530 |
|
534 | |||
531 | id : <id_for_response> |
|
535 | id : <id_for_response> | |
532 | api_key : "<api_key>" |
|
536 | api_key : "<api_key>" | |
533 | method : "delete_repo" |
|
537 | method : "delete_repo" | |
534 | args: { |
|
538 | args: { | |
535 | "repo_name" : "<reponame>", |
|
539 | "repo_name" : "<reponame>", | |
536 | } |
|
540 | } | |
537 |
|
541 | |||
538 | OUTPUT:: |
|
542 | OUTPUT:: | |
539 |
|
543 | |||
540 | result: { |
|
544 | result: { | |
541 | "msg": "Deleted repository <reponame>", |
|
545 | "msg": "Deleted repository <reponame>", | |
542 | } |
|
546 | } | |
543 | error: null |
|
547 | error: null | |
544 |
|
548 | |||
545 |
|
549 | |||
546 | grant_user_permission |
|
550 | grant_user_permission | |
547 | --------------------- |
|
551 | --------------------- | |
548 |
|
552 | |||
549 | Grant permission for user on given repository, or update existing one |
|
553 | Grant permission for user on given repository, or update existing one | |
550 | if found. This command can be executed only using api_key belonging to user |
|
554 | if found. This command can be executed only using api_key belonging to user | |
551 | with admin rights. |
|
555 | with admin rights. | |
552 |
|
556 | |||
553 |
|
557 | |||
554 | INPUT:: |
|
558 | INPUT:: | |
555 |
|
559 | |||
556 | id : <id_for_response> |
|
560 | id : <id_for_response> | |
557 | api_key : "<api_key>" |
|
561 | api_key : "<api_key>" | |
558 | method : "grant_user_permission" |
|
562 | method : "grant_user_permission" | |
559 | args: { |
|
563 | args: { | |
560 | "repo_name" : "<reponame>", |
|
564 | "repo_name" : "<reponame>", | |
561 | "username" : "<username>", |
|
565 | "username" : "<username>", | |
562 | "perm" : "(repository.(none|read|write|admin))", |
|
566 | "perm" : "(repository.(none|read|write|admin))", | |
563 | } |
|
567 | } | |
564 |
|
568 | |||
565 | OUTPUT:: |
|
569 | OUTPUT:: | |
566 |
|
570 | |||
567 | result: { |
|
571 | result: { | |
568 | "msg" : "Granted perm: <perm> for user: <username> in repo: <reponame>" |
|
572 | "msg" : "Granted perm: <perm> for user: <username> in repo: <reponame>" | |
569 | } |
|
573 | } | |
570 | error: null |
|
574 | error: null | |
571 |
|
575 | |||
572 |
|
576 | |||
573 | revoke_user_permission |
|
577 | revoke_user_permission | |
574 | ---------------------- |
|
578 | ---------------------- | |
575 |
|
579 | |||
576 | Revoke permission for user on given repository. This command can be executed |
|
580 | Revoke permission for user on given repository. This command can be executed | |
577 | only using api_key belonging to user with admin rights. |
|
581 | only using api_key belonging to user with admin rights. | |
578 |
|
582 | |||
579 |
|
583 | |||
580 | INPUT:: |
|
584 | INPUT:: | |
581 |
|
585 | |||
582 | id : <id_for_response> |
|
586 | id : <id_for_response> | |
583 | api_key : "<api_key>" |
|
587 | api_key : "<api_key>" | |
584 | method : "revoke_user_permission" |
|
588 | method : "revoke_user_permission" | |
585 | args: { |
|
589 | args: { | |
586 | "repo_name" : "<reponame>", |
|
590 | "repo_name" : "<reponame>", | |
587 | "username" : "<username>", |
|
591 | "username" : "<username>", | |
588 | } |
|
592 | } | |
589 |
|
593 | |||
590 | OUTPUT:: |
|
594 | OUTPUT:: | |
591 |
|
595 | |||
592 | result: { |
|
596 | result: { | |
593 | "msg" : "Revoked perm for user: <suername> in repo: <reponame>" |
|
597 | "msg" : "Revoked perm for user: <suername> in repo: <reponame>" | |
594 | } |
|
598 | } | |
595 | error: null |
|
599 | error: null | |
596 |
|
600 | |||
597 |
|
601 | |||
598 | grant_users_group_permission |
|
602 | grant_users_group_permission | |
599 | ---------------------------- |
|
603 | ---------------------------- | |
600 |
|
604 | |||
601 | Grant permission for users group on given repository, or update |
|
605 | Grant permission for users group on given repository, or update | |
602 | existing one if found. This command can be executed only using |
|
606 | existing one if found. This command can be executed only using | |
603 | api_key belonging to user with admin rights. |
|
607 | api_key belonging to user with admin rights. | |
604 |
|
608 | |||
605 |
|
609 | |||
606 | INPUT:: |
|
610 | INPUT:: | |
607 |
|
611 | |||
608 | id : <id_for_response> |
|
612 | id : <id_for_response> | |
609 | api_key : "<api_key>" |
|
613 | api_key : "<api_key>" | |
610 | method : "grant_users_group_permission" |
|
614 | method : "grant_users_group_permission" | |
611 | args: { |
|
615 | args: { | |
612 | "repo_name" : "<reponame>", |
|
616 | "repo_name" : "<reponame>", | |
613 | "group_name" : "<usersgroupname>", |
|
617 | "group_name" : "<usersgroupname>", | |
614 | "perm" : "(repository.(none|read|write|admin))", |
|
618 | "perm" : "(repository.(none|read|write|admin))", | |
615 | } |
|
619 | } | |
616 |
|
620 | |||
617 | OUTPUT:: |
|
621 | OUTPUT:: | |
618 |
|
622 | |||
619 | result: { |
|
623 | result: { | |
620 | "msg" : "Granted perm: <perm> for group: <usersgroupname> in repo: <reponame>" |
|
624 | "msg" : "Granted perm: <perm> for group: <usersgroupname> in repo: <reponame>" | |
621 | } |
|
625 | } | |
622 | error: null |
|
626 | error: null | |
623 |
|
627 | |||
624 |
|
628 | |||
625 | revoke_users_group_permission |
|
629 | revoke_users_group_permission | |
626 | ----------------------------- |
|
630 | ----------------------------- | |
627 |
|
631 | |||
628 | Revoke permission for users group on given repository.This command can be |
|
632 | Revoke permission for users group on given repository.This command can be | |
629 | executed only using api_key belonging to user with admin rights. |
|
633 | executed only using api_key belonging to user with admin rights. | |
630 |
|
634 | |||
631 | INPUT:: |
|
635 | INPUT:: | |
632 |
|
636 | |||
633 | id : <id_for_response> |
|
637 | id : <id_for_response> | |
634 | api_key : "<api_key>" |
|
638 | api_key : "<api_key>" | |
635 | method : "revoke_users_group_permission" |
|
639 | method : "revoke_users_group_permission" | |
636 | args: { |
|
640 | args: { | |
637 | "repo_name" : "<reponame>", |
|
641 | "repo_name" : "<reponame>", | |
638 | "users_group" : "<usersgroupname>", |
|
642 | "users_group" : "<usersgroupname>", | |
639 | } |
|
643 | } | |
640 |
|
644 | |||
641 | OUTPUT:: |
|
645 | OUTPUT:: | |
642 |
|
646 | |||
643 | result: { |
|
647 | result: { | |
644 | "msg" : "Revoked perm for group: <usersgroupname> in repo: <reponame>" |
|
648 | "msg" : "Revoked perm for group: <usersgroupname> in repo: <reponame>" | |
645 | } |
|
649 | } | |
646 | error: null No newline at end of file |
|
650 | error: null |
@@ -1,656 +1,656 b'' | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | """ |
|
2 | """ | |
3 | rhodecode.controllers.api |
|
3 | rhodecode.controllers.api | |
4 | ~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
4 | ~~~~~~~~~~~~~~~~~~~~~~~~~ | |
5 |
|
5 | |||
6 | API controller for RhodeCode |
|
6 | API controller for RhodeCode | |
7 |
|
7 | |||
8 | :created_on: Aug 20, 2011 |
|
8 | :created_on: Aug 20, 2011 | |
9 | :author: marcink |
|
9 | :author: marcink | |
10 | :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com> |
|
10 | :copyright: (C) 2011-2012 Marcin Kuzminski <marcin@python-works.com> | |
11 | :license: GPLv3, see COPYING for more details. |
|
11 | :license: GPLv3, see COPYING for more details. | |
12 | """ |
|
12 | """ | |
13 | # This program is free software; you can redistribute it and/or |
|
13 | # This program is free software; you can redistribute it and/or | |
14 | # modify it under the terms of the GNU General Public License |
|
14 | # modify it under the terms of the GNU General Public License | |
15 | # as published by the Free Software Foundation; version 2 |
|
15 | # as published by the Free Software Foundation; version 2 | |
16 | # of the License or (at your opinion) any later version of the license. |
|
16 | # of the License or (at your opinion) any later version of the license. | |
17 | # |
|
17 | # | |
18 | # This program is distributed in the hope that it will be useful, |
|
18 | # This program is distributed in the hope that it will be useful, | |
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | # GNU General Public License for more details. |
|
21 | # GNU General Public License for more details. | |
22 | # |
|
22 | # | |
23 | # You should have received a copy of the GNU General Public License |
|
23 | # You should have received a copy of the GNU General Public License | |
24 | # along with this program; if not, write to the Free Software |
|
24 | # along with this program; if not, write to the Free Software | |
25 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
25 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
26 | # MA 02110-1301, USA. |
|
26 | # MA 02110-1301, USA. | |
27 |
|
27 | |||
28 | import traceback |
|
28 | import traceback | |
29 | import logging |
|
29 | import logging | |
30 |
|
30 | |||
31 | from rhodecode.controllers.api import JSONRPCController, JSONRPCError |
|
31 | from rhodecode.controllers.api import JSONRPCController, JSONRPCError | |
32 | from rhodecode.lib.auth import HasPermissionAllDecorator, \ |
|
32 | from rhodecode.lib.auth import HasPermissionAllDecorator, \ | |
33 | HasPermissionAnyDecorator, PasswordGenerator |
|
33 | HasPermissionAnyDecorator, PasswordGenerator | |
34 |
|
34 | |||
35 | from rhodecode.model.meta import Session |
|
35 | from rhodecode.model.meta import Session | |
36 | from rhodecode.model.scm import ScmModel |
|
36 | from rhodecode.model.scm import ScmModel | |
37 | from rhodecode.model.db import User, UsersGroup, RepoGroup, Repository |
|
37 | from rhodecode.model.db import User, UsersGroup, RepoGroup, Repository | |
38 | from rhodecode.model.repo import RepoModel |
|
38 | from rhodecode.model.repo import RepoModel | |
39 | from rhodecode.model.user import UserModel |
|
39 | from rhodecode.model.user import UserModel | |
40 | from rhodecode.model.users_group import UsersGroupModel |
|
40 | from rhodecode.model.users_group import UsersGroupModel | |
41 | from rhodecode.model.repos_group import ReposGroupModel |
|
41 | from rhodecode.model.repos_group import ReposGroupModel | |
42 | from rhodecode.lib.utils import map_groups |
|
42 | from rhodecode.lib.utils import map_groups | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | log = logging.getLogger(__name__) |
|
45 | log = logging.getLogger(__name__) | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | class ApiController(JSONRPCController): |
|
48 | class ApiController(JSONRPCController): | |
49 | """ |
|
49 | """ | |
50 | API Controller |
|
50 | API Controller | |
51 |
|
51 | |||
52 |
|
52 | |||
53 | Each method needs to have USER as argument this is then based on given |
|
53 | Each method needs to have USER as argument this is then based on given | |
54 | API_KEY propagated as instance of user object |
|
54 | API_KEY propagated as instance of user object | |
55 |
|
55 | |||
56 | Preferably this should be first argument also |
|
56 | Preferably this should be first argument also | |
57 |
|
57 | |||
58 |
|
58 | |||
59 | Each function should also **raise** JSONRPCError for any |
|
59 | Each function should also **raise** JSONRPCError for any | |
60 | errors that happens |
|
60 | errors that happens | |
61 |
|
61 | |||
62 | """ |
|
62 | """ | |
63 |
|
63 | |||
64 | @HasPermissionAllDecorator('hg.admin') |
|
64 | @HasPermissionAllDecorator('hg.admin') | |
65 | def pull(self, apiuser, repo_name): |
|
65 | def pull(self, apiuser, repo_name): | |
66 | """ |
|
66 | """ | |
67 | Dispatch pull action on given repo |
|
67 | Dispatch pull action on given repo | |
68 |
|
68 | |||
69 |
|
69 | |||
70 | :param user: |
|
70 | :param user: | |
71 | :param repo_name: |
|
71 | :param repo_name: | |
72 | """ |
|
72 | """ | |
73 |
|
73 | |||
74 | if Repository.is_valid(repo_name) is False: |
|
74 | if Repository.is_valid(repo_name) is False: | |
75 | raise JSONRPCError('Unknown repo "%s"' % repo_name) |
|
75 | raise JSONRPCError('Unknown repo "%s"' % repo_name) | |
76 |
|
76 | |||
77 | try: |
|
77 | try: | |
78 | ScmModel().pull_changes(repo_name, self.rhodecode_user.username) |
|
78 | ScmModel().pull_changes(repo_name, self.rhodecode_user.username) | |
79 | return 'Pulled from %s' % repo_name |
|
79 | return 'Pulled from %s' % repo_name | |
80 | except Exception: |
|
80 | except Exception: | |
81 | raise JSONRPCError('Unable to pull changes from "%s"' % repo_name) |
|
81 | raise JSONRPCError('Unable to pull changes from "%s"' % repo_name) | |
82 |
|
82 | |||
83 | @HasPermissionAllDecorator('hg.admin') |
|
83 | @HasPermissionAllDecorator('hg.admin') | |
84 | def get_user(self, apiuser, userid): |
|
84 | def get_user(self, apiuser, userid): | |
85 | """" |
|
85 | """" | |
86 | Get a user by username |
|
86 | Get a user by username | |
87 |
|
87 | |||
88 | :param apiuser: |
|
88 | :param apiuser: | |
89 | :param username: |
|
89 | :param username: | |
90 | """ |
|
90 | """ | |
91 |
|
91 | |||
92 | user = UserModel().get_user(userid) |
|
92 | user = UserModel().get_user(userid) | |
93 | if user is None: |
|
93 | if user is None: | |
94 | return user |
|
94 | return user | |
95 |
|
95 | |||
96 | return dict( |
|
96 | return dict( | |
97 | id=user.user_id, |
|
97 | id=user.user_id, | |
98 | username=user.username, |
|
98 | username=user.username, | |
99 | firstname=user.name, |
|
99 | firstname=user.name, | |
100 | lastname=user.lastname, |
|
100 | lastname=user.lastname, | |
101 | email=user.email, |
|
101 | email=user.email, | |
102 | active=user.active, |
|
102 | active=user.active, | |
103 | admin=user.admin, |
|
103 | admin=user.admin, | |
104 | ldap_dn=user.ldap_dn |
|
104 | ldap_dn=user.ldap_dn | |
105 | ) |
|
105 | ) | |
106 |
|
106 | |||
107 | @HasPermissionAllDecorator('hg.admin') |
|
107 | @HasPermissionAllDecorator('hg.admin') | |
108 | def get_users(self, apiuser): |
|
108 | def get_users(self, apiuser): | |
109 | """" |
|
109 | """" | |
110 | Get all users |
|
110 | Get all users | |
111 |
|
111 | |||
112 | :param apiuser: |
|
112 | :param apiuser: | |
113 | """ |
|
113 | """ | |
114 |
|
114 | |||
115 | result = [] |
|
115 | result = [] | |
116 | for user in User.getAll(): |
|
116 | for user in User.getAll(): | |
117 | result.append( |
|
117 | result.append( | |
118 | dict( |
|
118 | dict( | |
119 | id=user.user_id, |
|
119 | id=user.user_id, | |
120 | username=user.username, |
|
120 | username=user.username, | |
121 | firstname=user.name, |
|
121 | firstname=user.name, | |
122 | lastname=user.lastname, |
|
122 | lastname=user.lastname, | |
123 | email=user.email, |
|
123 | email=user.email, | |
124 | active=user.active, |
|
124 | active=user.active, | |
125 | admin=user.admin, |
|
125 | admin=user.admin, | |
126 | ldap_dn=user.ldap_dn |
|
126 | ldap_dn=user.ldap_dn | |
127 | ) |
|
127 | ) | |
128 | ) |
|
128 | ) | |
129 | return result |
|
129 | return result | |
130 |
|
130 | |||
131 | @HasPermissionAllDecorator('hg.admin') |
|
131 | @HasPermissionAllDecorator('hg.admin') | |
132 | def create_user(self, apiuser, username, email, password, firstname=None, |
|
132 | def create_user(self, apiuser, username, email, password, firstname=None, | |
133 | lastname=None, active=True, admin=False, ldap_dn=None): |
|
133 | lastname=None, active=True, admin=False, ldap_dn=None): | |
134 | """ |
|
134 | """ | |
135 | Create new user |
|
135 | Create new user | |
136 |
|
136 | |||
137 | :param apiuser: |
|
137 | :param apiuser: | |
138 | :param username: |
|
138 | :param username: | |
139 | :param password: |
|
139 | :param password: | |
140 | :param email: |
|
140 | :param email: | |
141 | :param name: |
|
141 | :param name: | |
142 | :param lastname: |
|
142 | :param lastname: | |
143 | :param active: |
|
143 | :param active: | |
144 | :param admin: |
|
144 | :param admin: | |
145 | :param ldap_dn: |
|
145 | :param ldap_dn: | |
146 | """ |
|
146 | """ | |
147 | if User.get_by_username(username): |
|
147 | if User.get_by_username(username): | |
148 | raise JSONRPCError("user %s already exist" % username) |
|
148 | raise JSONRPCError("user %s already exist" % username) | |
149 |
|
149 | |||
150 | if User.get_by_email(email, case_insensitive=True): |
|
150 | if User.get_by_email(email, case_insensitive=True): | |
151 | raise JSONRPCError("email %s already exist" % email) |
|
151 | raise JSONRPCError("email %s already exist" % email) | |
152 |
|
152 | |||
153 | if ldap_dn: |
|
153 | if ldap_dn: | |
154 | # generate temporary password if ldap_dn |
|
154 | # generate temporary password if ldap_dn | |
155 | password = PasswordGenerator().gen_password(length=8) |
|
155 | password = PasswordGenerator().gen_password(length=8) | |
156 |
|
156 | |||
157 | try: |
|
157 | try: | |
158 | usr = UserModel().create_or_update( |
|
158 | usr = UserModel().create_or_update( | |
159 | username, password, email, firstname, |
|
159 | username, password, email, firstname, | |
160 | lastname, active, admin, ldap_dn |
|
160 | lastname, active, admin, ldap_dn | |
161 | ) |
|
161 | ) | |
162 | Session.commit() |
|
162 | Session.commit() | |
163 | return dict( |
|
163 | return dict( | |
164 | id=usr.user_id, |
|
164 | id=usr.user_id, | |
165 | msg='created new user %s' % username |
|
165 | msg='created new user %s' % username | |
166 | ) |
|
166 | ) | |
167 | except Exception: |
|
167 | except Exception: | |
168 | log.error(traceback.format_exc()) |
|
168 | log.error(traceback.format_exc()) | |
169 | raise JSONRPCError('failed to create user %s' % username) |
|
169 | raise JSONRPCError('failed to create user %s' % username) | |
170 |
|
170 | |||
171 | @HasPermissionAllDecorator('hg.admin') |
|
171 | @HasPermissionAllDecorator('hg.admin') | |
172 | def update_user(self, apiuser, userid, username, password, email, |
|
172 | def update_user(self, apiuser, userid, username, password, email, | |
173 | firstname, lastname, active, admin, ldap_dn): |
|
173 | firstname, lastname, active, admin, ldap_dn): | |
174 | """ |
|
174 | """ | |
175 | Updates given user |
|
175 | Updates given user | |
176 |
|
176 | |||
177 | :param apiuser: |
|
177 | :param apiuser: | |
178 | :param username: |
|
178 | :param username: | |
179 | :param password: |
|
179 | :param password: | |
180 | :param email: |
|
180 | :param email: | |
181 | :param name: |
|
181 | :param name: | |
182 | :param lastname: |
|
182 | :param lastname: | |
183 | :param active: |
|
183 | :param active: | |
184 | :param admin: |
|
184 | :param admin: | |
185 | :param ldap_dn: |
|
185 | :param ldap_dn: | |
186 | """ |
|
186 | """ | |
187 | if not UserModel().get_user(userid): |
|
187 | if not UserModel().get_user(userid): | |
188 | raise JSONRPCError("user %s does not exist" % username) |
|
188 | raise JSONRPCError("user %s does not exist" % username) | |
189 |
|
189 | |||
190 | try: |
|
190 | try: | |
191 | usr = UserModel().create_or_update( |
|
191 | usr = UserModel().create_or_update( | |
192 | username, password, email, firstname, |
|
192 | username, password, email, firstname, | |
193 | lastname, active, admin, ldap_dn |
|
193 | lastname, active, admin, ldap_dn | |
194 | ) |
|
194 | ) | |
195 | Session.commit() |
|
195 | Session.commit() | |
196 | return dict( |
|
196 | return dict( | |
197 | id=usr.user_id, |
|
197 | id=usr.user_id, | |
198 | msg='updated user %s' % username |
|
198 | msg='updated user %s' % username | |
199 | ) |
|
199 | ) | |
200 | except Exception: |
|
200 | except Exception: | |
201 | log.error(traceback.format_exc()) |
|
201 | log.error(traceback.format_exc()) | |
202 | raise JSONRPCError('failed to update user %s' % username) |
|
202 | raise JSONRPCError('failed to update user %s' % username) | |
203 |
|
203 | |||
204 | @HasPermissionAllDecorator('hg.admin') |
|
204 | @HasPermissionAllDecorator('hg.admin') | |
205 | def get_users_group(self, apiuser, group_name): |
|
205 | def get_users_group(self, apiuser, group_name): | |
206 | """" |
|
206 | """" | |
207 | Get users group by name |
|
207 | Get users group by name | |
208 |
|
208 | |||
209 | :param apiuser: |
|
209 | :param apiuser: | |
210 | :param group_name: |
|
210 | :param group_name: | |
211 | """ |
|
211 | """ | |
212 |
|
212 | |||
213 | users_group = UsersGroup.get_by_group_name(group_name) |
|
213 | users_group = UsersGroup.get_by_group_name(group_name) | |
214 | if not users_group: |
|
214 | if not users_group: | |
215 | return None |
|
215 | return None | |
216 |
|
216 | |||
217 | members = [] |
|
217 | members = [] | |
218 | for user in users_group.members: |
|
218 | for user in users_group.members: | |
219 | user = user.user |
|
219 | user = user.user | |
220 | members.append(dict(id=user.user_id, |
|
220 | members.append(dict(id=user.user_id, | |
221 | username=user.username, |
|
221 | username=user.username, | |
222 | firstname=user.name, |
|
222 | firstname=user.name, | |
223 | lastname=user.lastname, |
|
223 | lastname=user.lastname, | |
224 | email=user.email, |
|
224 | email=user.email, | |
225 | active=user.active, |
|
225 | active=user.active, | |
226 | admin=user.admin, |
|
226 | admin=user.admin, | |
227 | ldap=user.ldap_dn)) |
|
227 | ldap=user.ldap_dn)) | |
228 |
|
228 | |||
229 | return dict(id=users_group.users_group_id, |
|
229 | return dict(id=users_group.users_group_id, | |
230 | group_name=users_group.users_group_name, |
|
230 | group_name=users_group.users_group_name, | |
231 | active=users_group.users_group_active, |
|
231 | active=users_group.users_group_active, | |
232 | members=members) |
|
232 | members=members) | |
233 |
|
233 | |||
234 | @HasPermissionAllDecorator('hg.admin') |
|
234 | @HasPermissionAllDecorator('hg.admin') | |
235 | def get_users_groups(self, apiuser): |
|
235 | def get_users_groups(self, apiuser): | |
236 | """" |
|
236 | """" | |
237 | Get all users groups |
|
237 | Get all users groups | |
238 |
|
238 | |||
239 | :param apiuser: |
|
239 | :param apiuser: | |
240 | """ |
|
240 | """ | |
241 |
|
241 | |||
242 | result = [] |
|
242 | result = [] | |
243 | for users_group in UsersGroup.getAll(): |
|
243 | for users_group in UsersGroup.getAll(): | |
244 | members = [] |
|
244 | members = [] | |
245 | for user in users_group.members: |
|
245 | for user in users_group.members: | |
246 | user = user.user |
|
246 | user = user.user | |
247 | members.append(dict(id=user.user_id, |
|
247 | members.append(dict(id=user.user_id, | |
248 | username=user.username, |
|
248 | username=user.username, | |
249 | firstname=user.name, |
|
249 | firstname=user.name, | |
250 | lastname=user.lastname, |
|
250 | lastname=user.lastname, | |
251 | email=user.email, |
|
251 | email=user.email, | |
252 | active=user.active, |
|
252 | active=user.active, | |
253 | admin=user.admin, |
|
253 | admin=user.admin, | |
254 | ldap=user.ldap_dn)) |
|
254 | ldap=user.ldap_dn)) | |
255 |
|
255 | |||
256 | result.append(dict(id=users_group.users_group_id, |
|
256 | result.append(dict(id=users_group.users_group_id, | |
257 | group_name=users_group.users_group_name, |
|
257 | group_name=users_group.users_group_name, | |
258 | active=users_group.users_group_active, |
|
258 | active=users_group.users_group_active, | |
259 | members=members)) |
|
259 | members=members)) | |
260 | return result |
|
260 | return result | |
261 |
|
261 | |||
262 | @HasPermissionAllDecorator('hg.admin') |
|
262 | @HasPermissionAllDecorator('hg.admin') | |
263 | def create_users_group(self, apiuser, group_name, active=True): |
|
263 | def create_users_group(self, apiuser, group_name, active=True): | |
264 | """ |
|
264 | """ | |
265 | Creates an new usergroup |
|
265 | Creates an new usergroup | |
266 |
|
266 | |||
267 | :param group_name: |
|
267 | :param group_name: | |
268 | :param active: |
|
268 | :param active: | |
269 | """ |
|
269 | """ | |
270 |
|
270 | |||
271 | if self.get_users_group(apiuser, group_name): |
|
271 | if self.get_users_group(apiuser, group_name): | |
272 | raise JSONRPCError("users group %s already exist" % group_name) |
|
272 | raise JSONRPCError("users group %s already exist" % group_name) | |
273 |
|
273 | |||
274 | try: |
|
274 | try: | |
275 | ug = UsersGroupModel().create(name=group_name, active=active) |
|
275 | ug = UsersGroupModel().create(name=group_name, active=active) | |
276 | Session.commit() |
|
276 | Session.commit() | |
277 | return dict(id=ug.users_group_id, |
|
277 | return dict(id=ug.users_group_id, | |
278 | msg='created new users group %s' % group_name) |
|
278 | msg='created new users group %s' % group_name) | |
279 | except Exception: |
|
279 | except Exception: | |
280 | log.error(traceback.format_exc()) |
|
280 | log.error(traceback.format_exc()) | |
281 | raise JSONRPCError('failed to create group %s' % group_name) |
|
281 | raise JSONRPCError('failed to create group %s' % group_name) | |
282 |
|
282 | |||
283 | @HasPermissionAllDecorator('hg.admin') |
|
283 | @HasPermissionAllDecorator('hg.admin') | |
284 | def add_user_to_users_group(self, apiuser, group_name, username): |
|
284 | def add_user_to_users_group(self, apiuser, group_name, username): | |
285 | """" |
|
285 | """" | |
286 | Add a user to a group |
|
286 | Add a user to a users group | |
287 |
|
287 | |||
288 | :param apiuser: |
|
288 | :param apiuser: | |
289 | :param group_name: |
|
289 | :param group_name: | |
290 | :param username: |
|
290 | :param username: | |
291 | """ |
|
291 | """ | |
292 |
|
292 | |||
293 | try: |
|
293 | try: | |
294 | users_group = UsersGroup.get_by_group_name(group_name) |
|
294 | users_group = UsersGroup.get_by_group_name(group_name) | |
295 | if not users_group: |
|
295 | if not users_group: | |
296 | raise JSONRPCError('unknown users group %s' % group_name) |
|
296 | raise JSONRPCError('unknown users group %s' % group_name) | |
297 |
|
297 | |||
298 | user = User.get_by_username(username) |
|
298 | user = User.get_by_username(username) | |
299 | if user is None: |
|
299 | if user is None: | |
300 | raise JSONRPCError('unknown user %s' % username) |
|
300 | raise JSONRPCError('unknown user %s' % username) | |
301 |
|
301 | |||
302 | ugm = UsersGroupModel().add_user_to_group(users_group, user) |
|
302 | ugm = UsersGroupModel().add_user_to_group(users_group, user) | |
303 | success = True if ugm != True else False |
|
303 | success = True if ugm != True else False | |
304 | msg = 'added member %s to users group %s' % (username, group_name) |
|
304 | msg = 'added member %s to users group %s' % (username, group_name) | |
305 | msg = msg if success else 'User is already in that group' |
|
305 | msg = msg if success else 'User is already in that group' | |
306 | Session.commit() |
|
306 | Session.commit() | |
307 |
|
307 | |||
308 | return dict( |
|
308 | return dict( | |
309 | id=ugm.users_group_member_id if ugm != True else None, |
|
309 | id=ugm.users_group_member_id if ugm != True else None, | |
310 | success=success, |
|
310 | success=success, | |
311 | msg=msg |
|
311 | msg=msg | |
312 | ) |
|
312 | ) | |
313 | except Exception: |
|
313 | except Exception: | |
314 | log.error(traceback.format_exc()) |
|
314 | log.error(traceback.format_exc()) | |
315 | raise JSONRPCError('failed to add users group member') |
|
315 | raise JSONRPCError('failed to add users group member') | |
316 |
|
316 | |||
317 | @HasPermissionAllDecorator('hg.admin') |
|
317 | @HasPermissionAllDecorator('hg.admin') | |
318 | def remove_user_from_users_group(self, apiuser, group_name, username): |
|
318 | def remove_user_from_users_group(self, apiuser, group_name, username): | |
319 | """ |
|
319 | """ | |
320 | Remove user from a group |
|
320 | Remove user from a group | |
321 |
|
321 | |||
322 | :param apiuser |
|
322 | :param apiuser | |
323 | :param group_name |
|
323 | :param group_name | |
324 | :param username |
|
324 | :param username | |
325 | """ |
|
325 | """ | |
326 |
|
326 | |||
327 | try: |
|
327 | try: | |
328 | users_group = UsersGroup.get_by_group_name(group_name) |
|
328 | users_group = UsersGroup.get_by_group_name(group_name) | |
329 | if not users_group: |
|
329 | if not users_group: | |
330 | raise JSONRPCError('unknown users group %s' % group_name) |
|
330 | raise JSONRPCError('unknown users group %s' % group_name) | |
331 |
|
331 | |||
332 | user = User.get_by_username(username) |
|
332 | user = User.get_by_username(username) | |
333 | if user is None: |
|
333 | if user is None: | |
334 | raise JSONRPCError('unknown user %s' % username) |
|
334 | raise JSONRPCError('unknown user %s' % username) | |
335 |
|
335 | |||
336 | success = UsersGroupModel().remove_user_from_group(users_group, user) |
|
336 | success = UsersGroupModel().remove_user_from_group(users_group, user) | |
337 | msg = 'removed member %s from users group %s' % (username, group_name) |
|
337 | msg = 'removed member %s from users group %s' % (username, group_name) | |
338 | msg = msg if success else "User wasn't in group" |
|
338 | msg = msg if success else "User wasn't in group" | |
339 | Session.commit() |
|
339 | Session.commit() | |
340 | return dict(success=success, msg=msg) |
|
340 | return dict(success=success, msg=msg) | |
341 | except Exception: |
|
341 | except Exception: | |
342 | log.error(traceback.format_exc()) |
|
342 | log.error(traceback.format_exc()) | |
343 | raise JSONRPCError('failed to remove user from group') |
|
343 | raise JSONRPCError('failed to remove user from group') | |
344 |
|
344 | |||
345 | @HasPermissionAnyDecorator('hg.admin') |
|
345 | @HasPermissionAnyDecorator('hg.admin') | |
346 | def get_repo(self, apiuser, repoid): |
|
346 | def get_repo(self, apiuser, repoid): | |
347 | """" |
|
347 | """" | |
348 | Get repository by name |
|
348 | Get repository by name | |
349 |
|
349 | |||
350 | :param apiuser: |
|
350 | :param apiuser: | |
351 | :param repo_name: |
|
351 | :param repo_name: | |
352 | """ |
|
352 | """ | |
353 |
|
353 | |||
354 | repo = RepoModel().get_repo(repoid) |
|
354 | repo = RepoModel().get_repo(repoid) | |
355 | if repo is None: |
|
355 | if repo is None: | |
356 | raise JSONRPCError('unknown repository %s' % repo) |
|
356 | raise JSONRPCError('unknown repository %s' % repo) | |
357 |
|
357 | |||
358 | members = [] |
|
358 | members = [] | |
359 | for user in repo.repo_to_perm: |
|
359 | for user in repo.repo_to_perm: | |
360 | perm = user.permission.permission_name |
|
360 | perm = user.permission.permission_name | |
361 | user = user.user |
|
361 | user = user.user | |
362 | members.append( |
|
362 | members.append( | |
363 | dict( |
|
363 | dict( | |
364 |
type |
|
364 | type="user", | |
365 | id=user.user_id, |
|
365 | id=user.user_id, | |
366 | username=user.username, |
|
366 | username=user.username, | |
367 | firstname=user.name, |
|
367 | firstname=user.name, | |
368 | lastname=user.lastname, |
|
368 | lastname=user.lastname, | |
369 | email=user.email, |
|
369 | email=user.email, | |
370 | active=user.active, |
|
370 | active=user.active, | |
371 | admin=user.admin, |
|
371 | admin=user.admin, | |
372 | ldap=user.ldap_dn, |
|
372 | ldap=user.ldap_dn, | |
373 | permission=perm |
|
373 | permission=perm | |
374 | ) |
|
374 | ) | |
375 | ) |
|
375 | ) | |
376 | for users_group in repo.users_group_to_perm: |
|
376 | for users_group in repo.users_group_to_perm: | |
377 | perm = users_group.permission.permission_name |
|
377 | perm = users_group.permission.permission_name | |
378 | users_group = users_group.users_group |
|
378 | users_group = users_group.users_group | |
379 | members.append( |
|
379 | members.append( | |
380 | dict( |
|
380 | dict( | |
381 |
type |
|
381 | type="users_group", | |
382 | id=users_group.users_group_id, |
|
382 | id=users_group.users_group_id, | |
383 | name=users_group.users_group_name, |
|
383 | name=users_group.users_group_name, | |
384 | active=users_group.users_group_active, |
|
384 | active=users_group.users_group_active, | |
385 | permission=perm |
|
385 | permission=perm | |
386 | ) |
|
386 | ) | |
387 | ) |
|
387 | ) | |
388 |
|
388 | |||
389 | return dict( |
|
389 | return dict( | |
390 | id=repo.repo_id, |
|
390 | id=repo.repo_id, | |
391 | repo_name=repo.repo_name, |
|
391 | repo_name=repo.repo_name, | |
392 | type=repo.repo_type, |
|
392 | type=repo.repo_type, | |
393 | description=repo.description, |
|
393 | description=repo.description, | |
394 | members=members |
|
394 | members=members | |
395 | ) |
|
395 | ) | |
396 |
|
396 | |||
397 | @HasPermissionAnyDecorator('hg.admin') |
|
397 | @HasPermissionAnyDecorator('hg.admin') | |
398 | def get_repos(self, apiuser): |
|
398 | def get_repos(self, apiuser): | |
399 | """" |
|
399 | """" | |
400 | Get all repositories |
|
400 | Get all repositories | |
401 |
|
401 | |||
402 | :param apiuser: |
|
402 | :param apiuser: | |
403 | """ |
|
403 | """ | |
404 |
|
404 | |||
405 | result = [] |
|
405 | result = [] | |
406 | for repository in Repository.getAll(): |
|
406 | for repository in Repository.getAll(): | |
407 | result.append( |
|
407 | result.append( | |
408 | dict( |
|
408 | dict( | |
409 | id=repository.repo_id, |
|
409 | id=repository.repo_id, | |
410 | repo_name=repository.repo_name, |
|
410 | repo_name=repository.repo_name, | |
411 | type=repository.repo_type, |
|
411 | type=repository.repo_type, | |
412 | description=repository.description |
|
412 | description=repository.description | |
413 | ) |
|
413 | ) | |
414 | ) |
|
414 | ) | |
415 | return result |
|
415 | return result | |
416 |
|
416 | |||
417 | @HasPermissionAnyDecorator('hg.admin') |
|
417 | @HasPermissionAnyDecorator('hg.admin') | |
418 | def get_repo_nodes(self, apiuser, repo_name, revision, root_path, |
|
418 | def get_repo_nodes(self, apiuser, repo_name, revision, root_path, | |
419 | ret_type='all'): |
|
419 | ret_type='all'): | |
420 | """ |
|
420 | """ | |
421 | returns a list of nodes and it's children |
|
421 | returns a list of nodes and it's children | |
422 | for a given path at given revision. It's possible to specify ret_type |
|
422 | for a given path at given revision. It's possible to specify ret_type | |
423 | to show only files or dirs |
|
423 | to show only files or dirs | |
424 |
|
424 | |||
425 | :param apiuser: |
|
425 | :param apiuser: | |
426 | :param repo_name: name of repository |
|
426 | :param repo_name: name of repository | |
427 | :param revision: revision for which listing should be done |
|
427 | :param revision: revision for which listing should be done | |
428 | :param root_path: path from which start displaying |
|
428 | :param root_path: path from which start displaying | |
429 | :param ret_type: return type 'all|files|dirs' nodes |
|
429 | :param ret_type: return type 'all|files|dirs' nodes | |
430 | """ |
|
430 | """ | |
431 | try: |
|
431 | try: | |
432 | _d, _f = ScmModel().get_nodes(repo_name, revision, root_path, |
|
432 | _d, _f = ScmModel().get_nodes(repo_name, revision, root_path, | |
433 | flat=False) |
|
433 | flat=False) | |
434 | _map = { |
|
434 | _map = { | |
435 | 'all': _d + _f, |
|
435 | 'all': _d + _f, | |
436 | 'files': _f, |
|
436 | 'files': _f, | |
437 | 'dirs': _d, |
|
437 | 'dirs': _d, | |
438 | } |
|
438 | } | |
439 | return _map[ret_type] |
|
439 | return _map[ret_type] | |
440 | except KeyError: |
|
440 | except KeyError: | |
441 | raise JSONRPCError('ret_type must be one of %s' % _map.keys()) |
|
441 | raise JSONRPCError('ret_type must be one of %s' % _map.keys()) | |
442 | except Exception, e: |
|
442 | except Exception, e: | |
443 | raise JSONRPCError(e) |
|
443 | raise JSONRPCError(e) | |
444 |
|
444 | |||
445 | @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') |
|
445 | @HasPermissionAnyDecorator('hg.admin', 'hg.create.repository') | |
446 | def create_repo(self, apiuser, repo_name, owner_name, description='', |
|
446 | def create_repo(self, apiuser, repo_name, owner_name, description='', | |
447 | repo_type='hg', private=False, clone_uri=None): |
|
447 | repo_type='hg', private=False, clone_uri=None): | |
448 | """ |
|
448 | """ | |
449 | Create repository, if clone_url is given it makes a remote clone |
|
449 | Create repository, if clone_url is given it makes a remote clone | |
450 |
|
450 | |||
451 | :param apiuser: |
|
451 | :param apiuser: | |
452 | :param repo_name: |
|
452 | :param repo_name: | |
453 | :param owner_name: |
|
453 | :param owner_name: | |
454 | :param description: |
|
454 | :param description: | |
455 | :param repo_type: |
|
455 | :param repo_type: | |
456 | :param private: |
|
456 | :param private: | |
457 | :param clone_uri: |
|
457 | :param clone_uri: | |
458 | """ |
|
458 | """ | |
459 |
|
459 | |||
460 | try: |
|
460 | try: | |
461 | owner = User.get_by_username(owner_name) |
|
461 | owner = User.get_by_username(owner_name) | |
462 | if owner is None: |
|
462 | if owner is None: | |
463 | raise JSONRPCError('unknown user %s' % owner_name) |
|
463 | raise JSONRPCError('unknown user %s' % owner_name) | |
464 |
|
464 | |||
465 | if Repository.get_by_repo_name(repo_name): |
|
465 | if Repository.get_by_repo_name(repo_name): | |
466 | raise JSONRPCError("repo %s already exist" % repo_name) |
|
466 | raise JSONRPCError("repo %s already exist" % repo_name) | |
467 |
|
467 | |||
468 | groups = repo_name.split(Repository.url_sep()) |
|
468 | groups = repo_name.split(Repository.url_sep()) | |
469 | real_name = groups[-1] |
|
469 | real_name = groups[-1] | |
470 | # create structure of groups |
|
470 | # create structure of groups | |
471 | group = map_groups(repo_name) |
|
471 | group = map_groups(repo_name) | |
472 |
|
472 | |||
473 | repo = RepoModel().create( |
|
473 | repo = RepoModel().create( | |
474 | dict( |
|
474 | dict( | |
475 | repo_name=real_name, |
|
475 | repo_name=real_name, | |
476 | repo_name_full=repo_name, |
|
476 | repo_name_full=repo_name, | |
477 | description=description, |
|
477 | description=description, | |
478 | private=private, |
|
478 | private=private, | |
479 | repo_type=repo_type, |
|
479 | repo_type=repo_type, | |
480 | repo_group=group.group_id if group else None, |
|
480 | repo_group=group.group_id if group else None, | |
481 | clone_uri=clone_uri |
|
481 | clone_uri=clone_uri | |
482 | ), |
|
482 | ), | |
483 | owner |
|
483 | owner | |
484 | ) |
|
484 | ) | |
485 | Session.commit() |
|
485 | Session.commit() | |
486 |
|
486 | |||
487 | return dict( |
|
487 | return dict( | |
488 | id=repo.repo_id, |
|
488 | id=repo.repo_id, | |
489 | msg="Created new repository %s" % repo.repo_name |
|
489 | msg="Created new repository %s" % repo.repo_name | |
490 | ) |
|
490 | ) | |
491 |
|
491 | |||
492 | except Exception: |
|
492 | except Exception: | |
493 | log.error(traceback.format_exc()) |
|
493 | log.error(traceback.format_exc()) | |
494 | raise JSONRPCError('failed to create repository %s' % repo_name) |
|
494 | raise JSONRPCError('failed to create repository %s' % repo_name) | |
495 |
|
495 | |||
496 | @HasPermissionAnyDecorator('hg.admin') |
|
496 | @HasPermissionAnyDecorator('hg.admin') | |
497 | def delete_repo(self, apiuser, repo_name): |
|
497 | def delete_repo(self, apiuser, repo_name): | |
498 | """ |
|
498 | """ | |
499 | Deletes a given repository |
|
499 | Deletes a given repository | |
500 |
|
500 | |||
501 | :param repo_name: |
|
501 | :param repo_name: | |
502 | """ |
|
502 | """ | |
503 | if not Repository.get_by_repo_name(repo_name): |
|
503 | if not Repository.get_by_repo_name(repo_name): | |
504 | raise JSONRPCError("repo %s does not exist" % repo_name) |
|
504 | raise JSONRPCError("repo %s does not exist" % repo_name) | |
505 | try: |
|
505 | try: | |
506 | RepoModel().delete(repo_name) |
|
506 | RepoModel().delete(repo_name) | |
507 | Session.commit() |
|
507 | Session.commit() | |
508 | return dict( |
|
508 | return dict( | |
509 | msg='Deleted repository %s' % repo_name |
|
509 | msg='Deleted repository %s' % repo_name | |
510 | ) |
|
510 | ) | |
511 | except Exception: |
|
511 | except Exception: | |
512 | log.error(traceback.format_exc()) |
|
512 | log.error(traceback.format_exc()) | |
513 | raise JSONRPCError('failed to delete repository %s' % repo_name) |
|
513 | raise JSONRPCError('failed to delete repository %s' % repo_name) | |
514 |
|
514 | |||
515 | @HasPermissionAnyDecorator('hg.admin') |
|
515 | @HasPermissionAnyDecorator('hg.admin') | |
516 | def grant_user_permission(self, apiuser, repo_name, username, perm): |
|
516 | def grant_user_permission(self, apiuser, repo_name, username, perm): | |
517 | """ |
|
517 | """ | |
518 | Grant permission for user on given repository, or update existing one |
|
518 | Grant permission for user on given repository, or update existing one | |
519 | if found |
|
519 | if found | |
520 |
|
520 | |||
521 | :param repo_name: |
|
521 | :param repo_name: | |
522 | :param username: |
|
522 | :param username: | |
523 | :param perm: |
|
523 | :param perm: | |
524 | """ |
|
524 | """ | |
525 |
|
525 | |||
526 | try: |
|
526 | try: | |
527 | repo = Repository.get_by_repo_name(repo_name) |
|
527 | repo = Repository.get_by_repo_name(repo_name) | |
528 | if repo is None: |
|
528 | if repo is None: | |
529 | raise JSONRPCError('unknown repository %s' % repo) |
|
529 | raise JSONRPCError('unknown repository %s' % repo) | |
530 |
|
530 | |||
531 | user = User.get_by_username(username) |
|
531 | user = User.get_by_username(username) | |
532 | if user is None: |
|
532 | if user is None: | |
533 | raise JSONRPCError('unknown user %s' % username) |
|
533 | raise JSONRPCError('unknown user %s' % username) | |
534 |
|
534 | |||
535 | RepoModel().grant_user_permission(repo=repo, user=user, perm=perm) |
|
535 | RepoModel().grant_user_permission(repo=repo, user=user, perm=perm) | |
536 |
|
536 | |||
537 | Session.commit() |
|
537 | Session.commit() | |
538 | return dict( |
|
538 | return dict( | |
539 | msg='Granted perm: %s for user: %s in repo: %s' % ( |
|
539 | msg='Granted perm: %s for user: %s in repo: %s' % ( | |
540 | perm, username, repo_name |
|
540 | perm, username, repo_name | |
541 | ) |
|
541 | ) | |
542 | ) |
|
542 | ) | |
543 | except Exception: |
|
543 | except Exception: | |
544 | log.error(traceback.format_exc()) |
|
544 | log.error(traceback.format_exc()) | |
545 | raise JSONRPCError( |
|
545 | raise JSONRPCError( | |
546 | 'failed to edit permission %(repo)s for %(user)s' % dict( |
|
546 | 'failed to edit permission %(repo)s for %(user)s' % dict( | |
547 | user=username, repo=repo_name |
|
547 | user=username, repo=repo_name | |
548 | ) |
|
548 | ) | |
549 | ) |
|
549 | ) | |
550 |
|
550 | |||
551 | @HasPermissionAnyDecorator('hg.admin') |
|
551 | @HasPermissionAnyDecorator('hg.admin') | |
552 | def revoke_user_permission(self, apiuser, repo_name, username): |
|
552 | def revoke_user_permission(self, apiuser, repo_name, username): | |
553 | """ |
|
553 | """ | |
554 | Revoke permission for user on given repository |
|
554 | Revoke permission for user on given repository | |
555 |
|
555 | |||
556 | :param repo_name: |
|
556 | :param repo_name: | |
557 | :param username: |
|
557 | :param username: | |
558 | """ |
|
558 | """ | |
559 |
|
559 | |||
560 | try: |
|
560 | try: | |
561 | repo = Repository.get_by_repo_name(repo_name) |
|
561 | repo = Repository.get_by_repo_name(repo_name) | |
562 | if repo is None: |
|
562 | if repo is None: | |
563 | raise JSONRPCError('unknown repository %s' % repo) |
|
563 | raise JSONRPCError('unknown repository %s' % repo) | |
564 |
|
564 | |||
565 | user = User.get_by_username(username) |
|
565 | user = User.get_by_username(username) | |
566 | if user is None: |
|
566 | if user is None: | |
567 | raise JSONRPCError('unknown user %s' % username) |
|
567 | raise JSONRPCError('unknown user %s' % username) | |
568 |
|
568 | |||
569 | RepoModel().revoke_user_permission(repo=repo_name, user=username) |
|
569 | RepoModel().revoke_user_permission(repo=repo_name, user=username) | |
570 |
|
570 | |||
571 | Session.commit() |
|
571 | Session.commit() | |
572 | return dict( |
|
572 | return dict( | |
573 | msg='Revoked perm for user: %s in repo: %s' % ( |
|
573 | msg='Revoked perm for user: %s in repo: %s' % ( | |
574 | username, repo_name |
|
574 | username, repo_name | |
575 | ) |
|
575 | ) | |
576 | ) |
|
576 | ) | |
577 | except Exception: |
|
577 | except Exception: | |
578 | log.error(traceback.format_exc()) |
|
578 | log.error(traceback.format_exc()) | |
579 | raise JSONRPCError( |
|
579 | raise JSONRPCError( | |
580 | 'failed to edit permission %(repo)s for %(user)s' % dict( |
|
580 | 'failed to edit permission %(repo)s for %(user)s' % dict( | |
581 | user=username, repo=repo_name |
|
581 | user=username, repo=repo_name | |
582 | ) |
|
582 | ) | |
583 | ) |
|
583 | ) | |
584 |
|
584 | |||
585 | @HasPermissionAnyDecorator('hg.admin') |
|
585 | @HasPermissionAnyDecorator('hg.admin') | |
586 | def grant_users_group_permission(self, apiuser, repo_name, group_name, perm): |
|
586 | def grant_users_group_permission(self, apiuser, repo_name, group_name, perm): | |
587 | """ |
|
587 | """ | |
588 | Grant permission for users group on given repository, or update |
|
588 | Grant permission for users group on given repository, or update | |
589 | existing one if found |
|
589 | existing one if found | |
590 |
|
590 | |||
591 | :param repo_name: |
|
591 | :param repo_name: | |
592 | :param group_name: |
|
592 | :param group_name: | |
593 | :param perm: |
|
593 | :param perm: | |
594 | """ |
|
594 | """ | |
595 |
|
595 | |||
596 | try: |
|
596 | try: | |
597 | repo = Repository.get_by_repo_name(repo_name) |
|
597 | repo = Repository.get_by_repo_name(repo_name) | |
598 | if repo is None: |
|
598 | if repo is None: | |
599 | raise JSONRPCError('unknown repository %s' % repo) |
|
599 | raise JSONRPCError('unknown repository %s' % repo) | |
600 |
|
600 | |||
601 | user_group = UsersGroup.get_by_group_name(group_name) |
|
601 | user_group = UsersGroup.get_by_group_name(group_name) | |
602 | if user_group is None: |
|
602 | if user_group is None: | |
603 | raise JSONRPCError('unknown users group %s' % user_group) |
|
603 | raise JSONRPCError('unknown users group %s' % user_group) | |
604 |
|
604 | |||
605 | RepoModel().grant_users_group_permission(repo=repo_name, |
|
605 | RepoModel().grant_users_group_permission(repo=repo_name, | |
606 | group_name=group_name, |
|
606 | group_name=group_name, | |
607 | perm=perm) |
|
607 | perm=perm) | |
608 |
|
608 | |||
609 | Session.commit() |
|
609 | Session.commit() | |
610 | return dict( |
|
610 | return dict( | |
611 | msg='Granted perm: %s for group: %s in repo: %s' % ( |
|
611 | msg='Granted perm: %s for group: %s in repo: %s' % ( | |
612 | perm, group_name, repo_name |
|
612 | perm, group_name, repo_name | |
613 | ) |
|
613 | ) | |
614 | ) |
|
614 | ) | |
615 | except Exception: |
|
615 | except Exception: | |
616 | log.error(traceback.format_exc()) |
|
616 | log.error(traceback.format_exc()) | |
617 | raise JSONRPCError( |
|
617 | raise JSONRPCError( | |
618 | 'failed to edit permission %(repo)s for %(usersgr)s' % dict( |
|
618 | 'failed to edit permission %(repo)s for %(usersgr)s' % dict( | |
619 | usersgr=group_name, repo=repo_name |
|
619 | usersgr=group_name, repo=repo_name | |
620 | ) |
|
620 | ) | |
621 | ) |
|
621 | ) | |
622 |
|
622 | |||
623 | @HasPermissionAnyDecorator('hg.admin') |
|
623 | @HasPermissionAnyDecorator('hg.admin') | |
624 | def revoke_users_group_permission(self, apiuser, repo_name, group_name): |
|
624 | def revoke_users_group_permission(self, apiuser, repo_name, group_name): | |
625 | """ |
|
625 | """ | |
626 | Revoke permission for users group on given repository |
|
626 | Revoke permission for users group on given repository | |
627 |
|
627 | |||
628 | :param repo_name: |
|
628 | :param repo_name: | |
629 | :param group_name: |
|
629 | :param group_name: | |
630 | """ |
|
630 | """ | |
631 |
|
631 | |||
632 | try: |
|
632 | try: | |
633 | repo = Repository.get_by_repo_name(repo_name) |
|
633 | repo = Repository.get_by_repo_name(repo_name) | |
634 | if repo is None: |
|
634 | if repo is None: | |
635 | raise JSONRPCError('unknown repository %s' % repo) |
|
635 | raise JSONRPCError('unknown repository %s' % repo) | |
636 |
|
636 | |||
637 | user_group = UsersGroup.get_by_group_name(group_name) |
|
637 | user_group = UsersGroup.get_by_group_name(group_name) | |
638 | if user_group is None: |
|
638 | if user_group is None: | |
639 | raise JSONRPCError('unknown users group %s' % user_group) |
|
639 | raise JSONRPCError('unknown users group %s' % user_group) | |
640 |
|
640 | |||
641 | RepoModel().revoke_users_group_permission(repo=repo_name, |
|
641 | RepoModel().revoke_users_group_permission(repo=repo_name, | |
642 | group_name=group_name) |
|
642 | group_name=group_name) | |
643 |
|
643 | |||
644 | Session.commit() |
|
644 | Session.commit() | |
645 | return dict( |
|
645 | return dict( | |
646 | msg='Revoked perm for group: %s in repo: %s' % ( |
|
646 | msg='Revoked perm for group: %s in repo: %s' % ( | |
647 | group_name, repo_name |
|
647 | group_name, repo_name | |
648 | ) |
|
648 | ) | |
649 | ) |
|
649 | ) | |
650 | except Exception: |
|
650 | except Exception: | |
651 | log.error(traceback.format_exc()) |
|
651 | log.error(traceback.format_exc()) | |
652 | raise JSONRPCError( |
|
652 | raise JSONRPCError( | |
653 | 'failed to edit permission %(repo)s for %(usersgr)s' % dict( |
|
653 | 'failed to edit permission %(repo)s for %(usersgr)s' % dict( | |
654 | usersgr=group_name, repo=repo_name |
|
654 | usersgr=group_name, repo=repo_name | |
655 | ) |
|
655 | ) | |
656 | ) |
|
656 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now