Mercurial > kallithea
annotate rhodecode/model/repo.py @ 2445:9b623dcddb02 beta
Format datetime in notifications according to unified function
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 11 Jun 2012 23:23:32 +0200 |
parents | d3978233fcfa |
children | d3ac7491a5c8 |
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 |
2404
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
30 import pkg_resources |
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
31 from os.path import dirname as dn, join as jn |
367
a26f48ad7a8a
fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents:
356
diff
changeset
|
32 from datetime import datetime |
786
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
33 |
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
|
34 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
|
35 from rhodecode.lib.compat import json |
2109 | 36 from rhodecode.lib.utils2 import LazyProperty, safe_str, safe_unicode |
1669
f522f4d3bf93
moved caching query to libs
Marcin Kuzminski <marcin@python-works.com>
parents:
1633
diff
changeset
|
37 from rhodecode.lib.caching_query import FromCache |
1972
27abf546aa8a
#348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents:
1824
diff
changeset
|
38 from rhodecode.lib.hooks import log_create_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
|
39 |
786
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
40 from rhodecode.model import BaseModel |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
41 from rhodecode.model.db import Repository, UserRepoToPerm, User, Permission, \ |
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
42 Statistics, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi, RepoGroup |
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 |
786
2889a4446960
when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents:
752
diff
changeset
|
44 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
45 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 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
|
47 |
1271
aa7e45ad0cea
Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents:
1206
diff
changeset
|
48 |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
49 class RepoModel(BaseModel): |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
50 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
51 def __get_user(self, user): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
52 return self._get_instance(User, user, callback=User.get_by_username) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
53 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
54 def __get_users_group(self, users_group): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
55 return self._get_instance(UsersGroup, users_group, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
56 callback=UsersGroup.get_by_group_name) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
57 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
58 def __get_repos_group(self, repos_group): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
59 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
|
60 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
|
61 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
62 def __get_repo(self, repository): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
63 return self._get_instance(Repository, repository, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
64 callback=Repository.get_by_repo_name) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
65 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
66 def __get_perm(self, permission): |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
67 return self._get_instance(Permission, permission, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
68 callback=Permission.get_by_key) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
69 |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
70 @LazyProperty |
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
71 def repos_path(self): |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
72 """ |
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
73 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
|
74 """ |
1017
ade3414a8b61
Fixed problems with repository creation
Marcin Kuzminski <marcin@python-works.com>
parents:
1015
diff
changeset
|
75 |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
76 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
|
77 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
|
78 |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
79 def get(self, repo_id, cache=False): |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
80 repo = self.sa.query(Repository)\ |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
81 .filter(Repository.repo_id == repo_id) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
82 |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
83 if cache: |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
84 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
|
85 "get_repo_%s" % repo_id)) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
86 return repo.scalar() |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
87 |
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
|
88 def get_repo(self, repository): |
14dffcfebb02
API get_user and get_repo methods can fetch by id or names
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
89 return self.__get_repo(repository) |
14dffcfebb02
API get_user and get_repo methods can fetch by id or names
Marcin Kuzminski <marcin@python-works.com>
parents:
2007
diff
changeset
|
90 |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
91 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
|
92 repo = self.sa.query(Repository)\ |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
93 .filter(Repository.repo_name == repo_name) |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
94 |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
95 if cache: |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
96 repo = repo.options(FromCache("sql_cache_short", |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
97 "get_repo_%s" % repo_name)) |
752
89b9037d68b7
fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
98 return repo.scalar() |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
708
diff
changeset
|
99 |
298
15e96b5a2685
autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents:
296
diff
changeset
|
100 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
|
101 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
|
102 return json.dumps([ |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
103 { |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
104 'id': u.user_id, |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
105 'fname': u.name, |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
106 'lname': u.lastname, |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
107 'nname': u.username, |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
108 '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
|
109 } for u in users] |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
110 ) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
111 |
1013
d2a840b29858
#56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
112 def get_users_groups_js(self): |
d2a840b29858
#56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
113 users_groups = self.sa.query(UsersGroup)\ |
d2a840b29858
#56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
114 .filter(UsersGroup.users_group_active == True).all() |
d2a840b29858
#56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
115 |
2142
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
116 return json.dumps([ |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
117 { |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
118 'id': gr.users_group_id, |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
119 'grname': gr.users_group_name, |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
120 'grmembers': len(gr.members), |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
121 } for gr in users_groups] |
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
122 ) |
1013
d2a840b29858
#56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
123 |
1594 | 124 def _get_defaults(self, repo_name): |
125 """ | |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
126 Get's information about repository, and returns a dict for |
1594 | 127 usage in forms |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
128 |
1594 | 129 :param repo_name: |
130 """ | |
131 | |
132 repo_info = Repository.get_by_repo_name(repo_name) | |
133 | |
134 if repo_info is None: | |
135 return None | |
136 | |
137 defaults = repo_info.get_dict() | |
138 group, repo_name = repo_info.groups_and_repo | |
139 defaults['repo_name'] = repo_name | |
140 defaults['repo_group'] = getattr(group[-1] if group else None, | |
141 'group_id', None) | |
142 | |
143 # fill owner | |
144 if repo_info.user: | |
145 defaults.update({'user': repo_info.user.username}) | |
146 else: | |
147 replacement_user = User.query().filter(User.admin == | |
148 True).first().username | |
149 defaults.update({'user': replacement_user}) | |
150 | |
151 # fill repository users | |
152 for p in repo_info.repo_to_perm: | |
153 defaults.update({'u_perm_%s' % p.user.username: | |
154 p.permission.permission_name}) | |
155 | |
156 # fill repository groups | |
157 for p in repo_info.users_group_to_perm: | |
158 defaults.update({'g_perm_%s' % p.users_group.users_group_name: | |
159 p.permission.permission_name}) | |
160 | |
161 return defaults | |
162 | |
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
|
163 def update(self, repo_name, form_data): |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
164 try: |
822
d5a71348ee4d
small code fixes to repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
811
diff
changeset
|
165 cur_repo = self.get_by_repo_name(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
|
166 |
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
|
167 # update permissions |
1014
6fdc3ff65fce
#56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents:
1013
diff
changeset
|
168 for member, perm, member_type in form_data['perms_updates']: |
6fdc3ff65fce
#56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents:
1013
diff
changeset
|
169 if member_type == 'user': |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
170 # this updates existing one |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
171 RepoModel().grant_user_permission( |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
172 repo=cur_repo, user=member, perm=perm |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
173 ) |
1014
6fdc3ff65fce
#56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents:
1013
diff
changeset
|
174 else: |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
175 RepoModel().grant_users_group_permission( |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
176 repo=cur_repo, group_name=member, perm=perm |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
177 ) |
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
|
178 # set new permissions |
1014
6fdc3ff65fce
#56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents:
1013
diff
changeset
|
179 for member, perm, member_type in form_data['perms_new']: |
6fdc3ff65fce
#56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents:
1013
diff
changeset
|
180 if member_type == 'user': |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
181 RepoModel().grant_user_permission( |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
182 repo=cur_repo, user=member, perm=perm |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
183 ) |
1014
6fdc3ff65fce
#56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents:
1013
diff
changeset
|
184 else: |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
185 RepoModel().grant_users_group_permission( |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
186 repo=cur_repo, group_name=member, perm=perm |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
187 ) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
188 |
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
|
189 # update current repo |
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
|
190 for k, v in form_data.items(): |
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
|
191 if k == 'user': |
1530
04027bdb876c
Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents:
1517
diff
changeset
|
192 cur_repo.user = User.get_by_username(v) |
1323
a7a772ea7b95
fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents:
1271
diff
changeset
|
193 elif k == '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
|
194 pass |
1379
7ca0b584c912
fixes #205 db value was not set to none after moving out of group
Marcin Kuzminski <marcin@python-works.com>
parents:
1366
diff
changeset
|
195 elif k == 'repo_group': |
1633
2c0d35e336b5
refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents:
1594
diff
changeset
|
196 cur_repo.group = RepoGroup.get(v) |
1323
a7a772ea7b95
fixed saving settings on repositories inside groups, also fixes #187
Marcin Kuzminski <marcin@python-works.com>
parents:
1271
diff
changeset
|
197 |
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
|
198 else: |
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
|
199 setattr(cur_repo, k, v) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
200 |
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
|
201 new_name = cur_repo.get_new_name(form_data['repo_name']) |
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
|
202 cur_repo.repo_name = new_name |
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
|
203 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
204 self.sa.add(cur_repo) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
205 |
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
|
206 if 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
|
207 # rename repository |
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
|
208 self.__rename_repo(old=repo_name, new=new_name) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
209 |
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
|
210 return cur_repo |
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
|
211 except: |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
212 log.error(traceback.format_exc()) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
213 raise |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
214 |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
215 def create(self, form_data, cur_user, just_db=False, fork=False): |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
216 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
|
217 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
218 try: |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
219 if fork: |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
220 fork_parent_id = form_data['fork_parent_id'] |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
221 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
222 # 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
|
223 # 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
|
224 # with name and path of group |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
225 repo_name = form_data['repo_name'] |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
226 repo_name_full = form_data['repo_name_full'] |
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
|
227 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
228 new_repo = Repository() |
1075
f726a939d2d4
Enable statistics are disabled by default now
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
229 new_repo.enable_statistics = False |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
230 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
231 for k, v in form_data.items(): |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
232 if k == 'repo_name': |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
233 v = repo_name_full |
1350
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
234 if k == 'repo_group': |
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
235 k = 'group_id' |
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
|
236 if k == 'description': |
142a05597cba
assure that we don't have an empty description when creating a repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1507
diff
changeset
|
237 v = v or repo_name |
142a05597cba
assure that we don't have an empty description when creating a repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1507
diff
changeset
|
238 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
239 setattr(new_repo, k, v) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
240 |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
241 if fork: |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
242 parent_repo = Repository.get(fork_parent_id) |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
243 new_repo.fork = parent_repo |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
244 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
245 new_repo.user_id = cur_user.user_id |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
246 self.sa.add(new_repo) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
247 |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
248 def _create_default_perms(): |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
249 # create default permission |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
250 repo_to_perm = UserRepoToPerm() |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
251 default = 'repository.read' |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
252 for p in User.get_by_username('default').user_perms: |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
253 if p.permission.permission_name.startswith('repository.'): |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
254 default = p.permission.permission_name |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
255 break |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
256 |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
257 default_perm = 'repository.none' if form_data['private'] else default |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
258 |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
259 repo_to_perm.permission_id = self.sa.query(Permission)\ |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
260 .filter(Permission.permission_name == default_perm)\ |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
261 .one().permission_id |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
262 |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
263 repo_to_perm.repository = new_repo |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
264 repo_to_perm.user_id = User.get_by_username('default').user_id |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
265 |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
266 self.sa.add(repo_to_perm) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
267 |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
268 if fork: |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
269 if form_data.get('copy_permissions'): |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
270 repo = Repository.get(fork_parent_id) |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
271 user_perms = UserRepoToPerm.query()\ |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
272 .filter(UserRepoToPerm.repository == repo).all() |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
273 group_perms = UsersGroupRepoToPerm.query()\ |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
274 .filter(UsersGroupRepoToPerm.repository == repo).all() |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
275 |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
276 for perm in user_perms: |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
277 UserRepoToPerm.create(perm.user, new_repo, |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
278 perm.permission) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
279 |
1729
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
280 for perm in group_perms: |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
281 UsersGroupRepoToPerm.create(perm.users_group, new_repo, |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
282 perm.permission) |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
283 else: |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
284 _create_default_perms() |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
285 else: |
da8ee2ef7f6d
implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents:
1722
diff
changeset
|
286 _create_default_perms() |
1028
f42ee60e673b
fixed issue with db transaction when filesystem creation of repository failed
Marcin Kuzminski <marcin@python-works.com>
parents:
1020
diff
changeset
|
287 |
f42ee60e673b
fixed issue with db transaction when filesystem creation of repository failed
Marcin Kuzminski <marcin@python-works.com>
parents:
1020
diff
changeset
|
288 if not just_db: |
1112
6d0a7284949d
#109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents:
1075
diff
changeset
|
289 self.__create_repo(repo_name, form_data['repo_type'], |
1350
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
290 form_data['repo_group'], |
1112
6d0a7284949d
#109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents:
1075
diff
changeset
|
291 form_data['clone_uri']) |
2185
eac0d6194783
fixed repo_create hooks for forks
Marcin Kuzminski <marcin@python-works.com>
parents:
2142
diff
changeset
|
292 log_create_repository(new_repo.get_dict(), |
eac0d6194783
fixed repo_create hooks for forks
Marcin Kuzminski <marcin@python-works.com>
parents:
2142
diff
changeset
|
293 created_by=cur_user.username) |
1028
f42ee60e673b
fixed issue with db transaction when filesystem creation of repository failed
Marcin Kuzminski <marcin@python-works.com>
parents:
1020
diff
changeset
|
294 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
295 # 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
|
296 ScmModel(self.sa).toggle_following_repo(new_repo.repo_id, |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
297 cur_user.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
|
298 return new_repo |
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
|
299 except: |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
300 log.error(traceback.format_exc()) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
301 raise |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
302 |
530
a08f610e545e
Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents:
417
diff
changeset
|
303 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
|
304 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
305 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
|
306 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
307 :param form_data: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
308 :param cur_user: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
309 """ |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
310 from rhodecode.lib.celerylib import tasks, run_task |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
311 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
|
312 |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
313 def delete(self, repo): |
2003
7dfcdf4c7dd2
implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1982
diff
changeset
|
314 repo = self.__get_repo(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
|
315 try: |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
316 self.sa.delete(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
|
317 self.__delete_repo(repo) |
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
|
318 except: |
29370bb76fa6
first permissions commit: added permission managment on repository edit. Changed db rmissions, validators.
Marcin Kuzminski <marcin@python-works.com>
parents:
265
diff
changeset
|
319 log.error(traceback.format_exc()) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
320 raise |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
321 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
322 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
|
323 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
324 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
|
325 if found |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
326 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
327 :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
|
328 :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
|
329 :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
|
330 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
331 user = self.__get_user(user) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
332 repo = self.__get_repo(repo) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
333 permission = self.__get_perm(perm) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
334 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
335 # 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
|
336 obj = self.sa.query(UserRepoToPerm)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
337 .filter(UserRepoToPerm.user == user)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
338 .filter(UserRepoToPerm.repository == repo)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
339 .scalar() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
340 if obj is None: |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
341 # create new ! |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
342 obj = UserRepoToPerm() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
343 obj.repository = repo |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
344 obj.user = user |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
345 obj.permission = permission |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
346 self.sa.add(obj) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
347 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
348 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
|
349 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
350 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
|
351 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
352 :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
|
353 :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
|
354 """ |
2142
a21eab6ff42f
Added gravatars into permissions view and permissions autocomplete
Marcin Kuzminski <marcin@python-works.com>
parents:
2109
diff
changeset
|
355 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
356 user = self.__get_user(user) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
357 repo = self.__get_repo(repo) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
358 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
359 obj = self.sa.query(UserRepoToPerm)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
360 .filter(UserRepoToPerm.repository == repo)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
361 .filter(UserRepoToPerm.user == user)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
362 .one() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
363 self.sa.delete(obj) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
364 |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
365 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
|
366 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
367 Grant permission for users group on given repository, or update |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
368 existing one if found |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
369 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
370 :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
|
371 :param group_name: Instance of UserGroup, users_group_id, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
372 or users group name |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
373 :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
|
374 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
375 repo = self.__get_repo(repo) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
376 group_name = self.__get_users_group(group_name) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
377 permission = self.__get_perm(perm) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
378 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
379 # 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
|
380 obj = self.sa.query(UsersGroupRepoToPerm)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
381 .filter(UsersGroupRepoToPerm.users_group == group_name)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
382 .filter(UsersGroupRepoToPerm.repository == repo)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
383 .scalar() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
384 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
385 if obj is None: |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
386 # create new |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
387 obj = UsersGroupRepoToPerm() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
388 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
389 obj.repository = repo |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
390 obj.users_group = group_name |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
391 obj.permission = permission |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
392 self.sa.add(obj) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
393 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
394 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
|
395 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
396 Revoke permission for users group on given repository |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
397 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
398 :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
|
399 :param group_name: Instance of UserGroup, users_group_id, |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
400 or users group name |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
401 """ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
402 repo = self.__get_repo(repo) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
403 group_name = self.__get_users_group(group_name) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
404 |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
405 obj = self.sa.query(UsersGroupRepoToPerm)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
406 .filter(UsersGroupRepoToPerm.repository == repo)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
407 .filter(UsersGroupRepoToPerm.users_group == group_name)\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
408 .one() |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
409 self.sa.delete(obj) |
1015
65129c332d37
#56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents:
1014
diff
changeset
|
410 |
708
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
411 def delete_stats(self, repo_name): |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
412 """ |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
413 removes stats for given repo |
1818
cf51bbfb120e
auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents:
1749
diff
changeset
|
414 |
1722
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
415 :param repo_name: |
e7eef7a1db6a
#235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents:
1716
diff
changeset
|
416 """ |
708
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
417 try: |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1669
diff
changeset
|
418 obj = self.sa.query(Statistics)\ |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
419 .filter(Statistics.repository == |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
420 self.get_by_repo_name(repo_name))\ |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
421 .one() |
1713
54687aa00724
Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents:
1669
diff
changeset
|
422 self.sa.delete(obj) |
708
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
423 except: |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
424 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
|
425 raise |
b9bbc0d6e9f3
added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
426 |
1350
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
427 def __create_repo(self, repo_name, alias, new_parent_id, clone_uri=False): |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
428 """ |
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
|
429 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
|
430 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
|
431 group location |
1203
6832ef664673
source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents:
1119
diff
changeset
|
432 |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
433 :param repo_name: |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
434 :param alias: |
1350
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
435 :param parent_id: |
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
436 :param clone_uri: |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
437 """ |
1594 | 438 from rhodecode.lib.utils import is_valid_repo, is_valid_repos_group |
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
|
439 |
1350
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
440 if new_parent_id: |
1716
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
441 paths = RepoGroup.get(new_parent_id)\ |
7d1fc253549e
notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents:
1713
diff
changeset
|
442 .full_path.split(RepoGroup.url_sep()) |
1350
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
443 new_parent_path = os.sep.join(paths) |
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
444 else: |
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
445 new_parent_path = '' |
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
446 |
1973
0a46e8f1b7aa
fixed issue with logger crashing on mixed str and unicode
Marcin Kuzminski <marcin@python-works.com>
parents:
1972
diff
changeset
|
447 # we need to make it str for mercurial |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
448 repo_path = os.path.join(*map(lambda x: safe_str(x), |
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
|
449 [self.repos_path, new_parent_path, repo_name])) |
1350
eb489bf9d7c7
#47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents:
1323
diff
changeset
|
450 |
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
|
451 # 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
|
452 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
|
453 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
|
454 |
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
|
455 # 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
|
456 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
|
457 raise Exception('This path %s is a valid group' % repo_path) |
1594 | 458 |
1973
0a46e8f1b7aa
fixed issue with logger crashing on mixed str and unicode
Marcin Kuzminski <marcin@python-works.com>
parents:
1972
diff
changeset
|
459 log.info('creating repo %s in %s @ %s' % ( |
0a46e8f1b7aa
fixed issue with logger crashing on mixed str and unicode
Marcin Kuzminski <marcin@python-works.com>
parents:
1972
diff
changeset
|
460 repo_name, safe_unicode(repo_path), clone_uri |
0a46e8f1b7aa
fixed issue with logger crashing on mixed str and unicode
Marcin Kuzminski <marcin@python-works.com>
parents:
1972
diff
changeset
|
461 ) |
0a46e8f1b7aa
fixed issue with logger crashing on mixed str and unicode
Marcin Kuzminski <marcin@python-works.com>
parents:
1972
diff
changeset
|
462 ) |
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
|
463 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
|
464 if alias == 'hg': |
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
|
465 backend(repo_path, create=True, src_url=clone_uri) |
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
|
466 elif alias == 'git': |
2404
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
467 r = backend(repo_path, create=True, src_url=clone_uri, bare=True) |
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
468 # add rhodecode hook into this repo |
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
469 |
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
470 loc = jn(r.path, 'hooks') |
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
471 if not r.bare: |
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
472 loc = jn(r.path, '.git', 'hooks') |
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
473 if not os.path.isdir(loc): |
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
474 os.makedirs(loc) |
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
475 |
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
476 tmpl = pkg_resources.resource_string( |
2411
d3978233fcfa
chmod the hooks to 755, like all other githooks.
Marcin Kuzminski <marcin@python-works.com>
parents:
2407
diff
changeset
|
477 'rhodecode', jn('config', 'post_receive_tmpl.py') |
2404
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
478 ) |
2407
8a68e0292232
Change git & hg hooks to post. They shouldn't block as they are used just for logging actions. Futhermore post hooks have access to changesets, so it's much better flexible
Marcin Kuzminski <marcin@python-works.com>
parents:
2404
diff
changeset
|
479 _hook_file = jn(loc, 'post-receive') |
2404
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
480 with open(_hook_file, 'wb') as f: |
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
481 f.write(tmpl) |
2411
d3978233fcfa
chmod the hooks to 755, like all other githooks.
Marcin Kuzminski <marcin@python-works.com>
parents:
2407
diff
changeset
|
482 os.chmod(_hook_file, 0755) |
2404
a3efdd61a21f
Git Hooks are automatically installed in new repos
Marcin Kuzminski <marcin@python-works.com>
parents:
2327
diff
changeset
|
483 |
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
|
484 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
|
485 raise Exception('Undefined alias %s' % alias) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
486 |
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
487 def __rename_repo(self, old, new): |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
488 """ |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
489 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
|
490 |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
491 :param old: old name |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
492 :param new: new name |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
493 """ |
1976 | 494 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
|
495 |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
496 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
|
497 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
|
498 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
|
499 raise Exception( |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
500 '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
|
501 ) |
265
0e5455fda8fd
Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
502 shutil.move(old_path, new_path) |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
503 |
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
|
504 def __delete_repo(self, repo): |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
505 """ |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
506 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
|
507 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
|
508 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
|
509 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
|
510 |
787
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
511 :param repo: repo object |
4502ceec31be
docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents:
786
diff
changeset
|
512 """ |
1036
405b80e4ccd5
Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents:
1028
diff
changeset
|
513 rm_path = os.path.join(self.repos_path, repo.repo_name) |
1976 | 514 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
|
515 # 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
|
516 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
|
517 |
69b836e383df
don't disable .git directory for bare repos on deleting, ref #413
Marcin Kuzminski <marcin@python-works.com>
parents:
2321
diff
changeset
|
518 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
|
519 |
69b836e383df
don't disable .git directory for bare repos on deleting, ref #413
Marcin Kuzminski <marcin@python-works.com>
parents:
2321
diff
changeset
|
520 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
|
521 # 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
|
522 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
|
523 os.path.join(rm_path, 'rm__.%s' % alias)) |
1749
8ecc6b8229a5
commit less models
Marcin Kuzminski <marcin@python-works.com>
parents:
1729
diff
changeset
|
524 # disable repo |
1982
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
525 _d = 'rm__%s__%s' % (datetime.now().strftime('%Y%m%d_%H%M%S_%f'), |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
526 repo.repo_name) |
87f0800abc7b
#227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents:
1976
diff
changeset
|
527 shutil.move(rm_path, os.path.join(self.repos_path, _d)) |