annotate rhodecode/model/repo.py @ 2031:82a88013a3fd

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