Mercurial > kallithea
annotate rhodecode/model/repo.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
This imports changes between changesets 21af6c4eab3d and 6177597791c2 in
RhodeCode's original repository, including only changes to Python files and HTML.
RhodeCode clearly licensed its changes to these files under GPLv3
in their /LICENSE file, which states the following:
The Python code and integrated HTML are licensed under the GPLv3 license.
(See:
https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE
or
http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE
for an online copy of that LICENSE file)
Conservancy reviewed these changes and confirmed that they can be licensed as
a whole to the Kallithea project under GPLv3-only.
While some of the contents committed herein are clearly licensed
GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the
statement above from RhodeCode indicates that they intend GPLv3-only as their
license, per GPLv3§14 and other relevant sections of GPLv3.
author | Bradley M. Kuhn <bkuhn@sfconservancy.org> |
---|---|
date | Wed, 02 Jul 2014 19:03:13 -0400 |
parents | a5888ca796b5 |
children | 7e5f8c12a3fc |
rev | line source |
---|---|
786
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
1 # -*- coding: utf-8 -*- |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
5 # (at your option) any later version. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1119
diff
changeset
|
6 # |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
7 # This program is distributed in the hope that it will be useful, |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
10 # GNU General Public License for more details. |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1119
diff
changeset
|
11 # |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
14 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
15 rhodecode.model.repo |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
16 ~~~~~~~~~~~~~~~~~~~~ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
17 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
18 Repository model for rhodecode |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
19 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
20 :created_on: Jun 5, 2010 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
21 :author: marcink |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
22 :copyright: (c) 2013 RhodeCode GmbH. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
23 :license: GPLv3, see LICENSE for more details. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
24 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
25 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
26 |
2404
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
27 from __future__ import with_statement |
786
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
28 import os |
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
29 import shutil |
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
30 import logging |
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
31 import traceback |
367
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
32 from datetime import datetime |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
33 from rhodecode.lib.utils import make_ui |
786
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
34 |
2007
324ac367a4da
Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents:
2003
diff
changeset
|
35 from rhodecode.lib.vcs.backends import get_backend |
2142
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
36 from rhodecode.lib.compat import json |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
37 from rhodecode.lib.utils2 import LazyProperty, safe_str, safe_unicode, \ |
4012
55dbc440878b
Fixed bug with log_delete hook didn't properly store
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
38 remove_prefix, obfuscate_url_pw, get_current_rhodecode_user |
1669
f522f4d3bf93
moved caching query to libs
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
39 from rhodecode.lib.caching_query import FromCache |
2904
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
40 from rhodecode.lib.hooks import log_create_repository, log_delete_repository |
1401
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1393
diff
changeset
|
41 |
786
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
42 from rhodecode.model import BaseModel |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
43 from rhodecode.model.db import Repository, UserRepoToPerm, UserGroupRepoToPerm, \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
44 UserRepoGroupToPerm, UserGroupRepoGroupToPerm, User, Permission, \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
45 Statistics, UserGroup, RhodeCodeUi, RepoGroup, \ |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3245
diff
changeset
|
46 RhodeCodeSetting, RepositoryField |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
47 |
2142
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
48 from rhodecode.lib import helpers as h |
3789
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
49 from rhodecode.lib.auth import HasRepoPermissionAny, HasUserGroupPermissionAny |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
50 from rhodecode.lib.exceptions import AttachedForksError |
3789
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
51 from rhodecode.model.scm import UserGroupList |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
52 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 log = logging.getLogger(__name__) |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 |
1271
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
55 |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
56 class RepoModel(BaseModel): |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
57 |
2522
17893d61792a
Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
58 cls = Repository |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
59 URL_SEPARATOR = Repository.url_sep() |
2522
17893d61792a
Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
60 |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
61 def _get_user_group(self, users_group): |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
62 return self._get_instance(UserGroup, users_group, |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
63 callback=UserGroup.get_by_group_name) |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
64 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
65 def _get_repo_group(self, repo_group): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
66 return self._get_instance(RepoGroup, repo_group, |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
67 callback=RepoGroup.get_by_group_name) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
68 |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
69 def _create_default_perms(self, repository, private): |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
70 # create default permission |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
71 default = 'repository.read' |
3734
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3714
diff
changeset
|
72 def_user = User.get_default_user() |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
73 for p in def_user.user_perms: |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
74 if p.permission.permission_name.startswith('repository.'): |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
75 default = p.permission.permission_name |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
76 break |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
77 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
78 default_perm = 'repository.none' if private else default |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
79 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
80 repo_to_perm = UserRepoToPerm() |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
81 repo_to_perm.permission = Permission.get_by_key(default_perm) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
82 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
83 repo_to_perm.repository = repository |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
84 repo_to_perm.user_id = def_user.user_id |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
85 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
86 return repo_to_perm |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
87 |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
88 @LazyProperty |
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
89 def repos_path(self): |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
90 """ |
4089
a5888ca796b5
Fixed spelling of get's to gets
Marcin Kuzminski <marcin@python-works.com>
parents:
4018
diff
changeset
|
91 Gets the repositories root path from database |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
92 """ |
1017
ade3414a8b61
Fixed problems with repository creation
Marcin Kuzminski <marcin@python-works.com>
parents:
1015
diff
changeset
|
93 |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
94 q = self.sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one() |
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
95 return q.ui_value |
1013
d2a840b29858
#56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
96 |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
97 def get(self, repo_id, cache=False): |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
98 repo = self.sa.query(Repository) \ |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
99 .filter(Repository.repo_id == repo_id) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
100 |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
101 if cache: |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
102 repo = repo.options(FromCache("sql_cache_short", |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
103 "get_repo_%s" % repo_id)) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
104 return repo.scalar() |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
105 |
2010
14dffcfebb02
API get_user and get_repo methods can fetch by id or names
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
106 def get_repo(self, repository): |
2432
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2411
diff
changeset
|
107 return self._get_repo(repository) |
2010
14dffcfebb02
API get_user and get_repo methods can fetch by id or names
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
108 |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
109 def get_by_repo_name(self, repo_name, cache=False): |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
110 repo = self.sa.query(Repository) \ |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
111 .filter(Repository.repo_name == repo_name) |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
112 |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
113 if cache: |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
114 repo = repo.options(FromCache("sql_cache_short", |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
115 "get_repo_%s" % repo_name)) |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
116 return repo.scalar() |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
117 |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
118 def get_all_user_repos(self, user): |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
119 """ |
4089
a5888ca796b5
Fixed spelling of get's to gets
Marcin Kuzminski <marcin@python-works.com>
parents:
4018
diff
changeset
|
120 Gets all repositories that user have at least read access |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
121 |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
122 :param user: |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
123 """ |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
124 from rhodecode.lib.auth import AuthUser |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
125 user = self._get_user(user) |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
126 repos = AuthUser(user_id=user.user_id).permissions['repositories'] |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
127 access_check = lambda r: r[1] in ['repository.read', |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
128 'repository.write', |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
129 'repository.admin'] |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
130 repos = [x[0] for x in filter(access_check, repos.items())] |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
131 return Repository.query().filter(Repository.repo_name.in_(repos)) |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
132 |
298
15e96b5a2685
autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents:
296
diff
changeset
|
133 def get_users_js(self): |
328
cec5cbc956c0
Repository managment permissions, fixed found bugs updated js, added extra checks for doubled users and non active ones
Marcin Kuzminski <marcin@python-works.com>
parents:
299
diff
changeset
|
134 users = self.sa.query(User).filter(User.active == True).all() |
2142
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
135 return json.dumps([ |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
136 { |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
137 'id': u.user_id, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
138 'fname': u.name, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
139 'lname': u.lastname, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
140 'nname': u.username, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
141 'gravatar_lnk': h.gravatar_url(u.email, 14) |
2142
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
142 } for u in users] |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
143 ) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
144 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
145 def get_user_groups_js(self): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
146 user_groups = self.sa.query(UserGroup) \ |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
147 .filter(UserGroup.users_group_active == True).all() |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
148 user_groups = UserGroupList(user_groups, perm_set=['usergroup.read', |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
149 'usergroup.write', |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
150 'usergroup.admin']) |
2142
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
151 return json.dumps([ |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
152 { |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
153 'id': gr.users_group_id, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
154 'grname': gr.users_group_name, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
155 'grmembers': len(gr.members), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
156 } for gr in user_groups] |
2142
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
157 ) |
1013
d2a840b29858
#56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
158 |
3154
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
159 @classmethod |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
160 def _render_datatable(cls, tmpl, *args, **kwargs): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
161 import rhodecode |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
162 from pylons import tmpl_context as c |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
163 from pylons.i18n.translation import _ |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
164 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
165 _tmpl_lookup = rhodecode.CONFIG['pylons.app_globals'].mako_lookup |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
166 template = _tmpl_lookup.get_template('data_table/_dt_elements.html') |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
167 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
168 tmpl = template.get_def(tmpl) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
169 kwargs.update(dict(_=_, h=h, c=c)) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
170 return tmpl.render(*args, **kwargs) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
171 |
3309
b3cf4539d1bd
Added missing migrations, and move update_repoinfo to RepoModel
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
172 @classmethod |
b3cf4539d1bd
Added missing migrations, and move update_repoinfo to RepoModel
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
173 def update_repoinfo(cls, repositories=None): |
b3cf4539d1bd
Added missing migrations, and move update_repoinfo to RepoModel
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
174 if not repositories: |
b3cf4539d1bd
Added missing migrations, and move update_repoinfo to RepoModel
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
175 repositories = Repository.getAll() |
b3cf4539d1bd
Added missing migrations, and move update_repoinfo to RepoModel
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
176 for repo in repositories: |
3420
a6bef3e8a361
Update changeset cache should use non-cache version of repo if given attribute is empty, it's easier to controll how changesets are udpated
Marcin Kuzminski <marcin@python-works.com>
parents:
3417
diff
changeset
|
177 repo.update_changeset_cache() |
3309
b3cf4539d1bd
Added missing migrations, and move update_repoinfo to RepoModel
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
178 |
3245
8f3cc21d83e6
fixes issue #739 Delete/Edit repositories should only point to admin links if the user is an super admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
3163
diff
changeset
|
179 def get_repos_as_dict(self, repos_list=None, admin=False, perm_check=True, |
8f3cc21d83e6
fixes issue #739 Delete/Edit repositories should only point to admin links if the user is an super admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
3163
diff
changeset
|
180 super_user_actions=False): |
3154
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
181 _render = self._render_datatable |
3827
ff57547c9cf7
Add flag for permission check in _update_permissions function
Marcin Kuzminski <marcin@python-works.com>
parents:
3789
diff
changeset
|
182 from pylons import tmpl_context as c |
3154
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
183 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
184 def quick_menu(repo_name): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
185 return _render('quick_menu', repo_name) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
186 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
187 def repo_lnk(name, rtype, rstate, private, fork_of): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
188 return _render('repo_name', name, rtype, rstate, private, fork_of, |
3154
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
189 short_name=not admin, admin=False) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
190 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
191 def last_change(last_change): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
192 return _render("last_change", last_change) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
193 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
194 def rss_lnk(repo_name): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
195 return _render("rss", repo_name) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
196 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
197 def atom_lnk(repo_name): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
198 return _render("atom", repo_name) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
199 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
200 def last_rev(repo_name, cs_cache): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
201 return _render('revision', repo_name, cs_cache.get('revision'), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
202 cs_cache.get('raw_id'), cs_cache.get('author'), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
203 cs_cache.get('message')) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
204 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
205 def desc(desc): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
206 if c.visual.stylify_metatags: |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
207 return h.urlify_text(h.desc_stylize(h.truncate(desc, 60))) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
208 else: |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
209 return h.urlify_text(h.truncate(desc, 60)) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
210 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
211 def state(repo_state): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
212 return _render("repo_state", repo_state) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
213 |
3154
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
214 def repo_actions(repo_name): |
3245
8f3cc21d83e6
fixes issue #739 Delete/Edit repositories should only point to admin links if the user is an super admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
3163
diff
changeset
|
215 return _render('repo_actions', repo_name, super_user_actions) |
3154
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
216 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
217 def owner_actions(user_id, username): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
218 return _render('user_name', user_id, username) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
219 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
220 repos_data = [] |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
221 for repo in repos_list: |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
222 if perm_check: |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
223 # check permission at this level |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
224 if not HasRepoPermissionAny( |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
225 'repository.read', 'repository.write', |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
226 'repository.admin' |
3154
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
227 )(repo.repo_name, 'get_repos_as_dict check'): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
228 continue |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
229 cs_cache = repo.changeset_cache |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
230 row = { |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
231 "menu": quick_menu(repo.repo_name), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
232 "raw_name": repo.repo_name.lower(), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
233 "name": repo_lnk(repo.repo_name, repo.repo_type, |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
234 repo.repo_state, repo.private, repo.fork), |
3154
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
235 "last_change": last_change(repo.last_db_change), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
236 "last_changeset": last_rev(repo.repo_name, cs_cache), |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
237 "last_rev_raw": cs_cache.get('revision'), |
3154
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
238 "desc": desc(repo.description), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
239 "owner": h.person(repo.user.username), |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
240 "state": state(repo.repo_state), |
3154
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
241 "rss": rss_lnk(repo.repo_name), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
242 "atom": atom_lnk(repo.repo_name), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
243 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
244 } |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
245 if admin: |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
246 row.update({ |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
247 "action": repo_actions(repo.repo_name), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
248 "owner": owner_actions(repo.user.user_id, |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
249 h.person(repo.user.username)) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
250 }) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
251 repos_data.append(row) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
252 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
253 return { |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
254 "totalRecords": len(repos_list), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
255 "startIndex": 0, |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
256 "sort": "name", |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
257 "dir": "asc", |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
258 "records": repos_data |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
259 } |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
260 |
1594 | 261 def _get_defaults(self, repo_name): |
262 """ | |
4089
a5888ca796b5
Fixed spelling of get's to gets
Marcin Kuzminski <marcin@python-works.com>
parents:
4018
diff
changeset
|
263 Gets information about repository, and returns a dict for |
1594 | 264 usage in forms |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
265 |
1594 | 266 :param repo_name: |
267 """ | |
268 | |
269 repo_info = Repository.get_by_repo_name(repo_name) | |
270 | |
271 if repo_info is None: | |
272 return None | |
273 | |
274 defaults = repo_info.get_dict() | |
3599
8087731920d8
breadcrumbs: make repo names link to summary pages
Mads Kiilerich <madski@unity3d.com>
parents:
3452
diff
changeset
|
275 group, repo_name, repo_name_full = repo_info.groups_and_repo |
1594 | 276 defaults['repo_name'] = repo_name |
277 defaults['repo_group'] = getattr(group[-1] if group else None, | |
278 'group_id', None) | |
279 | |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
280 for strip, k in [(0, 'repo_type'), (1, 'repo_enable_downloads'), |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
281 (1, 'repo_description'), (1, 'repo_enable_locking'), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
282 (1, 'repo_landing_rev'), (0, 'clone_uri'), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
283 (1, 'repo_private'), (1, 'repo_enable_statistics')]: |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
284 attr = k |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
285 if strip: |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
286 attr = remove_prefix(k, 'repo_') |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
287 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
288 val = defaults[attr] |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
289 if k == 'repo_landing_rev': |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
290 val = ':'.join(defaults[attr]) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
291 defaults[k] = val |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
292 if k == 'clone_uri': |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
293 defaults['clone_uri_hidden'] = repo_info.clone_uri_hidden |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
294 |
1594 | 295 # fill owner |
296 if repo_info.user: | |
297 defaults.update({'user': repo_info.user.username}) | |
298 else: | |
299 replacement_user = User.query().filter(User.admin == | |
300 True).first().username | |
301 defaults.update({'user': replacement_user}) | |
302 | |
303 # fill repository users | |
304 for p in repo_info.repo_to_perm: | |
305 defaults.update({'u_perm_%s' % p.user.username: | |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
306 p.permission.permission_name}) |
1594 | 307 |
308 # fill repository groups | |
309 for p in repo_info.users_group_to_perm: | |
310 defaults.update({'g_perm_%s' % p.users_group.users_group_name: | |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
311 p.permission.permission_name}) |
1594 | 312 |
313 return defaults | |
314 | |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
315 def update(self, repo, **kwargs): |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
316 try: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
317 cur_repo = self._get_repo(repo) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
318 org_repo_name = cur_repo.repo_name |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
319 if 'user' in kwargs: |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
320 cur_repo.user = User.get_by_username(kwargs['user']) |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
321 |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
322 if 'repo_group' in kwargs: |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
323 cur_repo.group = RepoGroup.get(kwargs['repo_group']) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
324 log.debug('Updating repo %s with params:%s' % (cur_repo, kwargs)) |
3859
c32322126fe4
Repo type can't be changed. Fixes issue 836
Simon Lopez <simon.lopez@slopez.org>
parents:
3840
diff
changeset
|
325 for strip, k in [(1, 'repo_enable_downloads'), |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
326 (1, 'repo_description'), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
327 (1, 'repo_enable_locking'), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
328 (1, 'repo_landing_rev'), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
329 (1, 'repo_private'), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
330 (1, 'repo_enable_statistics'), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
331 (0, 'clone_uri'),]: |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
332 if k in kwargs: |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
333 val = kwargs[k] |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
334 if strip: |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
335 k = remove_prefix(k, 'repo_') |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
336 if k == 'clone_uri': |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
337 from rhodecode.model.validators import Missing |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
338 _change = kwargs.get('clone_uri_change') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
339 if _change == Missing: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
340 # we don't change the value, so use original one |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
341 val = cur_repo.clone_uri |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
342 |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
343 setattr(cur_repo, k, val) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
344 |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
345 new_name = cur_repo.get_new_name(kwargs['repo_name']) |
1539
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
346 cur_repo.repo_name = new_name |
3629
802c94bdfc85
#749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents:
3628
diff
changeset
|
347 #if private flag is set, reset default permission to NONE |
1539
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
348 |
3629
802c94bdfc85
#749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents:
3628
diff
changeset
|
349 if kwargs.get('repo_private'): |
802c94bdfc85
#749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents:
3628
diff
changeset
|
350 EMPTY_PERM = 'repository.none' |
802c94bdfc85
#749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents:
3628
diff
changeset
|
351 RepoModel().grant_user_permission( |
802c94bdfc85
#749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents:
3628
diff
changeset
|
352 repo=cur_repo, user='default', perm=EMPTY_PERM |
802c94bdfc85
#749 and #516 Removed dupliciting of repo settings for rhodecode admins and repo admins
Marcin Kuzminski <marcin@python-works.com>
parents:
3628
diff
changeset
|
353 ) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
354 #handle extra fields |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
355 for field in filter(lambda k: k.startswith(RepositoryField.PREFIX), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
356 kwargs): |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3245
diff
changeset
|
357 k = RepositoryField.un_prefix_key(field) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3245
diff
changeset
|
358 ex_field = RepositoryField.get_by_key_name(key=k, repo=cur_repo) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3245
diff
changeset
|
359 if ex_field: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3245
diff
changeset
|
360 ex_field.field_value = kwargs[field] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3245
diff
changeset
|
361 self.sa.add(ex_field) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
362 self.sa.add(cur_repo) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
363 |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
364 if org_repo_name != new_name: |
1323
a7a772ea7b95
fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents:
1271
diff
changeset
|
365 # rename repository |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
366 self._rename_filesystem_repo(old=org_repo_name, new=new_name) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
367 |
1539
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
368 return cur_repo |
3631
10b4e34841a4
Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents:
3629
diff
changeset
|
369 except Exception: |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
370 log.error(traceback.format_exc()) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
371 raise |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
372 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
373 def _create_repo(self, repo_name, repo_type, description, owner, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
374 private=False, clone_uri=None, repo_group=None, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
375 landing_rev='rev:tip', fork_of=None, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
376 copy_fork_permissions=False, enable_statistics=False, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
377 enable_locking=False, enable_downloads=False, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
378 copy_group_permissions=False, state=Repository.STATE_PENDING): |
2652
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
379 """ |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
380 Create repository inside database with PENDING state, this should be |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
381 only executed by create() repo. With exception of importing existing repos |
2652
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
382 |
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
383 """ |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
384 from rhodecode.model.scm import ScmModel |
1366
9c0f5d558789
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents:
1361
diff
changeset
|
385 |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
386 owner = self._get_user(owner) |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
387 fork_of = self._get_repo(fork_of) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
388 repo_group = self._get_repo_group(repo_group) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
389 try: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
390 repo_name = safe_unicode(repo_name) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
391 description = safe_unicode(description) |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
392 # repo name is just a name of repository |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
393 # while repo_name_full is a full qualified name that is combined |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
394 # with name and path of group |
2529
40b3a54391f9
Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents:
2524
diff
changeset
|
395 repo_name_full = repo_name |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
396 repo_name = repo_name.split(self.URL_SEPARATOR)[-1] |
1361
87ca17540603
fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents:
1351
diff
changeset
|
397 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
398 new_repo = Repository() |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
399 new_repo.repo_state = state |
1075
f726a939d2d4
Enable statistics are disabled by default now
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
400 new_repo.enable_statistics = False |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
401 new_repo.repo_name = repo_name_full |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
402 new_repo.repo_type = repo_type |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
403 new_repo.user = owner |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
404 new_repo.group = repo_group |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
405 new_repo.description = description or repo_name |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
406 new_repo.private = private |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
407 new_repo.clone_uri = clone_uri |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
408 new_repo.landing_rev = landing_rev |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
409 |
3056
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
410 new_repo.enable_statistics = enable_statistics |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
411 new_repo.enable_locking = enable_locking |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
412 new_repo.enable_downloads = enable_downloads |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
413 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
414 if repo_group: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
415 new_repo.enable_locking = repo_group.enable_locking |
2755
839ee7a774ab
inherit locking from parent
Marcin Kuzminski <marcin@python-works.com>
parents:
2652
diff
changeset
|
416 |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
417 if fork_of: |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
418 parent_repo = fork_of |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
419 new_repo.fork = parent_repo |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
420 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
421 self.sa.add(new_repo) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
422 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
423 if fork_of and copy_fork_permissions: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
424 repo = fork_of |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
425 user_perms = UserRepoToPerm.query() \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
426 .filter(UserRepoToPerm.repository == repo).all() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
427 group_perms = UserGroupRepoToPerm.query() \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
428 .filter(UserGroupRepoToPerm.repository == repo).all() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
429 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
430 for perm in user_perms: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
431 UserRepoToPerm.create(perm.user, new_repo, perm.permission) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
432 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
433 for perm in group_perms: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
434 UserGroupRepoToPerm.create(perm.users_group, new_repo, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
435 perm.permission) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
436 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
437 elif repo_group and copy_group_permissions: |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
438 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
439 user_perms = UserRepoGroupToPerm.query() \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
440 .filter(UserRepoGroupToPerm.group == repo_group).all() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
441 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
442 group_perms = UserGroupRepoGroupToPerm.query() \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
443 .filter(UserGroupRepoGroupToPerm.group == repo_group).all() |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
444 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
445 for perm in user_perms: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
446 perm_name = perm.permission.permission_name.replace('group.', 'repository.') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
447 perm_obj = Permission.get_by_key(perm_name) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
448 UserRepoToPerm.create(perm.user, new_repo, perm_obj) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
449 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
450 for perm in group_perms: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
451 perm_name = perm.permission.permission_name.replace('group.', 'repository.') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
452 perm_obj = Permission.get_by_key(perm_name) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
453 UserGroupRepoToPerm.create(perm.users_group, new_repo, perm_obj) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
454 |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
455 else: |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
456 perm_obj = self._create_default_perms(new_repo, private) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
457 self.sa.add(perm_obj) |
1028
f42ee60e673b
fixed issue with db transaction when filesystem creation of repository failed
Marcin Kuzminski <marcin@python-works.com>
parents:
1020
diff
changeset
|
458 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
459 # now automatically start following this repository as owner |
786
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
460 ScmModel(self.sa).toggle_following_repo(new_repo.repo_id, |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
461 owner.user_id) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
462 # we need to flush here, in order to check if database won't |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
463 # throw any exceptions, create filesystem dirs at the very end |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
464 self.sa.flush() |
1539
bd604cf75c5a
fixes #260 Put repo in group, then move group to another group -> repo becomes unavailable
Marcin Kuzminski <marcin@python-works.com>
parents:
1530
diff
changeset
|
465 return new_repo |
3631
10b4e34841a4
Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents:
3629
diff
changeset
|
466 except Exception: |
296
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
467 log.error(traceback.format_exc()) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
468 raise |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
469 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
470 def create(self, form_data, cur_user): |
2652
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
471 """ |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
472 Create repository using celery tasks |
2652
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
473 |
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
474 :param form_data: |
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
475 :param cur_user: |
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
476 """ |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
477 from rhodecode.lib.celerylib import tasks, run_task |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
478 return run_task(tasks.create_repo, form_data, cur_user) |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
479 |
3827
ff57547c9cf7
Add flag for permission check in _update_permissions function
Marcin Kuzminski <marcin@python-works.com>
parents:
3789
diff
changeset
|
480 def _update_permissions(self, repo, perms_new=None, perms_updates=None, |
ff57547c9cf7
Add flag for permission check in _update_permissions function
Marcin Kuzminski <marcin@python-works.com>
parents:
3789
diff
changeset
|
481 check_perms=True): |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
482 if not perms_new: |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
483 perms_new = [] |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
484 if not perms_updates: |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
485 perms_updates = [] |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
486 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
487 # update permissions |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
488 for member, perm, member_type in perms_updates: |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
489 if member_type == 'user': |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
490 # this updates existing one |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
491 self.grant_user_permission( |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
492 repo=repo, user=member, perm=perm |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
493 ) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
494 else: |
3789
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
495 #check if we have permissions to alter this usergroup |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
496 req_perms = ( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
497 'usergroup.read', 'usergroup.write', 'usergroup.admin') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
498 if not check_perms or HasUserGroupPermissionAny(*req_perms)( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
499 member): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
500 self.grant_user_group_permission( |
3789
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
501 repo=repo, group_name=member, perm=perm |
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
502 ) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
503 # set new permissions |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
504 for member, perm, member_type in perms_new: |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
505 if member_type == 'user': |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
506 self.grant_user_permission( |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
507 repo=repo, user=member, perm=perm |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
508 ) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
509 else: |
3789
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
510 #check if we have permissions to alter this usergroup |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
511 req_perms = ( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
512 'usergroup.read', 'usergroup.write', 'usergroup.admin') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
513 if not check_perms or HasUserGroupPermissionAny(*req_perms)( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
514 member): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
515 self.grant_user_group_permission( |
3789
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
516 repo=repo, group_name=member, perm=perm |
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
517 ) |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
518 |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
519 def create_fork(self, form_data, cur_user): |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
520 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
521 Simple wrapper into executing celery task for fork creation |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
522 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
523 :param form_data: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
524 :param cur_user: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
525 """ |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
526 from rhodecode.lib.celerylib import tasks, run_task |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
527 return run_task(tasks.create_repo_fork, form_data, cur_user) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
528 |
4012
55dbc440878b
Fixed bug with log_delete hook didn't properly store
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
529 def delete(self, repo, forks=None, fs_remove=True, cur_user=None): |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
530 """ |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
531 Delete given repository, forks parameter defines what do do with |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
532 attached forks. Throws AttachedForksError if deleted repo has attached |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
533 forks |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
534 |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
535 :param repo: |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
536 :param forks: str 'delete' or 'detach' |
3694
34093903b505
repo rescann should detach forks of zombie repos,
Marcin Kuzminski <marcin@python-works.com>
parents:
3641
diff
changeset
|
537 :param fs_remove: remove(archive) repo from filesystem |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
538 """ |
4012
55dbc440878b
Fixed bug with log_delete hook didn't properly store
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
539 if not cur_user: |
4018
727d2a45ec10
Replaced fallback username from ? to None in hook loggers
Marcin Kuzminski <marcin@python-works.com>
parents:
4012
diff
changeset
|
540 cur_user = getattr(get_current_rhodecode_user(), 'username', None) |
2432
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2411
diff
changeset
|
541 repo = self._get_repo(repo) |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
542 if repo: |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
543 if forks == 'detach': |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
544 for r in repo.forks: |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
545 r.fork = None |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
546 self.sa.add(r) |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
547 elif forks == 'delete': |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
548 for r in repo.forks: |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
549 self.delete(r, forks='delete') |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
550 elif [f for f in repo.forks]: |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
551 raise AttachedForksError() |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
552 |
2904
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
553 old_repo_dict = repo.get_dict() |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
554 owner = repo.user |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
555 try: |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
556 self.sa.delete(repo) |
3694
34093903b505
repo rescann should detach forks of zombie repos,
Marcin Kuzminski <marcin@python-works.com>
parents:
3641
diff
changeset
|
557 if fs_remove: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
558 self._delete_filesystem_repo(repo) |
3694
34093903b505
repo rescann should detach forks of zombie repos,
Marcin Kuzminski <marcin@python-works.com>
parents:
3641
diff
changeset
|
559 else: |
34093903b505
repo rescann should detach forks of zombie repos,
Marcin Kuzminski <marcin@python-works.com>
parents:
3641
diff
changeset
|
560 log.debug('skipping removal from filesystem') |
2904
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
561 log_delete_repository(old_repo_dict, |
4012
55dbc440878b
Fixed bug with log_delete hook didn't properly store
Marcin Kuzminski <marcin@python-works.com>
parents:
3960
diff
changeset
|
562 deleted_by=cur_user) |
3631
10b4e34841a4
Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents:
3629
diff
changeset
|
563 except Exception: |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
564 log.error(traceback.format_exc()) |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
565 raise |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
566 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
567 def grant_user_permission(self, repo, user, perm): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
568 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
569 Grant permission for user on given repository, or update existing one |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
570 if found |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
571 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
572 :param repo: Instance of Repository, repository_id, or repository name |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
573 :param user: Instance of User, user_id or username |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
574 :param perm: Instance of Permission, or permission_name |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
575 """ |
2432
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2411
diff
changeset
|
576 user = self._get_user(user) |
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2411
diff
changeset
|
577 repo = self._get_repo(repo) |
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2411
diff
changeset
|
578 permission = self._get_perm(perm) |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
579 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
580 # check if we have that permission already |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
581 obj = self.sa.query(UserRepoToPerm) \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
582 .filter(UserRepoToPerm.user == user) \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
583 .filter(UserRepoToPerm.repository == repo) \ |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
584 .scalar() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
585 if obj is None: |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
586 # create new ! |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
587 obj = UserRepoToPerm() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
588 obj.repository = repo |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
589 obj.user = user |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
590 obj.permission = permission |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
591 self.sa.add(obj) |
2820
c0cc8f8a71b0
Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents:
2755
diff
changeset
|
592 log.debug('Granted perm %s to %s on %s' % (perm, user, repo)) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
593 return obj |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
594 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
595 def revoke_user_permission(self, repo, user): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
596 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
597 Revoke permission for user on given repository |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
598 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
599 :param repo: Instance of Repository, repository_id, or repository name |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
600 :param user: Instance of User, user_id or username |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
601 """ |
2142
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
602 |
2432
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2411
diff
changeset
|
603 user = self._get_user(user) |
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2411
diff
changeset
|
604 repo = self._get_repo(repo) |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
605 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
606 obj = self.sa.query(UserRepoToPerm) \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
607 .filter(UserRepoToPerm.repository == repo) \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
608 .filter(UserRepoToPerm.user == user) \ |
2820
c0cc8f8a71b0
Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents:
2755
diff
changeset
|
609 .scalar() |
c0cc8f8a71b0
Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents:
2755
diff
changeset
|
610 if obj: |
c0cc8f8a71b0
Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents:
2755
diff
changeset
|
611 self.sa.delete(obj) |
c0cc8f8a71b0
Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents:
2755
diff
changeset
|
612 log.debug('Revoked perm on %s on %s' % (repo, user)) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
613 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
614 def grant_user_group_permission(self, repo, group_name, perm): |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
615 """ |
3415
b8f929bff7e3
fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents:
3314
diff
changeset
|
616 Grant permission for user group on given repository, or update |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
617 existing one if found |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
618 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
619 :param repo: Instance of Repository, repository_id, or repository name |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
620 :param group_name: Instance of UserGroup, users_group_id, |
3415
b8f929bff7e3
fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents:
3314
diff
changeset
|
621 or user group name |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
622 :param perm: Instance of Permission, or permission_name |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
623 """ |
2432
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2411
diff
changeset
|
624 repo = self._get_repo(repo) |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
625 group_name = self._get_user_group(group_name) |
2432
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2411
diff
changeset
|
626 permission = self._get_perm(perm) |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
627 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
628 # check if we have that permission already |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
629 obj = self.sa.query(UserGroupRepoToPerm) \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
630 .filter(UserGroupRepoToPerm.users_group == group_name) \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
631 .filter(UserGroupRepoToPerm.repository == repo) \ |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
632 .scalar() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
633 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
634 if obj is None: |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
635 # create new |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
636 obj = UserGroupRepoToPerm() |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
637 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
638 obj.repository = repo |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
639 obj.users_group = group_name |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
640 obj.permission = permission |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
641 self.sa.add(obj) |
2820
c0cc8f8a71b0
Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents:
2755
diff
changeset
|
642 log.debug('Granted perm %s to %s on %s' % (perm, group_name, repo)) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
643 return obj |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
644 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
645 def revoke_user_group_permission(self, repo, group_name): |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
646 """ |
3415
b8f929bff7e3
fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents:
3314
diff
changeset
|
647 Revoke permission for user group on given repository |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
648 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
649 :param repo: Instance of Repository, repository_id, or repository name |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
650 :param group_name: Instance of UserGroup, users_group_id, |
3415
b8f929bff7e3
fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents:
3314
diff
changeset
|
651 or user group name |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
652 """ |
2432
d3ac7491a5c8
Share common getter functions in base model, and remove duplicated functions from other models
Marcin Kuzminski <marcin@python-works.com>
parents:
2411
diff
changeset
|
653 repo = self._get_repo(repo) |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
654 group_name = self._get_user_group(group_name) |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
655 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
656 obj = self.sa.query(UserGroupRepoToPerm) \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
657 .filter(UserGroupRepoToPerm.repository == repo) \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
658 .filter(UserGroupRepoToPerm.users_group == group_name) \ |
2820
c0cc8f8a71b0
Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents:
2755
diff
changeset
|
659 .scalar() |
c0cc8f8a71b0
Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents:
2755
diff
changeset
|
660 if obj: |
c0cc8f8a71b0
Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents:
2755
diff
changeset
|
661 self.sa.delete(obj) |
c0cc8f8a71b0
Permissions on group can be set in recursive mode setting defined permission to all children
Marcin Kuzminski <marcin@python-works.com>
parents:
2755
diff
changeset
|
662 log.debug('Revoked perm to %s on %s' % (repo, group_name)) |
1015
65129c332d37
#56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents:
1014
diff
changeset
|
663 |
708
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
664 def delete_stats(self, repo_name): |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
665 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
666 removes stats for given repo |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
667 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
668 :param repo_name: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
669 """ |
3314
059efaea23d6
fix reset statistics call if there are no statistics yet
Marcin Kuzminski <marcin@python-works.com>
parents:
3309
diff
changeset
|
670 repo = self._get_repo(repo_name) |
708
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
671 try: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
672 obj = self.sa.query(Statistics) \ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
673 .filter(Statistics.repository == repo).scalar() |
3314
059efaea23d6
fix reset statistics call if there are no statistics yet
Marcin Kuzminski <marcin@python-works.com>
parents:
3309
diff
changeset
|
674 if obj: |
059efaea23d6
fix reset statistics call if there are no statistics yet
Marcin Kuzminski <marcin@python-works.com>
parents:
3309
diff
changeset
|
675 self.sa.delete(obj) |
3631
10b4e34841a4
Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents:
3629
diff
changeset
|
676 except Exception: |
708
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
677 log.error(traceback.format_exc()) |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
678 raise |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
679 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
680 def _create_filesystem_repo(self, repo_name, repo_type, repo_group, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
681 clone_uri=None, repo_store_location=None): |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
682 """ |
1361
87ca17540603
fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents:
1351
diff
changeset
|
683 makes repository on filesystem. It's group aware means it'll create |
87ca17540603
fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents:
1351
diff
changeset
|
684 a repository within a group, and alter the paths accordingly of |
87ca17540603
fixed #47 adding a new repo that have a group chosen had wrong paths.
Marcin Kuzminski <marcin@python-works.com>
parents:
1351
diff
changeset
|
685 group location |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1119
diff
changeset
|
686 |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
687 :param repo_name: |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
688 :param alias: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
689 :param parent: |
1350
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
690 :param clone_uri: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
691 :param repo_store_location: |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
692 """ |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
693 from rhodecode.lib.utils import is_valid_repo, is_valid_repo_group |
2618
e1370dcb9908
Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents:
2592
diff
changeset
|
694 from rhodecode.model.scm import ScmModel |
1517
142a05597cba
assure that we don't have an empty description when creating a repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1507
diff
changeset
|
695 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
696 if '/' in repo_name: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
697 raise ValueError('repo_name must not contain groups got `%s`' % repo_name) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
698 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
699 if isinstance(repo_group, RepoGroup): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
700 new_parent_path = os.sep.join(repo_group.full_path_splitted) |
1350
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
701 else: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
702 new_parent_path = repo_group or '' |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
703 |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
704 if repo_store_location: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
705 _paths = [repo_store_location] |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
706 else: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
707 _paths = [self.repos_path, new_parent_path, repo_name] |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
708 # we need to make it str for mercurial |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
709 repo_path = os.path.join(*map(lambda x: safe_str(x), _paths)) |
1350
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
710 |
1550
6f468ba37650
fixes #266 Rhodecode allows to create repo with the same name and in the same parent as group
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
711 # check if this path is not a repository |
6f468ba37650
fixes #266 Rhodecode allows to create repo with the same name and in the same parent as group
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
712 if is_valid_repo(repo_path, self.repos_path): |
6f468ba37650
fixes #266 Rhodecode allows to create repo with the same name and in the same parent as group
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
713 raise Exception('This path %s is a valid repository' % repo_path) |
1401
b7563ad4e7ee
Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents:
1393
diff
changeset
|
714 |
1550
6f468ba37650
fixes #266 Rhodecode allows to create repo with the same name and in the same parent as group
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
715 # check if this path is a group |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
716 if is_valid_repo_group(repo_path, self.repos_path): |
1550
6f468ba37650
fixes #266 Rhodecode allows to create repo with the same name and in the same parent as group
Marcin Kuzminski <marcin@python-works.com>
parents:
1539
diff
changeset
|
717 raise Exception('This path %s is a valid group' % repo_path) |
1594 | 718 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
719 log.info('creating repo %s in %s from url: `%s`' % ( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
720 repo_name, safe_unicode(repo_path), |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
721 obfuscate_url_pw(clone_uri))) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
722 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
723 backend = get_backend(repo_type) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
724 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
725 if repo_type == 'hg': |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
726 baseui = make_ui('db', clear_session=False) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
727 # patch and reset hooks section of UI config to not run any |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
728 # hooks on creating remote repo |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
729 for k, v in baseui.configitems('hooks'): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
730 baseui.setconfig('hooks', k, None) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
731 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
732 repo = backend(repo_path, create=True, src_url=clone_uri, baseui=baseui) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
733 elif repo_type == 'git': |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
734 repo = backend(repo_path, create=True, src_url=clone_uri, bare=True) |
2404
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
735 # add rhodecode hook into this repo |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
736 ScmModel().install_git_hook(repo=repo) |
2321
75280665ad1e
init bare repos for git now by default. This is recommended setup for remotes repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2185
diff
changeset
|
737 else: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
738 raise Exception('Not supported repo_type %s expected hg/git' % repo_type) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
739 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
740 log.debug('Created repo %s with %s backend' |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
741 % (safe_unicode(repo_name), safe_unicode(repo_type))) |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
742 return repo |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
743 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
744 def _rename_filesystem_repo(self, old, new): |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
745 """ |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
746 renames repository on filesystem |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1119
diff
changeset
|
747 |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
748 :param old: old name |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
749 :param new: new name |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
750 """ |
1976 | 751 log.info('renaming repo from %s to %s' % (old, new)) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
752 |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
753 old_path = os.path.join(self.repos_path, old) |
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
754 new_path = os.path.join(self.repos_path, new) |
356
b0715a788432
Added new style error display,
Marcin Kuzminski <marcin@python-works.com>
parents:
328
diff
changeset
|
755 if os.path.isdir(new_path): |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
756 raise Exception( |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
757 'Was trying to rename to already existing dir %s' % new_path |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
758 ) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
759 shutil.move(old_path, new_path) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
760 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
761 def _delete_filesystem_repo(self, repo): |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
762 """ |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
763 removes repo from filesystem, the removal is acctually made by |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
764 added rm__ prefix into dir, and rename internat .hg/.git dirs so this |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
765 repository is no longer valid for rhodecode, can be undeleted later on |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
766 by reverting the renames on this repository |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1119
diff
changeset
|
767 |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
768 :param repo: repo object |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
769 """ |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
770 rm_path = os.path.join(self.repos_path, repo.repo_name) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
771 log.info("Removing repository %s" % (rm_path,)) |
2327
69b836e383df
don't disable .git directory for bare repos on deleting, ref #413
Marcin Kuzminski <marcin@python-works.com>
parents:
2321
diff
changeset
|
772 # disable hg/git internal that it doesn't get detected as repo |
668
dff6d5cb8bba
fixed deletion of repository on filesystem, works based on scm type for git and hg.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
773 alias = repo.repo_type |
2327
69b836e383df
don't disable .git directory for bare repos on deleting, ref #413
Marcin Kuzminski <marcin@python-works.com>
parents:
2321
diff
changeset
|
774 |
69b836e383df
don't disable .git directory for bare repos on deleting, ref #413
Marcin Kuzminski <marcin@python-works.com>
parents:
2321
diff
changeset
|
775 bare = getattr(repo.scm_instance, 'bare', False) |
69b836e383df
don't disable .git directory for bare repos on deleting, ref #413
Marcin Kuzminski <marcin@python-works.com>
parents:
2321
diff
changeset
|
776 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
777 # skip this for bare git repos |
2327
69b836e383df
don't disable .git directory for bare repos on deleting, ref #413
Marcin Kuzminski <marcin@python-works.com>
parents:
2321
diff
changeset
|
778 if not bare: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
779 # disable VCS repo |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
780 vcs_path = os.path.join(rm_path, '.%s' % alias) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
781 if os.path.exists(vcs_path): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
782 shutil.move(vcs_path, os.path.join(rm_path, 'rm__.%s' % alias)) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
783 |
2553
069e13b4dddc
removed %f from datetime formatting doesn't work on py25 :/
Marcin Kuzminski <marcin@python-works.com>
parents:
2529
diff
changeset
|
784 _now = datetime.now() |
2592
f6800c5e5b2d
fill miliseconds with 0 since it can return <6 digit number
Marcin Kuzminski <marcin@python-works.com>
parents:
2553
diff
changeset
|
785 _ms = str(_now.microsecond).rjust(6, '0') |
2553
069e13b4dddc
removed %f from datetime formatting doesn't work on py25 :/
Marcin Kuzminski <marcin@python-works.com>
parents:
2529
diff
changeset
|
786 _d = 'rm__%s__%s' % (_now.strftime('%Y%m%d_%H%M%S_' + _ms), |
2949
d37b79ad0ae8
Fixed issue with rm__ system that put removed repos in root location, it can lead to making a heavy copy, and remove operation.
Marcin Kuzminski <marcin@python-works.com>
parents:
2904
diff
changeset
|
787 repo.just_name) |
d37b79ad0ae8
Fixed issue with rm__ system that put removed repos in root location, it can lead to making a heavy copy, and remove operation.
Marcin Kuzminski <marcin@python-works.com>
parents:
2904
diff
changeset
|
788 if repo.group: |
d37b79ad0ae8
Fixed issue with rm__ system that put removed repos in root location, it can lead to making a heavy copy, and remove operation.
Marcin Kuzminski <marcin@python-works.com>
parents:
2904
diff
changeset
|
789 args = repo.group.full_path_splitted + [_d] |
d37b79ad0ae8
Fixed issue with rm__ system that put removed repos in root location, it can lead to making a heavy copy, and remove operation.
Marcin Kuzminski <marcin@python-works.com>
parents:
2904
diff
changeset
|
790 _d = os.path.join(*args) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
791 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
792 if os.path.isdir(rm_path): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4089
diff
changeset
|
793 shutil.move(rm_path, os.path.join(self.repos_path, _d)) |