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