Show More
@@ -37,7 +37,7 b' from rhodecode.model import meta' | |||
|
37 | 37 | from rhodecode.model.user import UserModel |
|
38 | 38 | from rhodecode.model.repo import RepoModel |
|
39 | 39 | from rhodecode.model.users_group import UsersGroupModel |
|
40 | from rhodecode.model.db import User | |
|
40 | from rhodecode.model.db import User, UsersGroup | |
|
41 | 41 | from rhodecode import BACKENDS |
|
42 | 42 | |
|
43 | 43 | from webhelpers.pylonslib.secure_form import authentication_token |
@@ -238,7 +238,8 b' def ValidForkType(old_data):' | |||
|
238 | 238 | return _ValidForkType |
|
239 | 239 | |
|
240 | 240 | class ValidPerms(formencode.validators.FancyValidator): |
|
241 |
messages = {'perm_new_ |
|
|
241 | messages = {'perm_new_member_name':_('This username or users group name' | |
|
242 | ' is not valid')} | |
|
242 | 243 | |
|
243 | 244 | def to_python(self, value, state): |
|
244 | 245 | perms_update = [] |
@@ -246,32 +247,42 b' class ValidPerms(formencode.validators.F' | |||
|
246 | 247 | #build a list of permission to update and new permission to create |
|
247 | 248 | for k, v in value.items(): |
|
248 | 249 | if k.startswith('perm_'): |
|
249 |
if |
|
|
250 | new_perm = value.get('perm_new_user', False) | |
|
251 |
new_ |
|
|
252 | if new_user and new_perm: | |
|
253 | if (new_user, new_perm) not in perms_new: | |
|
254 | perms_new.append((new_user, new_perm)) | |
|
250 | if k.startswith('perm_new_member'): | |
|
251 | #means new added member to permissions | |
|
252 | new_perm = value.get('perm_new_member', False) | |
|
253 | new_member = value.get('perm_new_member_name', False) | |
|
254 | new_type = value.get('perm_new_member_type') | |
|
255 | ||
|
256 | if new_member and new_perm: | |
|
257 | if (new_member, new_perm) not in perms_new: | |
|
258 | perms_new.append((new_member, new_perm, new_type)) | |
|
255 | 259 | else: |
|
256 | 260 | usr = k[5:] |
|
261 | t = 'user' | |
|
257 | 262 | if usr == 'default': |
|
258 | 263 | if value['private']: |
|
259 | 264 | #set none for default when updating to private repo |
|
260 | 265 | v = 'repository.none' |
|
261 | perms_update.append((usr, v)) | |
|
266 | perms_update.append((usr, v, t)) | |
|
262 | 267 | value['perms_updates'] = perms_update |
|
263 | 268 | value['perms_new'] = perms_new |
|
264 | 269 | sa = meta.Session |
|
265 | for k, v in perms_new: | |
|
270 | for k, v, t in perms_new: | |
|
266 | 271 | try: |
|
267 | self.user_db = sa.query(User)\ | |
|
268 |
. |
|
|
269 |
.filter(User. |
|
|
272 | if t is 'user': | |
|
273 | self.user_db = sa.query(User)\ | |
|
274 | .filter(User.active == True)\ | |
|
275 | .filter(User.username == k).one() | |
|
276 | if t is 'users_group': | |
|
277 | self.user_db = sa.query(UsersGroup)\ | |
|
278 | .filter(UsersGroup.users_group_active == True)\ | |
|
279 | .filter(UsersGroup.users_group_name == k).one() | |
|
280 | ||
|
270 | 281 | except Exception: |
|
271 |
msg = self.message('perm_new_ |
|
|
282 | msg = self.message('perm_new_member_name', | |
|
272 | 283 | state=State_obj) |
|
273 | 284 | raise formencode.Invalid(msg, value, state, |
|
274 |
error_dict={'perm_new_ |
|
|
285 | error_dict={'perm_new_member_name':msg}) | |
|
275 | 286 | return value |
|
276 | 287 | |
|
277 | 288 | class ValidSettings(formencode.validators.FancyValidator): |
@@ -30,12 +30,10 b' import logging' | |||
|
30 | 30 | import traceback |
|
31 | 31 | from datetime import datetime |
|
32 | 32 | |
|
33 | from pylons import app_globals as g | |
|
34 | ||
|
35 | 33 | from rhodecode.model import BaseModel |
|
36 | 34 | from rhodecode.model.caching_query import FromCache |
|
37 | 35 | from rhodecode.model.db import Repository, RepoToPerm, User, Permission, \ |
|
38 | Statistics | |
|
36 | Statistics, UsersGroup | |
|
39 | 37 | from rhodecode.model.user import UserModel |
|
40 | 38 | |
|
41 | 39 | from vcs.backends import get_backend |
@@ -44,6 +42,24 b' log = logging.getLogger(__name__)' | |||
|
44 | 42 | |
|
45 | 43 | class RepoModel(BaseModel): |
|
46 | 44 | |
|
45 | def __init__(self, sa=None): | |
|
46 | try: | |
|
47 | from pylons import app_globals | |
|
48 | self._base_path = app_globals.base_path | |
|
49 | except: | |
|
50 | self._base_path = None | |
|
51 | ||
|
52 | @property | |
|
53 | def base_path(): | |
|
54 | if self._base_path is None: | |
|
55 | raise Exception('Base Path is empty, try set this after' | |
|
56 | 'class initialization when not having ' | |
|
57 | 'app_globals available') | |
|
58 | return self._base_path | |
|
59 | ||
|
60 | super(RepoModel, self).__init__() | |
|
61 | ||
|
62 | ||
|
47 | 63 | def get(self, repo_id, cache=False): |
|
48 | 64 | repo = self.sa.query(Repository)\ |
|
49 | 65 | .filter(Repository.repo_id == repo_id) |
@@ -67,19 +83,31 b' class RepoModel(BaseModel):' | |||
|
67 | 83 | |
|
68 | 84 | users = self.sa.query(User).filter(User.active == True).all() |
|
69 | 85 | u_tmpl = '''{id:%s, fname:"%s", lname:"%s", nname:"%s"},''' |
|
70 |
users_array = '[%s] |
|
|
86 | users_array = '[%s]' % '\n'.join([u_tmpl % (u.user_id, u.name, | |
|
71 | 87 | u.lastname, u.username) |
|
72 | 88 | for u in users]) |
|
73 | 89 | return users_array |
|
74 | 90 | |
|
75 | 91 | |
|
92 | def get_users_groups_js(self): | |
|
93 | users_groups = self.sa.query(UsersGroup)\ | |
|
94 | .filter(UsersGroup.users_group_active == True).all() | |
|
95 | ||
|
96 | g_tmpl = '''{id:%s, grname:"%s",grmembers:"%s"},''' | |
|
97 | ||
|
98 | users_groups_array = '[%s]' % '\n'.join([g_tmpl % \ | |
|
99 | (gr.users_group_id, gr.users_group_name, | |
|
100 | len(gr.members)) | |
|
101 | for gr in users_groups]) | |
|
102 | return users_groups_array | |
|
103 | ||
|
76 | 104 | def update(self, repo_name, form_data): |
|
77 | 105 | try: |
|
78 | 106 | cur_repo = self.get_by_repo_name(repo_name, cache=False) |
|
79 | 107 | user_model = UserModel(self.sa) |
|
80 | 108 | |
|
81 | 109 | #update permissions |
|
82 | for username, perm in form_data['perms_updates']: | |
|
110 | for username, perm, member_type in form_data['perms_updates']: | |
|
83 | 111 | r2p = self.sa.query(RepoToPerm)\ |
|
84 | 112 | .filter(RepoToPerm.user == user_model.get_by_username(username))\ |
|
85 | 113 | .filter(RepoToPerm.repository == cur_repo)\ |
@@ -91,7 +119,7 b' class RepoModel(BaseModel):' | |||
|
91 | 119 | self.sa.add(r2p) |
|
92 | 120 | |
|
93 | 121 | #set new permissions |
|
94 | for username, perm in form_data['perms_new']: | |
|
122 | for username, perm, member_type in form_data['perms_new']: | |
|
95 | 123 | r2p = RepoToPerm() |
|
96 | 124 | r2p.repository = cur_repo |
|
97 | 125 | r2p.user = user_model.get_by_username(username, cache=False) |
@@ -223,8 +251,8 b' class RepoModel(BaseModel):' | |||
|
223 | 251 | :param alias: |
|
224 | 252 | """ |
|
225 | 253 | from rhodecode.lib.utils import check_repo |
|
226 |
repo_path = os.path.join( |
|
|
227 |
if check_repo(repo_name, |
|
|
254 | repo_path = os.path.join(self.base_path, repo_name) | |
|
255 | if check_repo(repo_name, self.base_path): | |
|
228 | 256 | log.info('creating repo %s in %s', repo_name, repo_path) |
|
229 | 257 | backend = get_backend(alias) |
|
230 | 258 | backend(repo_path, create=True) |
@@ -237,8 +265,8 b' class RepoModel(BaseModel):' | |||
|
237 | 265 | """ |
|
238 | 266 | log.info('renaming repo from %s to %s', old, new) |
|
239 | 267 | |
|
240 |
old_path = os.path.join( |
|
|
241 |
new_path = os.path.join( |
|
|
268 | old_path = os.path.join(self.base_path, old) | |
|
269 | new_path = os.path.join(self.base_path, new) | |
|
242 | 270 | if os.path.isdir(new_path): |
|
243 | 271 | raise Exception('Was trying to rename to already existing dir %s', |
|
244 | 272 | new_path) |
@@ -252,12 +280,12 b' class RepoModel(BaseModel):' | |||
|
252 | 280 | by reverting the renames on this repository |
|
253 | 281 | :param repo: repo object |
|
254 | 282 | """ |
|
255 |
rm_path = os.path.join( |
|
|
283 | rm_path = os.path.join(self.base_path, repo.repo_name) | |
|
256 | 284 | log.info("Removing %s", rm_path) |
|
257 | 285 | #disable hg/git |
|
258 | 286 | alias = repo.repo_type |
|
259 | 287 | shutil.move(os.path.join(rm_path, '.%s' % alias), |
|
260 | 288 | os.path.join(rm_path, 'rm__.%s' % alias)) |
|
261 | 289 | #disable repo |
|
262 |
shutil.move(rm_path, os.path.join( |
|
|
290 | shutil.move(rm_path, os.path.join(self.base_path, 'rm__%s__%s' \ | |
|
263 | 291 | % (datetime.today(), repo.repo_name))) |
General Comments 0
You need to be logged in to leave comments.
Login now