Mercurial > kallithea
annotate rhodecode/model/repo.py @ 3914:424b6c711a7f beta
allow underscores in usernames. Helps creating special internal users
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 29 May 2013 12:13:02 +0200 |
parents | c32322126fe4 |
children | 5293d4bbb1ea |
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 -*- |
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
2 """ |
811 | 3 rhodecode.model.repo |
4 ~~~~~~~~~~~~~~~~~~~~ | |
786
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
5 |
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
6 Repository model for rhodecode |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1119
diff
changeset
|
7 |
786
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
8 :created_on: Jun 5, 2010 |
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
9 :author: marcink |
1824
89efedac4e6c
2012 copyrights
Marcin Kuzminski <marcin@python-works.com>
parents:
1818
diff
changeset
|
10 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com> |
786
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
12 """ |
1206
a671db5bdd58
fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1203
diff
changeset
|
13 # 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
|
14 # 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
|
15 # 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
|
16 # (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
|
17 # |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # 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
|
19 # 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
|
20 # 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
|
21 # 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
|
22 # |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # 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
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
2404
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
25 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
|
26 import os |
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
27 import shutil |
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
28 import logging |
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
29 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
|
30 from datetime import datetime |
786
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
31 |
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
|
32 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
|
33 from rhodecode.lib.compat import json |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
34 from rhodecode.lib.utils2 import LazyProperty, safe_str, safe_unicode,\ |
3452
d778ed1c945f
use password obfuscate in when clonning a remote repo with credentials
Marcin Kuzminski <marcin@python-works.com>
parents:
3420
diff
changeset
|
35 remove_prefix, obfuscate_url_pw |
1669
f522f4d3bf93
moved caching query to libs
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
36 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
|
37 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
|
38 |
786
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
39 from rhodecode.model import BaseModel |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
40 from rhodecode.model.db import Repository, UserRepoToPerm, User, Permission, \ |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
41 Statistics, UserGroup, UserGroupRepoToPerm, RhodeCodeUi, RepoGroup,\ |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3245
diff
changeset
|
42 RhodeCodeSetting, RepositoryField |
2142
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
43 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
|
44 from rhodecode.lib.auth import HasRepoPermissionAny, HasUserGroupPermissionAny |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
45 from rhodecode.lib.exceptions import AttachedForksError |
3789
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
46 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
|
47 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 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
|
49 |
1271
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
50 |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
51 class RepoModel(BaseModel): |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
52 |
2522
17893d61792a
Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
53 cls = Repository |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
54 URL_SEPARATOR = Repository.url_sep() |
2522
17893d61792a
Added associated classes into child models
Marcin Kuzminski <marcin@python-works.com>
parents:
2432
diff
changeset
|
55 |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
56 def _get_user_group(self, users_group): |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
57 return self._get_instance(UserGroup, users_group, |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
58 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
|
59 |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
60 def _get_repo_group(self, repos_group): |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
61 return self._get_instance(RepoGroup, repos_group, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
62 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
|
63 |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
64 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
|
65 # 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
|
66 default = 'repository.read' |
3734
a8f520540ab0
New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents:
3714
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 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
|
71 break |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
72 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
73 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
|
74 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
75 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
|
76 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
|
77 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
78 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
|
79 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
|
80 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
81 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
|
82 |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
83 @LazyProperty |
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
84 def repos_path(self): |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
85 """ |
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
86 Get's 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
|
87 """ |
1017
ade3414a8b61
Fixed problems with repository creation
Marcin Kuzminski <marcin@python-works.com>
parents:
1015
diff
changeset
|
88 |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
89 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
|
90 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
|
91 |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
92 def get(self, repo_id, cache=False): |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
93 repo = self.sa.query(Repository)\ |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
94 .filter(Repository.repo_id == repo_id) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
95 |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
96 if cache: |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
97 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
|
98 "get_repo_%s" % repo_id)) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
99 return repo.scalar() |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
100 |
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
|
101 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
|
102 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
|
103 |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
104 def get_by_repo_name(self, repo_name, cache=False): |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
105 repo = self.sa.query(Repository)\ |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
106 .filter(Repository.repo_name == repo_name) |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
107 |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
108 if cache: |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
109 repo = repo.options(FromCache("sql_cache_short", |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
110 "get_repo_%s" % repo_name)) |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
111 return repo.scalar() |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
112 |
3163
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
113 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
|
114 """ |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
115 Get's all repositories that user have at least read access |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
116 |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
117 :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
|
118 """ |
28571535dd61
API methods create_repo, fork_repo, delete_repo, get_repo, get_repos
Marcin Kuzminski <marcin@python-works.com>
parents:
3154
diff
changeset
|
119 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
|
120 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
|
121 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
|
122 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
|
123 '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
|
124 '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
|
125 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
|
126 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
|
127 |
298
15e96b5a2685
autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents:
296
diff
changeset
|
128 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
|
129 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
|
130 return json.dumps([ |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
131 { |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
132 'id': u.user_id, |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
133 'fname': u.name, |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
134 'lname': u.lastname, |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
135 'nname': u.username, |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
136 'gravatar_lnk': h.gravatar_url(u.email, 14) |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
137 } for u in users] |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
138 ) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
139 |
1013
d2a840b29858
#56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
140 def get_users_groups_js(self): |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
141 users_groups = self.sa.query(UserGroup)\ |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
142 .filter(UserGroup.users_group_active == True).all() |
3789
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
143 users_groups = UserGroupList(users_groups, perm_set=['usergroup.read', |
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
144 'usergroup.write', |
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
145 'usergroup.admin']) |
2142
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
146 return json.dumps([ |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
147 { |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
148 'id': gr.users_group_id, |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
149 'grname': gr.users_group_name, |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
150 'grmembers': len(gr.members), |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
151 } for gr in users_groups] |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
152 ) |
1013
d2a840b29858
#56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
153 |
3154
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
154 @classmethod |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
155 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
|
156 import rhodecode |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
157 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
|
158 from pylons.i18n.translation import _ |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
159 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
160 _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
|
161 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
|
162 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
163 tmpl = template.get_def(tmpl) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
164 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
|
165 return tmpl.render(*args, **kwargs) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
166 |
3309
b3cf4539d1bd
Added missing migrations, and move update_repoinfo to RepoModel
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
167 @classmethod |
b3cf4539d1bd
Added missing migrations, and move update_repoinfo to RepoModel
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
168 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
|
169 if not repositories: |
b3cf4539d1bd
Added missing migrations, and move update_repoinfo to RepoModel
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
170 repositories = Repository.getAll() |
b3cf4539d1bd
Added missing migrations, and move update_repoinfo to RepoModel
Marcin Kuzminski <marcin@python-works.com>
parents:
3308
diff
changeset
|
171 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
|
172 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
|
173 |
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
|
174 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
|
175 super_user_actions=False): |
3154
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
176 _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
|
177 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
|
178 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
179 def quick_menu(repo_name): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
180 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
|
181 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
182 def repo_lnk(name, rtype, private, fork_of): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
183 return _render('repo_name', name, rtype, private, fork_of, |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
184 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
|
185 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
186 def last_change(last_change): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
187 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
|
188 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
189 def rss_lnk(repo_name): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
190 return _render("rss", repo_name) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
191 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
192 def atom_lnk(repo_name): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
193 return _render("atom", repo_name) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
194 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
195 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
|
196 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
|
197 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
|
198 cs_cache.get('message')) |
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 desc(desc): |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
201 if c.visual.stylify_metatags: |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
202 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
|
203 else: |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
204 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
|
205 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
206 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
|
207 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
|
208 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
209 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
|
210 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
|
211 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
212 repos_data = [] |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
213 for repo in repos_list: |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
214 if perm_check: |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
215 # check permission at this level |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
216 if not HasRepoPermissionAny( |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
217 'repository.read', 'repository.write', 'repository.admin' |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
218 )(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
|
219 continue |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
220 cs_cache = repo.changeset_cache |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
221 row = { |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
222 "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
|
223 "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
|
224 "name": repo_lnk(repo.repo_name, repo.repo_type, |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
225 repo.private, repo.fork), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
226 "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
|
227 "last_changeset": last_rev(repo.repo_name, cs_cache), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
228 "raw_tip": cs_cache.get('revision'), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
229 "desc": desc(repo.description), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
230 "owner": h.person(repo.user.username), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
231 "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
|
232 "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
|
233 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
234 } |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
235 if admin: |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
236 row.update({ |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
237 "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
|
238 "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
|
239 h.person(repo.user.username)) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
240 }) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
241 repos_data.append(row) |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
242 |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
243 return { |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
244 "totalRecords": len(repos_list), |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
245 "startIndex": 0, |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
246 "sort": "name", |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
247 "dir": "asc", |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
248 "records": repos_data |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
249 } |
0226b6d6b2b5
Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents:
3115
diff
changeset
|
250 |
1594 | 251 def _get_defaults(self, repo_name): |
252 """ | |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
253 Get's information about repository, and returns a dict for |
1594 | 254 usage in forms |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
255 |
1594 | 256 :param repo_name: |
257 """ | |
258 | |
259 repo_info = Repository.get_by_repo_name(repo_name) | |
260 | |
261 if repo_info is None: | |
262 return None | |
263 | |
264 defaults = repo_info.get_dict() | |
3599
8087731920d8
breadcrumbs: make repo names link to summary pages
Mads Kiilerich <madski@unity3d.com>
parents:
3452
diff
changeset
|
265 group, repo_name, repo_name_full = repo_info.groups_and_repo |
1594 | 266 defaults['repo_name'] = repo_name |
267 defaults['repo_group'] = getattr(group[-1] if group else None, | |
268 'group_id', None) | |
269 | |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
270 for strip, k in [(0, 'repo_type'), (1, 'repo_enable_downloads'), |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
271 (1, 'repo_description'), (1, 'repo_enable_locking'), |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
272 (1, 'repo_landing_rev'), (0, 'clone_uri'), |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
273 (1, 'repo_private'), (1, 'repo_enable_statistics')]: |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
274 attr = k |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
275 if strip: |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
276 attr = remove_prefix(k, 'repo_') |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
277 |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
278 defaults[k] = defaults[attr] |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
279 |
1594 | 280 # fill owner |
281 if repo_info.user: | |
282 defaults.update({'user': repo_info.user.username}) | |
283 else: | |
284 replacement_user = User.query().filter(User.admin == | |
285 True).first().username | |
286 defaults.update({'user': replacement_user}) | |
287 | |
288 # fill repository users | |
289 for p in repo_info.repo_to_perm: | |
290 defaults.update({'u_perm_%s' % p.user.username: | |
291 p.permission.permission_name}) | |
292 | |
293 # fill repository groups | |
294 for p in repo_info.users_group_to_perm: | |
295 defaults.update({'g_perm_%s' % p.users_group.users_group_name: | |
296 p.permission.permission_name}) | |
297 | |
298 return defaults | |
299 | |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
300 def update(self, org_repo_name, **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
|
301 try: |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
302 cur_repo = self.get_by_repo_name(org_repo_name, cache=False) |
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
|
303 |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
304 if 'user' in kwargs: |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
305 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
|
306 |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
307 if 'repo_group' in kwargs: |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
308 cur_repo.group = RepoGroup.get(kwargs['repo_group']) |
1323
a7a772ea7b95
fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents:
1271
diff
changeset
|
309 |
3859
c32322126fe4
Repo type can't be changed. Fixes issue 836
Simon Lopez <simon.lopez@slopez.org>
parents:
3840
diff
changeset
|
310 for strip, k in [(1, 'repo_enable_downloads'), |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
311 (1, 'repo_description'), (1, 'repo_enable_locking'), |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
312 (1, 'repo_landing_rev'), (0, 'clone_uri'), |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
313 (1, 'repo_private'), (1, 'repo_enable_statistics')]: |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
314 if k in kwargs: |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
315 val = kwargs[k] |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
316 if strip: |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
317 k = remove_prefix(k, 'repo_') |
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
318 setattr(cur_repo, k, val) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
319 |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
320 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
|
321 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
|
322 #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
|
323 |
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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 ) |
3308
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3245
diff
changeset
|
329 #handle extra fields |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3245
diff
changeset
|
330 for field in filter(lambda k: k.startswith(RepositoryField.PREFIX), kwargs): |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3245
diff
changeset
|
331 k = RepositoryField.un_prefix_key(field) |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3245
diff
changeset
|
332 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
|
333 if ex_field: |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3245
diff
changeset
|
334 ex_field.field_value = kwargs[field] |
72a91632b731
repository extra fields implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
3245
diff
changeset
|
335 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
|
336 self.sa.add(cur_repo) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
337 |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
338 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
|
339 # rename repository |
3089
4cc9bb83ecb4
Fixed some issues with edit form
Marcin Kuzminski <marcin@python-works.com>
parents:
3056
diff
changeset
|
340 self.__rename_repo(old=org_repo_name, new=new_name) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
341 |
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
|
342 return cur_repo |
3631
10b4e34841a4
Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents:
3629
diff
changeset
|
343 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
|
344 log.error(traceback.format_exc()) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
345 raise |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
346 |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
347 def create_repo(self, repo_name, repo_type, description, owner, |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
348 private=False, clone_uri=None, repos_group=None, |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
349 landing_rev='tip', just_db=False, fork_of=None, |
3056
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
350 copy_fork_permissions=False, enable_statistics=False, |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
351 enable_locking=False, enable_downloads=False): |
2652
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
352 """ |
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
353 Create repository |
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
354 |
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
355 """ |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
356 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
|
357 |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
358 owner = self._get_user(owner) |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
359 fork_of = self._get_repo(fork_of) |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
360 repos_group = self._get_repo_group(repos_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
|
361 try: |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
362 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
363 # 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
|
364 # 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
|
365 # 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
|
366 repo_name_full = repo_name |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
367 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
|
368 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
369 new_repo = Repository() |
1075
f726a939d2d4
Enable statistics are disabled by default now
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
370 new_repo.enable_statistics = False |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
371 new_repo.repo_name = repo_name_full |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
372 new_repo.repo_type = repo_type |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
373 new_repo.user = owner |
2529
40b3a54391f9
Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents:
2524
diff
changeset
|
374 new_repo.group = repos_group |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
375 new_repo.description = description or repo_name |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
376 new_repo.private = private |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
377 new_repo.clone_uri = clone_uri |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
378 new_repo.landing_rev = landing_rev |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
379 |
3056
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
380 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
|
381 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
|
382 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
|
383 |
2755
839ee7a774ab
inherit locking from parent
Marcin Kuzminski <marcin@python-works.com>
parents:
2652
diff
changeset
|
384 if repos_group: |
839ee7a774ab
inherit locking from parent
Marcin Kuzminski <marcin@python-works.com>
parents:
2652
diff
changeset
|
385 new_repo.enable_locking = repos_group.enable_locking |
839ee7a774ab
inherit locking from parent
Marcin Kuzminski <marcin@python-works.com>
parents:
2652
diff
changeset
|
386 |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
387 if fork_of: |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
388 parent_repo = fork_of |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
389 new_repo.fork = parent_repo |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
390 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
391 self.sa.add(new_repo) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
392 |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
393 if fork_of: |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
394 if copy_fork_permissions: |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
395 repo = fork_of |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
396 user_perms = UserRepoToPerm.query()\ |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
397 .filter(UserRepoToPerm.repository == repo).all() |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
398 group_perms = UserGroupRepoToPerm.query()\ |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
399 .filter(UserGroupRepoToPerm.repository == repo).all() |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
400 |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
401 for perm in user_perms: |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
402 UserRepoToPerm.create(perm.user, new_repo, |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
403 perm.permission) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
404 |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
405 for perm in group_perms: |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
406 UserGroupRepoToPerm.create(perm.users_group, new_repo, |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
407 perm.permission) |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
408 else: |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
409 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
|
410 self.sa.add(perm_obj) |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
411 else: |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
412 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
|
413 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
|
414 |
f42ee60e673b
fixed issue with db transaction when filesystem creation of repository failed
Marcin Kuzminski <marcin@python-works.com>
parents:
1020
diff
changeset
|
415 if not just_db: |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
416 self.__create_repo(repo_name, repo_type, |
2529
40b3a54391f9
Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents:
2524
diff
changeset
|
417 repos_group, |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
418 clone_uri) |
2185
eac0d6194783
fixed repo_create hooks for forks
Marcin Kuzminski <marcin@python-works.com>
parents:
2142
diff
changeset
|
419 log_create_repository(new_repo.get_dict(), |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
420 created_by=owner.username) |
2621
4f3ecd7357a2
Removed stupid code that assumed we have vcs instance after just creating it in database.
Marcin Kuzminski <marcin@python-works.com>
parents:
2618
diff
changeset
|
421 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
422 # 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
|
423 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
|
424 owner.user_id) |
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
|
425 return new_repo |
3631
10b4e34841a4
Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents:
3629
diff
changeset
|
426 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
|
427 log.error(traceback.format_exc()) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
428 raise |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
429 |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
430 def create(self, form_data, cur_user, just_db=False, fork=None): |
2652
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
431 """ |
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
432 Backward compatibility function, just a wrapper on top of create_repo |
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
433 |
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
434 :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
|
435 :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
|
436 :param just_db: |
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
437 :param fork: |
532ee86cf9b1
Refactored create fork function to use new RepoModel functions instead of old
Marcin Kuzminski <marcin@python-works.com>
parents:
2631
diff
changeset
|
438 """ |
3056
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
439 owner = cur_user |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
440 repo_name = form_data['repo_name_full'] |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
441 repo_type = form_data['repo_type'] |
3056
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
442 description = form_data['repo_description'] |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
443 private = form_data['repo_private'] |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
444 clone_uri = form_data.get('clone_uri') |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
445 repos_group = form_data['repo_group'] |
3056
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
446 landing_rev = form_data['repo_landing_rev'] |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
447 copy_fork_permissions = form_data.get('copy_permissions') |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
448 fork_of = form_data.get('fork_parent_id') |
3056
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
449 |
3115
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
450 ## repo creation defaults, private and repo_type are filled in form |
3056
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
451 defs = RhodeCodeSetting.get_default_repo_settings(strip_prefix=True) |
3115
ebd76deee70d
Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents:
3089
diff
changeset
|
452 enable_statistics = defs.get('repo_enable_statistics') |
3056
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
453 enable_locking = defs.get('repo_enable_locking') |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
454 enable_downloads = defs.get('repo_enable_downloads') |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
455 |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
456 return self.create_repo( |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
457 repo_name, repo_type, description, owner, private, clone_uri, |
3056
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
458 repos_group, landing_rev, just_db, fork_of, copy_fork_permissions, |
6104dfd35b16
Implemented #379 defaults settings page for creation of repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
2949
diff
changeset
|
459 enable_statistics, enable_locking, enable_downloads |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
460 ) |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
461 |
3827
ff57547c9cf7
Add flag for permission check in _update_permissions function
Marcin Kuzminski <marcin@python-works.com>
parents:
3789
diff
changeset
|
462 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
|
463 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
|
464 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
|
465 perms_new = [] |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
466 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
|
467 perms_updates = [] |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
468 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
469 # update permissions |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
470 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
|
471 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
|
472 # 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
|
473 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
|
474 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
|
475 ) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
476 else: |
3789
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
477 #check if we have permissions to alter this usergroup |
3827
ff57547c9cf7
Add flag for permission check in _update_permissions function
Marcin Kuzminski <marcin@python-works.com>
parents:
3789
diff
changeset
|
478 req_perms = ('usergroup.read', 'usergroup.write', 'usergroup.admin') |
ff57547c9cf7
Add flag for permission check in _update_permissions function
Marcin Kuzminski <marcin@python-works.com>
parents:
3789
diff
changeset
|
479 if not check_perms or HasUserGroupPermissionAny(*req_perms)(member): |
3789
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
480 self.grant_users_group_permission( |
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
481 repo=repo, group_name=member, perm=perm |
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
482 ) |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
483 # set new permissions |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
484 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
|
485 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
|
486 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
|
487 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
|
488 ) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
489 else: |
3789
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
490 #check if we have permissions to alter this usergroup |
3827
ff57547c9cf7
Add flag for permission check in _update_permissions function
Marcin Kuzminski <marcin@python-works.com>
parents:
3789
diff
changeset
|
491 req_perms = ('usergroup.read', 'usergroup.write', 'usergroup.admin') |
ff57547c9cf7
Add flag for permission check in _update_permissions function
Marcin Kuzminski <marcin@python-works.com>
parents:
3789
diff
changeset
|
492 if not check_perms or HasUserGroupPermissionAny(*req_perms)(member): |
3789
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
493 self.grant_users_group_permission( |
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
494 repo=repo, group_name=member, perm=perm |
32f66c839c54
managing users groups enforce permissions checks.
Marcin Kuzminski <marcin@python-works.com>
parents:
3734
diff
changeset
|
495 ) |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3694
diff
changeset
|
496 |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
497 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
|
498 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
499 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
|
500 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
501 :param form_data: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
502 :param cur_user: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
503 """ |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
504 from rhodecode.lib.celerylib import tasks, run_task |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
505 run_task(tasks.create_repo_fork, form_data, cur_user) |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
506 |
3694
34093903b505
repo rescann should detach forks of zombie repos,
Marcin Kuzminski <marcin@python-works.com>
parents:
3641
diff
changeset
|
507 def delete(self, repo, forks=None, fs_remove=True): |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
508 """ |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
509 Delete given repository, forks parameter defines what do do with |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
510 attached forks. Throws AttachedForksError if deleted repo has attached |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
511 forks |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
512 |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
513 :param repo: |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
514 :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
|
515 :param fs_remove: remove(archive) repo from filesystem |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
516 """ |
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
|
517 repo = self._get_repo(repo) |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
518 if repo: |
3641
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
519 if forks == 'detach': |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
520 for r in repo.forks: |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
521 r.fork = None |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
522 self.sa.add(r) |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
523 elif forks == 'delete': |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
524 for r in repo.forks: |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
525 self.delete(r, forks='delete') |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
526 elif [f for f in repo.forks]: |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
527 raise AttachedForksError() |
b44979649915
recursive forks detach
Marcin Kuzminski <marcin@python-works.com>
parents:
3631
diff
changeset
|
528 |
2904
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
529 old_repo_dict = repo.get_dict() |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
530 owner = repo.user |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
531 try: |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
532 self.sa.delete(repo) |
3694
34093903b505
repo rescann should detach forks of zombie repos,
Marcin Kuzminski <marcin@python-works.com>
parents:
3641
diff
changeset
|
533 if fs_remove: |
34093903b505
repo rescann should detach forks of zombie repos,
Marcin Kuzminski <marcin@python-works.com>
parents:
3641
diff
changeset
|
534 self.__delete_repo(repo) |
34093903b505
repo rescann should detach forks of zombie repos,
Marcin Kuzminski <marcin@python-works.com>
parents:
3641
diff
changeset
|
535 else: |
34093903b505
repo rescann should detach forks of zombie repos,
Marcin Kuzminski <marcin@python-works.com>
parents:
3641
diff
changeset
|
536 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
|
537 log_delete_repository(old_repo_dict, |
1b275d04ac07
#595 add rcextension hook for repository delete
Marcin Kuzminski <marcin@python-works.com>
parents:
2820
diff
changeset
|
538 deleted_by=owner.username) |
3631
10b4e34841a4
Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents:
3629
diff
changeset
|
539 except Exception: |
2524
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
540 log.error(traceback.format_exc()) |
9d4b80743a2a
New repo model create function
Marcin Kuzminski <marcin@python-works.com>
parents:
2522
diff
changeset
|
541 raise |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
542 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
543 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
|
544 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
545 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
|
546 if found |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
547 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
548 :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
|
549 :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
|
550 :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
|
551 """ |
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
|
552 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
|
553 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
|
554 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
|
555 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
556 # check if we have that permission already |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
557 obj = self.sa.query(UserRepoToPerm)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
558 .filter(UserRepoToPerm.user == user)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
559 .filter(UserRepoToPerm.repository == repo)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
560 .scalar() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
561 if obj is None: |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
562 # create new ! |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
563 obj = UserRepoToPerm() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
564 obj.repository = repo |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
565 obj.user = user |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
566 obj.permission = permission |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
567 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
|
568 log.debug('Granted perm %s to %s on %s' % (perm, user, repo)) |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
569 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
570 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
|
571 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
572 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
|
573 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
574 :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
|
575 :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
|
576 """ |
2142
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
577 |
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
|
578 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
|
579 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
|
580 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
581 obj = self.sa.query(UserRepoToPerm)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
582 .filter(UserRepoToPerm.repository == repo)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
583 .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
|
584 .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
|
585 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
|
586 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
|
587 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
|
588 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
589 def grant_users_group_permission(self, repo, group_name, perm): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
590 """ |
3415
b8f929bff7e3
fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents:
3314
diff
changeset
|
591 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
|
592 existing one if found |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
593 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
594 :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
|
595 :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
|
596 or user group name |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
597 :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
|
598 """ |
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
|
599 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
|
600 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
|
601 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
|
602 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
603 # check if we have that permission already |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
604 obj = self.sa.query(UserGroupRepoToPerm)\ |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
605 .filter(UserGroupRepoToPerm.users_group == group_name)\ |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
606 .filter(UserGroupRepoToPerm.repository == repo)\ |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
607 .scalar() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
608 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
609 if obj is None: |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
610 # create new |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
611 obj = UserGroupRepoToPerm() |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
612 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
613 obj.repository = repo |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
614 obj.users_group = group_name |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
615 obj.permission = permission |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
616 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
|
617 log.debug('Granted perm %s to %s on %s' % (perm, group_name, repo)) |
1982
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 def revoke_users_group_permission(self, repo, group_name): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
620 """ |
3415
b8f929bff7e3
fixed tests and missing replacements from 5f1850e4712a
Marcin Kuzminski <marcin@python-works.com>
parents:
3314
diff
changeset
|
621 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
|
622 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
623 :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
|
624 :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
|
625 or user group name |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
626 """ |
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
|
627 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
|
628 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
|
629 |
3417
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
630 obj = self.sa.query(UserGroupRepoToPerm)\ |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
631 .filter(UserGroupRepoToPerm.repository == repo)\ |
fa6ba6727475
further cleanup of UsersGroup
Mads Kiilerich <madski@unity3d.com>
parents:
3415
diff
changeset
|
632 .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
|
633 .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
|
634 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
|
635 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
|
636 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
|
637 |
708
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
638 def delete_stats(self, repo_name): |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
639 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
640 removes stats for given repo |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
641 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
642 :param repo_name: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
643 """ |
3314
059efaea23d6
fix reset statistics call if there are no statistics yet
Marcin Kuzminski <marcin@python-works.com>
parents:
3309
diff
changeset
|
644 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
|
645 try: |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1669
diff
changeset
|
646 obj = self.sa.query(Statistics)\ |
3314
059efaea23d6
fix reset statistics call if there are no statistics yet
Marcin Kuzminski <marcin@python-works.com>
parents:
3309
diff
changeset
|
647 .filter(Statistics.repository == repo).scalar() |
059efaea23d6
fix reset statistics call if there are no statistics yet
Marcin Kuzminski <marcin@python-works.com>
parents:
3309
diff
changeset
|
648 if obj: |
059efaea23d6
fix reset statistics call if there are no statistics yet
Marcin Kuzminski <marcin@python-works.com>
parents:
3309
diff
changeset
|
649 self.sa.delete(obj) |
3631
10b4e34841a4
Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents:
3629
diff
changeset
|
650 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
|
651 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
|
652 raise |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
653 |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
654 def _create_repo(self, repo_name, alias, parent, clone_uri=False, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
655 repo_store_location=None): |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
656 return self.__create_repo(repo_name, alias, parent, clone_uri, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
657 repo_store_location) |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
658 |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
659 def __create_repo(self, repo_name, alias, parent, clone_uri=False, |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
660 repo_store_location=None): |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
661 """ |
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
|
662 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
|
663 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
|
664 group location |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1119
diff
changeset
|
665 |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
666 :param repo_name: |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
667 :param alias: |
1350
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
668 :param parent_id: |
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
669 :param clone_uri: |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
670 :param repo_path: |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
671 """ |
1594 | 672 from rhodecode.lib.utils import is_valid_repo, is_valid_repos_group |
2618
e1370dcb9908
Created install_git_hook more verbose version of previos code.
Marcin Kuzminski <marcin@python-works.com>
parents:
2592
diff
changeset
|
673 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
|
674 |
2529
40b3a54391f9
Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents:
2524
diff
changeset
|
675 if parent: |
40b3a54391f9
Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents:
2524
diff
changeset
|
676 new_parent_path = os.sep.join(parent.full_path_splitted) |
1350
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
677 else: |
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
678 new_parent_path = '' |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
679 if repo_store_location: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
680 _paths = [repo_store_location] |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
681 else: |
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
682 _paths = [self.repos_path, new_parent_path, repo_name] |
1973
0a46e8f1b7aa
fixed issue with logger crashing on mixed str and unicode
Marcin Kuzminski <marcin@python-works.com>
parents:
1972
diff
changeset
|
683 # 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
|
684 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
|
685 |
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
|
686 # 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
|
687 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
|
688 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
|
689 |
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
|
690 # check if this path is a group |
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
|
691 if is_valid_repos_group(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
|
692 raise Exception('This path %s is a valid group' % repo_path) |
1594 | 693 |
1973
0a46e8f1b7aa
fixed issue with logger crashing on mixed str and unicode
Marcin Kuzminski <marcin@python-works.com>
parents:
1972
diff
changeset
|
694 log.info('creating repo %s in %s @ %s' % ( |
3452
d778ed1c945f
use password obfuscate in when clonning a remote repo with credentials
Marcin Kuzminski <marcin@python-works.com>
parents:
3420
diff
changeset
|
695 repo_name, safe_unicode(repo_path), |
d778ed1c945f
use password obfuscate in when clonning a remote repo with credentials
Marcin Kuzminski <marcin@python-works.com>
parents:
3420
diff
changeset
|
696 obfuscate_url_pw(clone_uri) |
1973
0a46e8f1b7aa
fixed issue with logger crashing on mixed str and unicode
Marcin Kuzminski <marcin@python-works.com>
parents:
1972
diff
changeset
|
697 ) |
0a46e8f1b7aa
fixed issue with logger crashing on mixed str and unicode
Marcin Kuzminski <marcin@python-works.com>
parents:
1972
diff
changeset
|
698 ) |
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
|
699 backend = get_backend(alias) |
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
|
700 if alias == 'hg': |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
701 repo = backend(repo_path, create=True, src_url=clone_uri) |
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
|
702 elif alias == 'git': |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
703 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
|
704 # add rhodecode hook into this repo |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
705 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
|
706 else: |
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
|
707 raise Exception('Undefined alias %s' % alias) |
3840
dc4644865e8b
Implemented simple gist functionality ref #530.
Marcin Kuzminski <marcin@python-works.com>
parents:
3827
diff
changeset
|
708 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
|
709 |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
710 def __rename_repo(self, old, new): |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
711 """ |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
712 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
|
713 |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
714 :param old: old name |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
715 :param new: new name |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
716 """ |
1976 | 717 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
|
718 |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
719 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
|
720 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
|
721 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
|
722 raise Exception( |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
723 '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
|
724 ) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
725 shutil.move(old_path, new_path) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
726 |
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
|
727 def __delete_repo(self, repo): |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
728 """ |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
729 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
|
730 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
|
731 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
|
732 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
|
733 |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
734 :param repo: repo object |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
735 """ |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
736 rm_path = os.path.join(self.repos_path, repo.repo_name) |
1976 | 737 log.info("Removing %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
|
738 # 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
|
739 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
|
740 |
69b836e383df
don't disable .git directory for bare repos on deleting, ref #413
Marcin Kuzminski <marcin@python-works.com>
parents:
2321
diff
changeset
|
741 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
|
742 |
69b836e383df
don't disable .git directory for bare repos on deleting, ref #413
Marcin Kuzminski <marcin@python-works.com>
parents:
2321
diff
changeset
|
743 if not bare: |
69b836e383df
don't disable .git directory for bare repos on deleting, ref #413
Marcin Kuzminski <marcin@python-works.com>
parents:
2321
diff
changeset
|
744 # skip this for bare git repos |
69b836e383df
don't disable .git directory for bare repos on deleting, ref #413
Marcin Kuzminski <marcin@python-works.com>
parents:
2321
diff
changeset
|
745 shutil.move(os.path.join(rm_path, '.%s' % alias), |
69b836e383df
don't disable .git directory for bare repos on deleting, ref #413
Marcin Kuzminski <marcin@python-works.com>
parents:
2321
diff
changeset
|
746 os.path.join(rm_path, 'rm__.%s' % alias)) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1729
diff
changeset
|
747 # disable repo |
2553
069e13b4dddc
removed %f from datetime formatting doesn't work on py25 :/
Marcin Kuzminski <marcin@python-works.com>
parents:
2529
diff
changeset
|
748 _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
|
749 _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
|
750 _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
|
751 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
|
752 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
|
753 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
|
754 _d = os.path.join(*args) |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
755 shutil.move(rm_path, os.path.join(self.repos_path, _d)) |