annotate rhodecode/model/repo.py @ 2007:324ac367a4da beta

Added VCS into rhodecode core for faster and easier deployments of new versions
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 20 Feb 2012 23:00:54 +0200
parents 7dfcdf4c7dd2
children 14dffcfebb02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 787
diff changeset
3 rhodecode.model.repo
bb35ad076e2f docs updates
Marcin Kuzminski <marcin@python-works.com>
parents: 787
diff changeset
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/>.
786
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
25 import os
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
26 import shutil
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
27 import logging
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
28 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
29 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
30
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
31 from rhodecode.lib.vcs.backends import get_backend
1036
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
32
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
33 from rhodecode.lib import LazyProperty
1973
0a46e8f1b7aa fixed issue with logger crashing on mixed str and unicode
Marcin Kuzminski <marcin@python-works.com>
parents: 1972
diff changeset
34 from rhodecode.lib import safe_str, safe_unicode
1669
f522f4d3bf93 moved caching query to libs
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
35 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
36 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
37
786
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
38 from rhodecode.model import BaseModel
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
39 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
40 Statistics, UsersGroup, UsersGroupRepoToPerm, RhodeCodeUi, RepoGroup
786
2889a4446960 when new repo is created make user follow it automatically,
Marcin Kuzminski <marcin@python-works.com>
parents: 752
diff changeset
41
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
42
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 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
44
1271
aa7e45ad0cea Fixed permissions for users groups, group can have create repo permission now.
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
45
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
46 class RepoModel(BaseModel):
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
47
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
48 def __get_user(self, user):
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
49 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
50
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
51 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
52 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
53 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
54
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
55 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
56 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
57 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
58
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
59 def __get_repo(self, repository):
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
60 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
61 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
62
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
63 def __get_perm(self, permission):
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
64 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
65 callback=Permission.get_by_key)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
66
1036
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
67 @LazyProperty
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
68 def repos_path(self):
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
69 """
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
70 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
71 """
1017
ade3414a8b61 Fixed problems with repository creation
Marcin Kuzminski <marcin@python-works.com>
parents: 1015
diff changeset
72
1036
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
73 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
74 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
75
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
76 def get(self, repo_id, cache=False):
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
77 repo = self.sa.query(Repository)\
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
78 .filter(Repository.repo_id == repo_id)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
79
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
80 if cache:
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
81 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
82 "get_repo_%s" % repo_id))
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
83 return repo.scalar()
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
84
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
85 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
86 repo = self.sa.query(Repository)\
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
87 .filter(Repository.repo_name == repo_name)
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
88
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
89 if cache:
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
90 repo = repo.options(FromCache("sql_cache_short",
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
91 "get_repo_%s" % repo_name))
752
89b9037d68b7 fixed Example celery config to ampq,
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
92 return repo.scalar()
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 708
diff changeset
93
298
15e96b5a2685 autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents: 296
diff changeset
94 def get_users_js(self):
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
95
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
96 users = self.sa.query(User).filter(User.active == True).all()
298
15e96b5a2685 autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents: 296
diff changeset
97 u_tmpl = '''{id:%s, fname:"%s", lname:"%s", nname:"%s"},'''
1013
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
98 users_array = '[%s]' % '\n'.join([u_tmpl % (u.user_id, u.name,
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
99 u.lastname, u.username)
298
15e96b5a2685 autocomplete for repository managment of users
Marcin Kuzminski <marcin@python-works.com>
parents: 296
diff changeset
100 for u in users])
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
101 return users_array
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
102
1013
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
103 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
104 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
105 .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
106
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
107 g_tmpl = '''{id:%s, grname:"%s",grmembers:"%s"},'''
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
108
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
109 users_groups_array = '[%s]' % '\n'.join([g_tmpl % \
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
110 (gr.users_group_id, gr.users_group_name,
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
111 len(gr.members))
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
112 for gr in users_groups])
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
113 return users_groups_array
d2a840b29858 #56 hacking on forms, and model for users groups
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
114
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
115 def _get_defaults(self, repo_name):
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
116 """
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
117 Get's information about repository, and returns a dict for
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
118 usage in forms
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
119
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
120 :param repo_name:
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
121 """
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
122
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
123 repo_info = Repository.get_by_repo_name(repo_name)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
124
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
125 if repo_info is None:
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
126 return None
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
127
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
128 defaults = repo_info.get_dict()
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
129 group, repo_name = repo_info.groups_and_repo
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
130 defaults['repo_name'] = repo_name
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
131 defaults['repo_group'] = getattr(group[-1] if group else None,
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
132 'group_id', None)
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
133
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
134 # fill owner
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
135 if repo_info.user:
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
136 defaults.update({'user': repo_info.user.username})
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
137 else:
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
138 replacement_user = User.query().filter(User.admin ==
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
139 True).first().username
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
140 defaults.update({'user': replacement_user})
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
141
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
142 # fill repository users
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
143 for p in repo_info.repo_to_perm:
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
144 defaults.update({'u_perm_%s' % p.user.username:
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
145 p.permission.permission_name})
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
146
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
147 # fill repository groups
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
148 for p in repo_info.users_group_to_perm:
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
149 defaults.update({'g_perm_%s' % p.users_group.users_group_name:
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
150 p.permission.permission_name})
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
151
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
152 return defaults
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
153
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
154 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
155 try:
822
d5a71348ee4d small code fixes to repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 811
diff changeset
156 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
157
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
158 # update permissions
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
159 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
160 if member_type == 'user':
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
161 # this updates existing one
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
162 RepoModel().grant_user_permission(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
163 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
164 )
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
165 else:
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
166 RepoModel().grant_users_group_permission(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
167 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
168 )
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
169 # set new permissions
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
170 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
171 if member_type == 'user':
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
172 RepoModel().grant_user_permission(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
173 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
174 )
1014
6fdc3ff65fce #56 added assignments of users groups into repository
Marcin Kuzminski <marcin@python-works.com>
parents: 1013
diff changeset
175 else:
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
176 RepoModel().grant_users_group_permission(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
177 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
178 )
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
179
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
180 # 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
181 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
182 if k == 'user':
1530
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1517
diff changeset
183 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
184 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
185 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
186 elif k == 'repo_group':
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
187 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
188
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
189 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
190 setattr(cur_repo, k, v)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
191
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
192 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
193 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
194
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
195 self.sa.add(cur_repo)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
196
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
197 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
198 # 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
199 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
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 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
202 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
203 log.error(traceback.format_exc())
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
204 raise
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
205
530
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
206 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
207 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
208
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
209 try:
530
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
210 if fork:
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
211 fork_parent_id = form_data['fork_parent_id']
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
212
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
213 # 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
214 # 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
215 # with name and path of group
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
216 repo_name = form_data['repo_name']
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
217 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
218
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
219 new_repo = Repository()
1075
f726a939d2d4 Enable statistics are disabled by default now
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
220 new_repo.enable_statistics = False
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
221
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
222 for k, v in form_data.items():
530
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
223 if k == 'repo_name':
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
224 v = repo_name_full
1350
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
225 if k == 'repo_group':
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
226 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
227 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
228 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
229
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
230 setattr(new_repo, k, v)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
231
530
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
232 if fork:
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
233 parent_repo = Repository.get(fork_parent_id)
530
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
234 new_repo.fork = parent_repo
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
235
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
236 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
237 self.sa.add(new_repo)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
238
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
239 def _create_default_perms():
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
240 # create default permission
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
241 repo_to_perm = UserRepoToPerm()
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
242 default = 'repository.read'
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
243 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
244 if p.permission.permission_name.startswith('repository.'):
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
245 default = p.permission.permission_name
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
246 break
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
247
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
248 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
249
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
250 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
251 .filter(Permission.permission_name == default_perm)\
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
252 .one().permission_id
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
253
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
254 repo_to_perm.repository = new_repo
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
255 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
256
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
257 self.sa.add(repo_to_perm)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
258
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
259 if fork:
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
260 if form_data.get('copy_permissions'):
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
261 repo = Repository.get(fork_parent_id)
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
262 user_perms = UserRepoToPerm.query()\
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
263 .filter(UserRepoToPerm.repository == repo).all()
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
264 group_perms = UsersGroupRepoToPerm.query()\
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
265 .filter(UsersGroupRepoToPerm.repository == repo).all()
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
266
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
267 for perm in user_perms:
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
268 UserRepoToPerm.create(perm.user, new_repo,
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
269 perm.permission)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
270
1729
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
271 for perm in group_perms:
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
272 UsersGroupRepoToPerm.create(perm.users_group, new_repo,
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
273 perm.permission)
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
274 else:
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
275 _create_default_perms()
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
276 else:
da8ee2ef7f6d implements #236 forking copy permission option
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
277 _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
278
f42ee60e673b fixed issue with db transaction when filesystem creation of repository failed
Marcin Kuzminski <marcin@python-works.com>
parents: 1020
diff changeset
279 if not just_db:
1112
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
280 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
281 form_data['repo_group'],
1112
6d0a7284949d #109, added optional clone uri when creating repo.
Marcin Kuzminski <marcin@python-works.com>
parents: 1075
diff changeset
282 form_data['clone_uri'])
1028
f42ee60e673b fixed issue with db transaction when filesystem creation of repository failed
Marcin Kuzminski <marcin@python-works.com>
parents: 1020
diff changeset
283
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
284 # 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
285 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
286 cur_user.user_id)
1972
27abf546aa8a #348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
287 log_create_repository(new_repo.get_dict(),
27abf546aa8a #348 added post-create repository hook
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
288 created_by=cur_user.username)
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
289 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
290 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
291 log.error(traceback.format_exc())
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
292 raise
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
293
530
a08f610e545e Implemented server side forks
Marcin Kuzminski <marcin@python-works.com>
parents: 417
diff changeset
294 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
295 """
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
296 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
297
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
298 :param form_data:
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
299 :param cur_user:
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
300 """
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
301 from rhodecode.lib.celerylib import tasks, run_task
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
302 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
303
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
304 def delete(self, repo):
2003
7dfcdf4c7dd2 implements #361 API method for deleting repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1982
diff changeset
305 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
306 try:
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
307 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
308 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
309 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
310 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
311 raise
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
312
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
313 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
314 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
315 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
316 if found
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
317
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
318 :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
319 :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
320 :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
321 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
322 user = self.__get_user(user)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
323 repo = self.__get_repo(repo)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
324 permission = self.__get_perm(perm)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
325
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
326 # 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
327 obj = self.sa.query(UserRepoToPerm)\
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
328 .filter(UserRepoToPerm.user == user)\
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
329 .filter(UserRepoToPerm.repository == repo)\
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
330 .scalar()
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
331 if obj is None:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
332 # create new !
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
333 obj = UserRepoToPerm()
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
334 obj.repository = repo
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
335 obj.user = user
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
336 obj.permission = permission
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
337 self.sa.add(obj)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
338
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
339 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
340 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
341 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
342
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
343 :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
344 :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
345 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
346 user = self.__get_user(user)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
347 repo = self.__get_repo(repo)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
348
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
349 obj = self.sa.query(UserRepoToPerm)\
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
350 .filter(UserRepoToPerm.repository == repo)\
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
351 .filter(UserRepoToPerm.user == user)\
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
352 .one()
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
353 self.sa.delete(obj)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
354
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
355 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
356 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
357 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
358 existing one if found
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
359
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
360 :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
361 :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
362 or users group name
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
363 :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
364 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
365 repo = self.__get_repo(repo)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
366 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
367 permission = self.__get_perm(perm)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
368
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
369 # 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
370 obj = self.sa.query(UsersGroupRepoToPerm)\
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
371 .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
372 .filter(UsersGroupRepoToPerm.repository == repo)\
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
373 .scalar()
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 if obj is None:
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
376 # create new
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
377 obj = UsersGroupRepoToPerm()
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 obj.repository = repo
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
380 obj.users_group = group_name
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
381 obj.permission = permission
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
382 self.sa.add(obj)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
383
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
384 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
385 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
386 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
387
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
388 :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
389 :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
390 or users group name
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
391 """
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
392 repo = self.__get_repo(repo)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
393 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
394
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
395 obj = self.sa.query(UsersGroupRepoToPerm)\
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
396 .filter(UsersGroupRepoToPerm.repository == repo)\
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
397 .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
398 .one()
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
399 self.sa.delete(obj)
1015
65129c332d37 #56 added ajax removal of users groups,
Marcin Kuzminski <marcin@python-works.com>
parents: 1014
diff changeset
400
708
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
401 def delete_stats(self, repo_name):
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
402 """
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
403 removes stats for given repo
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1749
diff changeset
404
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
405 :param repo_name:
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
406 """
708
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
407 try:
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
408 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
409 .filter(Statistics.repository ==
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
410 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
411 .one()
1713
54687aa00724 Tests updates, Session refactoring
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
412 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
413 except:
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
414 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
415 raise
b9bbc0d6e9f3 added cache reset, stats reset, and delete into repository settings in admin.
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
416
1350
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
417 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
418 """
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
419 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
420 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
421 group location
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1119
diff changeset
422
787
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
423 :param repo_name:
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
424 :param alias:
1350
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
425 :param parent_id:
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
426 :param clone_uri:
787
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
427 """
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
428 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
429
1350
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
430 if new_parent_id:
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
431 paths = RepoGroup.get(new_parent_id)\
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1713
diff changeset
432 .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
433 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
434 else:
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
435 new_parent_path = ''
eb489bf9d7c7 #47 fixed group aware on adding new repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1323
diff changeset
436
1973
0a46e8f1b7aa fixed issue with logger crashing on mixed str and unicode
Marcin Kuzminski <marcin@python-works.com>
parents: 1972
diff changeset
437 # 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
438 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
439 [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
440
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
441 # 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
442 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
443 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
444
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
445 # 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
446 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
447 raise Exception('This path %s is a valid group' % repo_path)
1594
9dae92a65e40 fixes #288
Marcin Kuzminski <marcin@python-works.com>
parents: 1550
diff changeset
448
1973
0a46e8f1b7aa fixed issue with logger crashing on mixed str and unicode
Marcin Kuzminski <marcin@python-works.com>
parents: 1972
diff changeset
449 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
450 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
451 )
0a46e8f1b7aa fixed issue with logger crashing on mixed str and unicode
Marcin Kuzminski <marcin@python-works.com>
parents: 1972
diff changeset
452 )
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
453 backend = get_backend(alias)
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
454
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 backend(repo_path, create=True, src_url=clone_uri)
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
456
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
457 def __rename_repo(self, old, new):
787
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
458 """
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
459 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
460
787
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
461 :param old: old name
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
462 :param new: new name
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
463 """
1976
Marcin Kuzminski <marcin@python-works.com>
parents: 1973
diff changeset
464 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
465
1036
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
466 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
467 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
468 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
469 raise Exception(
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
470 '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
471 )
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
472 shutil.move(old_path, new_path)
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
473
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
474 def __delete_repo(self, repo):
787
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
475 """
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
476 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
477 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
478 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
479 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
480
787
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
481 :param repo: repo object
4502ceec31be docs update for repo model
Marcin Kuzminski <marcin@python-works.com>
parents: 786
diff changeset
482 """
1036
405b80e4ccd5 Major refactoring, removed when possible calls to app globals.
Marcin Kuzminski <marcin@python-works.com>
parents: 1028
diff changeset
483 rm_path = os.path.join(self.repos_path, repo.repo_name)
1976
Marcin Kuzminski <marcin@python-works.com>
parents: 1973
diff changeset
484 log.info("Removing %s" % (rm_path))
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
485 # disable hg/git
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
486 alias = repo.repo_type
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
487 shutil.move(os.path.join(rm_path, '.%s' % alias),
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
488 os.path.join(rm_path, 'rm__.%s' % alias))
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1729
diff changeset
489 # disable repo
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
490 _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
491 repo.repo_name)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
492 shutil.move(rm_path, os.path.join(self.repos_path, _d))