Show More
@@ -68,6 +68,15 b' def make_map(config):' | |||||
68 | return is_valid_repos_group(repos_group_name, config['base_path'], |
|
68 | return is_valid_repos_group(repos_group_name, config['base_path'], | |
69 | skip_path_check=True) |
|
69 | skip_path_check=True) | |
70 |
|
70 | |||
|
71 | def check_user_group(environ, match_dict): | |||
|
72 | """ | |||
|
73 | check for valid user group for proper 404 handling | |||
|
74 | ||||
|
75 | :param environ: | |||
|
76 | :param match_dict: | |||
|
77 | """ | |||
|
78 | return True | |||
|
79 | ||||
71 | def check_int(environ, match_dict): |
|
80 | def check_int(environ, match_dict): | |
72 | return match_dict.get('id').isdigit() |
|
81 | return match_dict.get('id').isdigit() | |
73 |
|
82 | |||
@@ -266,7 +275,8 b' def make_map(config):' | |||||
266 | m.connect("delete_users_group", "/users_groups/{id}", |
|
275 | m.connect("delete_users_group", "/users_groups/{id}", | |
267 | action="delete", conditions=dict(method=["DELETE"])) |
|
276 | action="delete", conditions=dict(method=["DELETE"])) | |
268 | m.connect("edit_users_group", "/users_groups/{id}/edit", |
|
277 | m.connect("edit_users_group", "/users_groups/{id}/edit", | |
269 |
action="edit", conditions=dict(method=["GET"]) |
|
278 | action="edit", conditions=dict(method=["GET"]), | |
|
279 | function=check_user_group) | |||
270 | m.connect("formatted_edit_users_group", |
|
280 | m.connect("formatted_edit_users_group", | |
271 | "/users_groups/{id}.{format}/edit", |
|
281 | "/users_groups/{id}.{format}/edit", | |
272 | action="edit", conditions=dict(method=["GET"])) |
|
282 | action="edit", conditions=dict(method=["GET"])) |
@@ -55,15 +55,19 b' class PermissionsController(BaseControll' | |||||
55 | def __before__(self): |
|
55 | def __before__(self): | |
56 | super(PermissionsController, self).__before__() |
|
56 | super(PermissionsController, self).__before__() | |
57 |
|
57 | |||
58 |
|
|
58 | c.repo_perms_choices = [('repository.none', _('None'),), | |
59 | ('repository.read', _('Read'),), |
|
59 | ('repository.read', _('Read'),), | |
60 | ('repository.write', _('Write'),), |
|
60 | ('repository.write', _('Write'),), | |
61 | ('repository.admin', _('Admin'),)] |
|
61 | ('repository.admin', _('Admin'),)] | |
62 |
|
|
62 | c.group_perms_choices = [('group.none', _('None'),), | |
63 |
|
|
63 | ('group.read', _('Read'),), | |
64 |
|
|
64 | ('group.write', _('Write'),), | |
65 |
|
|
65 | ('group.admin', _('Admin'),)] | |
66 | self.register_choices = [ |
|
66 | c.user_group_perms_choices = [('usergroup.none', _('None'),), | |
|
67 | ('usergroup.read', _('Read'),), | |||
|
68 | ('usergroup.write', _('Write'),), | |||
|
69 | ('usergroup.admin', _('Admin'),)] | |||
|
70 | c.register_choices = [ | |||
67 | ('hg.register.none', |
|
71 | ('hg.register.none', | |
68 | _('Disabled')), |
|
72 | _('Disabled')), | |
69 | ('hg.register.manual_activate', |
|
73 | ('hg.register.manual_activate', | |
@@ -71,18 +75,17 b' class PermissionsController(BaseControll' | |||||
71 | ('hg.register.auto_activate', |
|
75 | ('hg.register.auto_activate', | |
72 | _('Allowed with automatic account activation')), ] |
|
76 | _('Allowed with automatic account activation')), ] | |
73 |
|
77 | |||
74 |
|
|
78 | c.repo_create_choices = [('hg.create.none', _('Disabled')), | |
75 | ('hg.create.repository', _('Enabled'))] |
|
79 | ('hg.create.repository', _('Enabled'))] | |
76 |
|
80 | |||
77 |
|
|
81 | c.user_group_create_choices = [('hg.usergroup.create.false', _('Disabled')), | |
78 |
('hg. |
|
82 | ('hg.usergroup.create.true', _('Enabled'))] | |
79 |
|
83 | |||
80 | # set the global template variables |
|
84 | c.repo_group_create_choices = [('hg.repogroup.create.false', _('Disabled')), | |
81 | c.repo_perms_choices = self.repo_perms_choices |
|
85 | ('hg.repogroup.create.true', _('Enabled'))] | |
82 | c.group_perms_choices = self.group_perms_choices |
|
86 | ||
83 | c.register_choices = self.register_choices |
|
87 | c.fork_choices = [('hg.fork.none', _('Disabled')), | |
84 | c.create_choices = self.create_choices |
|
88 | ('hg.fork.repository', _('Enabled'))] | |
85 | c.fork_choices = self.fork_choices |
|
|||
86 |
|
89 | |||
87 | def index(self, format='html'): |
|
90 | def index(self, format='html'): | |
88 | """GET /permissions: All items in the collection""" |
|
91 | """GET /permissions: All items in the collection""" | |
@@ -105,23 +108,25 b' class PermissionsController(BaseControll' | |||||
105 | # method='put') |
|
108 | # method='put') | |
106 | # url('permission', id=ID) |
|
109 | # url('permission', id=ID) | |
107 | if id == 'default': |
|
110 | if id == 'default': | |
108 |
c.user = default_user = User.get_ |
|
111 | c.user = default_user = User.get_default_user() | |
109 | c.perm_user = AuthUser(user_id=default_user.user_id) |
|
112 | c.perm_user = AuthUser(user_id=default_user.user_id) | |
110 | c.user_ip_map = UserIpMap.query()\ |
|
113 | c.user_ip_map = UserIpMap.query()\ | |
111 | .filter(UserIpMap.user == default_user).all() |
|
114 | .filter(UserIpMap.user == default_user).all() | |
112 | permission_model = PermissionModel() |
|
|||
113 |
|
115 | |||
114 | _form = DefaultPermissionsForm( |
|
116 | _form = DefaultPermissionsForm( | |
115 |
[x[0] for x in |
|
117 | [x[0] for x in c.repo_perms_choices], | |
116 |
[x[0] for x in |
|
118 | [x[0] for x in c.group_perms_choices], | |
117 |
[x[0] for x in |
|
119 | [x[0] for x in c.user_group_perms_choices], | |
118 |
[x[0] for x in |
|
120 | [x[0] for x in c.repo_create_choices], | |
119 |
[x[0] for x in |
|
121 | [x[0] for x in c.repo_group_create_choices], | |
|
122 | [x[0] for x in c.user_group_create_choices], | |||
|
123 | [x[0] for x in c.fork_choices], | |||
|
124 | [x[0] for x in c.register_choices])() | |||
120 |
|
125 | |||
121 | try: |
|
126 | try: | |
122 | form_result = _form.to_python(dict(request.POST)) |
|
127 | form_result = _form.to_python(dict(request.POST)) | |
123 | form_result.update({'perm_user_name': id}) |
|
128 | form_result.update({'perm_user_name': id}) | |
124 |
|
|
129 | PermissionModel().update(form_result) | |
125 | Session().commit() |
|
130 | Session().commit() | |
126 | h.flash(_('Default permissions updated successfully'), |
|
131 | h.flash(_('Default permissions updated successfully'), | |
127 | category='success') |
|
132 | category='success') | |
@@ -162,24 +167,33 b' class PermissionsController(BaseControll' | |||||
162 |
|
167 | |||
163 | #this form can only edit default user permissions |
|
168 | #this form can only edit default user permissions | |
164 | if id == 'default': |
|
169 | if id == 'default': | |
165 |
c.user = |
|
170 | c.user = User.get_default_user() | |
166 |
defaults = {'anonymous': |
|
171 | defaults = {'anonymous': c.user.active} | |
167 |
c.perm_user = AuthUser |
|
172 | c.perm_user = c.user.AuthUser | |
168 | c.user_ip_map = UserIpMap.query()\ |
|
173 | c.user_ip_map = UserIpMap.query()\ | |
169 |
.filter(UserIpMap.user == |
|
174 | .filter(UserIpMap.user == c.user).all() | |
170 |
for p in |
|
175 | for p in c.user.user_perms: | |
171 | if p.permission.permission_name.startswith('repository.'): |
|
176 | if p.permission.permission_name.startswith('repository.'): | |
172 | defaults['default_repo_perm'] = p.permission.permission_name |
|
177 | defaults['default_repo_perm'] = p.permission.permission_name | |
173 |
|
178 | |||
174 | if p.permission.permission_name.startswith('group.'): |
|
179 | if p.permission.permission_name.startswith('group.'): | |
175 | defaults['default_group_perm'] = p.permission.permission_name |
|
180 | defaults['default_group_perm'] = p.permission.permission_name | |
176 |
|
181 | |||
|
182 | if p.permission.permission_name.startswith('usergroup.'): | |||
|
183 | defaults['default_user_group_perm'] = p.permission.permission_name | |||
|
184 | ||||
|
185 | if p.permission.permission_name.startswith('hg.create.'): | |||
|
186 | defaults['default_repo_create'] = p.permission.permission_name | |||
|
187 | ||||
|
188 | if p.permission.permission_name.startswith('hg.repogroup.'): | |||
|
189 | defaults['default_repo_group_create'] = p.permission.permission_name | |||
|
190 | ||||
|
191 | if p.permission.permission_name.startswith('hg.usergroup.'): | |||
|
192 | defaults['default_user_group_create'] = p.permission.permission_name | |||
|
193 | ||||
177 | if p.permission.permission_name.startswith('hg.register.'): |
|
194 | if p.permission.permission_name.startswith('hg.register.'): | |
178 | defaults['default_register'] = p.permission.permission_name |
|
195 | defaults['default_register'] = p.permission.permission_name | |
179 |
|
196 | |||
180 | if p.permission.permission_name.startswith('hg.create.'): |
|
|||
181 | defaults['default_create'] = p.permission.permission_name |
|
|||
182 |
|
||||
183 | if p.permission.permission_name.startswith('hg.fork.'): |
|
197 | if p.permission.permission_name.startswith('hg.fork.'): | |
184 | defaults['default_fork'] = p.permission.permission_name |
|
198 | defaults['default_fork'] = p.permission.permission_name | |
185 |
|
199 |
@@ -98,7 +98,7 b' class ReposController(BaseRepoController' | |||||
98 | choices, c.landing_revs = ScmModel().get_repo_landing_revs(c.repo_info) |
|
98 | choices, c.landing_revs = ScmModel().get_repo_landing_revs(c.repo_info) | |
99 | c.landing_revs_choices = choices |
|
99 | c.landing_revs_choices = choices | |
100 |
|
100 | |||
101 |
c.default_user_id = User.get_ |
|
101 | c.default_user_id = User.get_default_user().user_id | |
102 | c.in_public_journal = UserFollowing.query()\ |
|
102 | c.in_public_journal = UserFollowing.query()\ | |
103 | .filter(UserFollowing.user_id == c.default_user_id)\ |
|
103 | .filter(UserFollowing.user_id == c.default_user_id)\ | |
104 | .filter(UserFollowing.follows_repository == c.repo_info).scalar() |
|
104 | .filter(UserFollowing.follows_repository == c.repo_info).scalar() | |
@@ -466,7 +466,7 b' class ReposController(BaseRepoController' | |||||
466 | if cur_token == token: |
|
466 | if cur_token == token: | |
467 | try: |
|
467 | try: | |
468 | repo_id = Repository.get_by_repo_name(repo_name).repo_id |
|
468 | repo_id = Repository.get_by_repo_name(repo_name).repo_id | |
469 |
user_id = User.get_ |
|
469 | user_id = User.get_default_user().user_id | |
470 | self.scm_model.toggle_following_repo(repo_id, user_id) |
|
470 | self.scm_model.toggle_following_repo(repo_id, user_id) | |
471 | h.flash(_('Updated repository visibility in public journal'), |
|
471 | h.flash(_('Updated repository visibility in public journal'), | |
472 | category='success') |
|
472 | category='success') |
@@ -77,7 +77,7 b' class ForksController(BaseRepoController' | |||||
77 | h.not_mapped_error(repo_name) |
|
77 | h.not_mapped_error(repo_name) | |
78 | return redirect(url('repos')) |
|
78 | return redirect(url('repos')) | |
79 |
|
79 | |||
80 |
c.default_user_id = User.get_ |
|
80 | c.default_user_id = User.get_default_user().user_id | |
81 | c.in_public_journal = UserFollowing.query()\ |
|
81 | c.in_public_journal = UserFollowing.query()\ | |
82 | .filter(UserFollowing.user_id == c.default_user_id)\ |
|
82 | .filter(UserFollowing.user_id == c.default_user_id)\ | |
83 | .filter(UserFollowing.follows_repository == c.repo_info).scalar() |
|
83 | .filter(UserFollowing.follows_repository == c.repo_info).scalar() |
@@ -126,7 +126,7 b' class LoginController(BaseController):' | |||||
126 | @HasPermissionAnyDecorator('hg.admin', 'hg.register.auto_activate', |
|
126 | @HasPermissionAnyDecorator('hg.admin', 'hg.register.auto_activate', | |
127 | 'hg.register.manual_activate') |
|
127 | 'hg.register.manual_activate') | |
128 | def register(self): |
|
128 | def register(self): | |
129 |
c.auto_active = 'hg.register.auto_activate' in User.get_ |
|
129 | c.auto_active = 'hg.register.auto_activate' in User.get_default_user()\ | |
130 | .AuthUser.permissions['global'] |
|
130 | .AuthUser.permissions['global'] | |
131 |
|
131 | |||
132 | if request.POST: |
|
132 | if request.POST: |
@@ -229,7 +229,7 b' def authenticate(username, password):' | |||||
229 | 'lastname': safe_unicode(get_ldap_attr('ldap_attr_lastname')), |
|
229 | 'lastname': safe_unicode(get_ldap_attr('ldap_attr_lastname')), | |
230 | 'email': get_ldap_attr('ldap_attr_email'), |
|
230 | 'email': get_ldap_attr('ldap_attr_email'), | |
231 | 'active': 'hg.register.auto_activate' in User\ |
|
231 | 'active': 'hg.register.auto_activate' in User\ | |
232 |
.get_ |
|
232 | .get_default_user().AuthUser.permissions['global'] | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | # don't store LDAP password since we don't need it. Override |
|
235 | # don't store LDAP password since we don't need it. Override | |
@@ -259,7 +259,7 b' def login_container_auth(username):' | |||||
259 | 'lastname': None, |
|
259 | 'lastname': None, | |
260 | 'email': None, |
|
260 | 'email': None, | |
261 | 'active': 'hg.register.auto_activate' in User\ |
|
261 | 'active': 'hg.register.auto_activate' in User\ | |
262 |
.get_ |
|
262 | .get_default_user().AuthUser.permissions['global'] | |
263 | } |
|
263 | } | |
264 | user = UserModel().create_for_container_auth(username, user_attrs) |
|
264 | user = UserModel().create_for_container_auth(username, user_attrs) | |
265 | if not user: |
|
265 | if not user: |
@@ -521,7 +521,7 b' class DbManage(object):' | |||||
521 | self.sa.add(setting) |
|
521 | self.sa.add(setting) | |
522 |
|
522 | |||
523 | def fixup_groups(self): |
|
523 | def fixup_groups(self): | |
524 |
def_usr = User.get_ |
|
524 | def_usr = User.get_default_user() | |
525 | for g in RepoGroup.query().all(): |
|
525 | for g in RepoGroup.query().all(): | |
526 | g.group_name = g.get_new_name(g.name) |
|
526 | g.group_name = g.get_new_name(g.name) | |
527 | self.sa.add(g) |
|
527 | self.sa.add(g) | |
@@ -688,13 +688,8 b' class DbManage(object):' | |||||
688 | """ |
|
688 | """ | |
689 | # module.(access|create|change|delete)_[name] |
|
689 | # module.(access|create|change|delete)_[name] | |
690 | # module.(none|read|write|admin) |
|
690 | # module.(none|read|write|admin) | |
691 |
|
691 | log.info('creating permissions') | ||
692 | for p in Permission.PERMS: |
|
692 | PermissionModel(self.sa).create_permissions() | |
693 | if not Permission.get_by_key(p[0]): |
|
|||
694 | new_perm = Permission() |
|
|||
695 | new_perm.permission_name = p[0] |
|
|||
696 | new_perm.permission_longname = p[0] |
|
|||
697 | self.sa.add(new_perm) |
|
|||
698 |
|
693 | |||
699 | def populate_default_permissions(self): |
|
694 | def populate_default_permissions(self): | |
700 | """ |
|
695 | """ |
@@ -58,6 +58,7 b' from rhodecode.model.meta import Session' | |||||
58 | from rhodecode.model.repos_group import ReposGroupModel |
|
58 | from rhodecode.model.repos_group import ReposGroupModel | |
59 | from rhodecode.lib.utils2 import safe_str, safe_unicode |
|
59 | from rhodecode.lib.utils2 import safe_str, safe_unicode | |
60 | from rhodecode.lib.vcs.utils.fakemod import create_module |
|
60 | from rhodecode.lib.vcs.utils.fakemod import create_module | |
|
61 | from rhodecode.model.users_group import UserGroupModel | |||
61 |
|
62 | |||
62 | log = logging.getLogger(__name__) |
|
63 | log = logging.getLogger(__name__) | |
63 |
|
64 | |||
@@ -100,6 +101,9 b' def repo_name_slug(value):' | |||||
100 | return slug |
|
101 | return slug | |
101 |
|
102 | |||
102 |
|
103 | |||
|
104 | #============================================================================== | |||
|
105 | # PERM DECORATOR HELPERS FOR EXTRACTING NAMES FOR PERM CHECKS | |||
|
106 | #============================================================================== | |||
103 | def get_repo_slug(request): |
|
107 | def get_repo_slug(request): | |
104 | _repo = request.environ['pylons.routes_dict'].get('repo_name') |
|
108 | _repo = request.environ['pylons.routes_dict'].get('repo_name') | |
105 | if _repo: |
|
109 | if _repo: | |
@@ -116,9 +120,15 b' def get_repos_group_slug(request):' | |||||
116 |
|
120 | |||
117 | def get_user_group_slug(request): |
|
121 | def get_user_group_slug(request): | |
118 | _group = request.environ['pylons.routes_dict'].get('id') |
|
122 | _group = request.environ['pylons.routes_dict'].get('id') | |
119 | _group = UserGroup.get(_group) |
|
123 | try: | |
120 | if _group: |
|
124 | _group = UserGroup.get(_group) | |
121 | _group = _group.users_group_name |
|
125 | if _group: | |
|
126 | _group = _group.users_group_name | |||
|
127 | except Exception: | |||
|
128 | log.debug(traceback.format_exc()) | |||
|
129 | #catch all failures here | |||
|
130 | pass | |||
|
131 | ||||
122 | return _group |
|
132 | return _group | |
123 |
|
133 | |||
124 |
|
134 |
@@ -637,6 +637,7 b' class UserGroup(Base, BaseModel):' | |||||
637 | members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined") |
|
637 | members = relationship('UserGroupMember', cascade="all, delete, delete-orphan", lazy="joined") | |
638 | users_group_to_perm = relationship('UserGroupToPerm', cascade='all') |
|
638 | users_group_to_perm = relationship('UserGroupToPerm', cascade='all') | |
639 | users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all') |
|
639 | users_group_repo_to_perm = relationship('UserGroupRepoToPerm', cascade='all') | |
|
640 | users_group_repo_group_to_perm = relationship('UserGroupRepoGroupToPerm', cascade='all') | |||
640 | user_user_group_to_perm = relationship('UserUserGroupToPerm ', cascade='all') |
|
641 | user_user_group_to_perm = relationship('UserUserGroupToPerm ', cascade='all') | |
641 | user = relationship('User') |
|
642 | user = relationship('User') | |
642 |
|
643 | |||
@@ -1426,6 +1427,12 b' class Permission(Base, BaseModel):' | |||||
1426 | ('usergroup.write', _('User group write access')), |
|
1427 | ('usergroup.write', _('User group write access')), | |
1427 | ('usergroup.admin', _('User group admin access')), |
|
1428 | ('usergroup.admin', _('User group admin access')), | |
1428 |
|
1429 | |||
|
1430 | ('hg.repogroup.create.false', _('Repository Group creation disabled')), | |||
|
1431 | ('hg.repogroup.create.true', _('Repository Group creation enabled')), | |||
|
1432 | ||||
|
1433 | ('hg.usergroup.create.false', _('User Group creation disabled')), | |||
|
1434 | ('hg.usergroup.create.true', _('User Group creation enabled')), | |||
|
1435 | ||||
1429 | ('hg.create.none', _('Repository creation disabled')), |
|
1436 | ('hg.create.none', _('Repository creation disabled')), | |
1430 | ('hg.create.repository', _('Repository creation enabled')), |
|
1437 | ('hg.create.repository', _('Repository creation enabled')), | |
1431 |
|
1438 | |||
@@ -1451,6 +1458,8 b' class Permission(Base, BaseModel):' | |||||
1451 | ] |
|
1458 | ] | |
1452 |
|
1459 | |||
1453 | # defines which permissions are more important higher the more important |
|
1460 | # defines which permissions are more important higher the more important | |
|
1461 | # Weight defines which permissions are more important. | |||
|
1462 | # The higher number the more important. | |||
1454 | PERM_WEIGHTS = { |
|
1463 | PERM_WEIGHTS = { | |
1455 | 'repository.none': 0, |
|
1464 | 'repository.none': 0, | |
1456 | 'repository.read': 1, |
|
1465 | 'repository.read': 1, | |
@@ -1466,6 +1475,11 b' class Permission(Base, BaseModel):' | |||||
1466 | 'usergroup.read': 1, |
|
1475 | 'usergroup.read': 1, | |
1467 | 'usergroup.write': 3, |
|
1476 | 'usergroup.write': 3, | |
1468 | 'usergroup.admin': 4, |
|
1477 | 'usergroup.admin': 4, | |
|
1478 | 'hg.repogroup.create.false': 0, | |||
|
1479 | 'hg.repogroup.create.true': 1, | |||
|
1480 | ||||
|
1481 | 'hg.usergroup.create.false': 0, | |||
|
1482 | 'hg.usergroup.create.true': 1, | |||
1469 |
|
1483 | |||
1470 | 'hg.fork.none': 0, |
|
1484 | 'hg.fork.none': 0, | |
1471 | 'hg.fork.repository': 1, |
|
1485 | 'hg.fork.repository': 1, |
@@ -311,7 +311,9 b' def ApplicationUiSettingsForm():' | |||||
311 |
|
311 | |||
312 |
|
312 | |||
313 | def DefaultPermissionsForm(repo_perms_choices, group_perms_choices, |
|
313 | def DefaultPermissionsForm(repo_perms_choices, group_perms_choices, | |
314 |
|
|
314 | user_group_perms_choices, create_choices, | |
|
315 | repo_group_create_choices, user_group_create_choices, | |||
|
316 | fork_choices, register_choices): | |||
315 | class _DefaultPermissionsForm(formencode.Schema): |
|
317 | class _DefaultPermissionsForm(formencode.Schema): | |
316 | allow_extra_fields = True |
|
318 | allow_extra_fields = True | |
317 | filter_extra_fields = True |
|
319 | filter_extra_fields = True | |
@@ -320,10 +322,14 b' def DefaultPermissionsForm(repo_perms_ch' | |||||
320 | anonymous = v.StringBoolean(if_missing=False) |
|
322 | anonymous = v.StringBoolean(if_missing=False) | |
321 | default_repo_perm = v.OneOf(repo_perms_choices) |
|
323 | default_repo_perm = v.OneOf(repo_perms_choices) | |
322 | default_group_perm = v.OneOf(group_perms_choices) |
|
324 | default_group_perm = v.OneOf(group_perms_choices) | |
323 |
default_ |
|
325 | default_user_group_perm = v.OneOf(user_group_perms_choices) | |
324 | default_create = v.OneOf(create_choices) |
|
326 | ||
|
327 | default_repo_create = v.OneOf(create_choices) | |||
|
328 | default_user_group_create = v.OneOf(user_group_create_choices) | |||
|
329 | #default_repo_group_create = v.OneOf(repo_group_create_choices) #not impl. yet | |||
325 | default_fork = v.OneOf(fork_choices) |
|
330 | default_fork = v.OneOf(fork_choices) | |
326 |
|
331 | |||
|
332 | default_register = v.OneOf(register_choices) | |||
327 | return _DefaultPermissionsForm |
|
333 | return _DefaultPermissionsForm | |
328 |
|
334 | |||
329 |
|
335 |
@@ -43,6 +43,17 b' class PermissionModel(BaseModel):' | |||||
43 |
|
43 | |||
44 | cls = Permission |
|
44 | cls = Permission | |
45 |
|
45 | |||
|
46 | def create_permissions(self): | |||
|
47 | """ | |||
|
48 | Create permissions for whole system | |||
|
49 | """ | |||
|
50 | for p in Permission.PERMS: | |||
|
51 | if not Permission.get_by_key(p[0]): | |||
|
52 | new_perm = Permission() | |||
|
53 | new_perm.permission_name = p[0] | |||
|
54 | new_perm.permission_longname = p[0] #translation err with p[1] | |||
|
55 | self.sa.add(new_perm) | |||
|
56 | ||||
46 | def create_default_permissions(self, user): |
|
57 | def create_default_permissions(self, user): | |
47 | """ |
|
58 | """ | |
48 | Creates only missing default permissions for user |
|
59 | Creates only missing default permissions for user | |
@@ -87,6 +98,7 b' class PermissionModel(BaseModel):' | |||||
87 |
|
98 | |||
88 | # stage 2 reset defaults and set them from form data |
|
99 | # stage 2 reset defaults and set them from form data | |
89 | def _make_new(usr, perm_name): |
|
100 | def _make_new(usr, perm_name): | |
|
101 | log.debug('Creating new permission:%s' % (perm_name)) | |||
90 | new = UserToPerm() |
|
102 | new = UserToPerm() | |
91 | new.user = usr |
|
103 | new.user = usr | |
92 | new.permission = Permission.get_by_key(perm_name) |
|
104 | new.permission = Permission.get_by_key(perm_name) | |
@@ -101,8 +113,11 b' class PermissionModel(BaseModel):' | |||||
101 | self.sa.delete(p) |
|
113 | self.sa.delete(p) | |
102 | #create fresh set of permissions |
|
114 | #create fresh set of permissions | |
103 | for def_perm_key in ['default_repo_perm', 'default_group_perm', |
|
115 | for def_perm_key in ['default_repo_perm', 'default_group_perm', | |
104 |
'default_ |
|
116 | 'default_user_group_perm', | |
105 |
'default_ |
|
117 | 'default_repo_create', | |
|
118 | #'default_repo_group_create', #not implemented yet | |||
|
119 | 'default_user_group_create', | |||
|
120 | 'default_fork', 'default_register']: | |||
106 | p = _make_new(perm_user, form_result[def_perm_key]) |
|
121 | p = _make_new(perm_user, form_result[def_perm_key]) | |
107 | self.sa.add(p) |
|
122 | self.sa.add(p) | |
108 |
|
123 |
@@ -63,7 +63,7 b' class RepoModel(BaseModel):' | |||||
63 | def _create_default_perms(self, repository, private): |
|
63 | def _create_default_perms(self, repository, private): | |
64 | # create default permission |
|
64 | # create default permission | |
65 | default = 'repository.read' |
|
65 | default = 'repository.read' | |
66 |
def_user = User.get_ |
|
66 | def_user = User.get_default_user() | |
67 | for p in def_user.user_perms: |
|
67 | for p in def_user.user_perms: | |
68 | if p.permission.permission_name.startswith('repository.'): |
|
68 | if p.permission.permission_name.startswith('repository.'): | |
69 | default = p.permission.permission_name |
|
69 | default = p.permission.permission_name |
@@ -62,7 +62,7 b' class ReposGroupModel(BaseModel):' | |||||
62 | def _create_default_perms(self, new_group): |
|
62 | def _create_default_perms(self, new_group): | |
63 | # create default permission |
|
63 | # create default permission | |
64 | default_perm = 'group.read' |
|
64 | default_perm = 'group.read' | |
65 |
def_user = User.get_ |
|
65 | def_user = User.get_default_user() | |
66 | for p in def_user.user_perms: |
|
66 | for p in def_user.user_perms: | |
67 | if p.permission.permission_name.startswith('group.'): |
|
67 | if p.permission.permission_name.startswith('group.'): | |
68 | default_perm = p.permission.permission_name |
|
68 | default_perm = p.permission.permission_name |
@@ -46,7 +46,7 b' class UserGroupModel(BaseModel):' | |||||
46 | def _create_default_perms(self, user_group): |
|
46 | def _create_default_perms(self, user_group): | |
47 | # create default permission |
|
47 | # create default permission | |
48 | default_perm = 'usergroup.read' |
|
48 | default_perm = 'usergroup.read' | |
49 |
def_user = User.get_ |
|
49 | def_user = User.get_default_user() | |
50 | for p in def_user.user_perms: |
|
50 | for p in def_user.user_perms: | |
51 | if p.permission.permission_name.startswith('usergroup.'): |
|
51 | if p.permission.permission_name.startswith('usergroup.'): | |
52 | default_perm = p.permission.permission_name |
|
52 | default_perm = p.permission.permission_name |
@@ -66,18 +66,32 b'' | |||||
66 | </div> |
|
66 | </div> | |
67 | <div class="field"> |
|
67 | <div class="field"> | |
68 | <div class="label"> |
|
68 | <div class="label"> | |
69 |
<label for="default_ |
|
69 | <label for="default_group_perm">${_('User group')}:</label> | |
70 | </div> |
|
70 | </div> | |
71 | <div class="select"> |
|
71 | <div class="select"> | |
72 |
${h.select('default_ |
|
72 | ${h.select('default_user_group_perm','',c.user_group_perms_choices)} | |
|
73 | ${h.checkbox('overwrite_default_user_group','true')} | |||
|
74 | <label for="overwrite_default_user_group"> | |||
|
75 | <span class="tooltip" | |||
|
76 | title="${h.tooltip(_('All default permissions on each user group will be reset to chosen permission, note that all custom default permission on repository groups will be lost'))}"> | |||
|
77 | ${_('Overwrite existing settings')}</span> </label> | |||
|
78 | ||||
73 | </div> |
|
79 | </div> | |
74 | </div> |
|
80 | </div> | |
75 | <div class="field"> |
|
81 | <div class="field"> | |
76 | <div class="label"> |
|
82 | <div class="label"> | |
77 | <label for="default_create">${_('Repository creation')}:</label> |
|
83 | <label for="default_repo_create">${_('Repository creation')}:</label> | |
78 | </div> |
|
84 | </div> | |
79 | <div class="select"> |
|
85 | <div class="select"> | |
80 | ${h.select('default_create','',c.create_choices)} |
|
86 | ${h.select('default_repo_create','',c.repo_create_choices)} | |
|
87 | </div> | |||
|
88 | </div> | |||
|
89 | <div class="field"> | |||
|
90 | <div class="label"> | |||
|
91 | <label for="default_user_group_create">${_('User group creation')}:</label> | |||
|
92 | </div> | |||
|
93 | <div class="select"> | |||
|
94 | ${h.select('default_user_group_create','',c.user_group_create_choices)} | |||
81 | </div> |
|
95 | </div> | |
82 | </div> |
|
96 | </div> | |
83 | <div class="field"> |
|
97 | <div class="field"> | |
@@ -88,6 +102,14 b'' | |||||
88 | ${h.select('default_fork','',c.fork_choices)} |
|
102 | ${h.select('default_fork','',c.fork_choices)} | |
89 | </div> |
|
103 | </div> | |
90 | </div> |
|
104 | </div> | |
|
105 | <div class="field"> | |||
|
106 | <div class="label"> | |||
|
107 | <label for="default_register">${_('Registration')}:</label> | |||
|
108 | </div> | |||
|
109 | <div class="select"> | |||
|
110 | ${h.select('default_register','',c.register_choices)} | |||
|
111 | </div> | |||
|
112 | </div> | |||
91 | <div class="buttons"> |
|
113 | <div class="buttons"> | |
92 | ${h.submit('save',_('Save'),class_="ui-btn large")} |
|
114 | ${h.submit('save',_('Save'),class_="ui-btn large")} | |
93 | ${h.reset('reset',_('Reset'),class_="ui-btn large")} |
|
115 | ${h.reset('reset',_('Reset'),class_="ui-btn large")} | |
@@ -104,7 +126,8 b'' | |||||
104 | </div> |
|
126 | </div> | |
105 |
|
127 | |||
106 | ## permissions overview |
|
128 | ## permissions overview | |
107 |
<% |
|
129 | <%namespace name="p" file="/base/perms_summary.html"/> | |
|
130 | ${p.perms_summary(c.perm_user.permissions)} | |||
108 |
|
131 | |||
109 | </div> |
|
132 | </div> | |
110 | <div class="box box-left" style="clear:left"> |
|
133 | <div class="box box-left" style="clear:left"> |
@@ -28,7 +28,9 b'' | |||||
28 | </ul> |
|
28 | </ul> | |
29 | </div> |
|
29 | </div> | |
30 | <!-- end box / title --> |
|
30 | <!-- end box / title --> | |
|
31 | ||||
31 | <div class="table"> |
|
32 | <div class="table"> | |
|
33 | %if c.users_groups_list: | |||
32 | <table class="table_disp"> |
|
34 | <table class="table_disp"> | |
33 | <tr class="header"> |
|
35 | <tr class="header"> | |
34 | <th class="left">${_('Group name')}</th> |
|
36 | <th class="left">${_('Group name')}</th> | |
@@ -55,6 +57,9 b'' | |||||
55 | </tr> |
|
57 | </tr> | |
56 | %endfor |
|
58 | %endfor | |
57 | </table> |
|
59 | </table> | |
|
60 | %else: | |||
|
61 | ${_('There are no user groups yet')} | |||
|
62 | %endif | |||
58 | </div> |
|
63 | </div> | |
59 | </div> |
|
64 | </div> | |
60 | </%def> |
|
65 | </%def> |
@@ -9,28 +9,32 b'' | |||||
9 | %else: |
|
9 | %else: | |
10 | <div id='tbl_list_wrap_${section}' class="yui-skin-sam"> |
|
10 | <div id='tbl_list_wrap_${section}' class="yui-skin-sam"> | |
11 | <table id="tbl_list_${section}"> |
|
11 | <table id="tbl_list_${section}"> | |
12 | <thead> |
|
|||
13 | <tr> |
|
|||
14 | <th class="left">${_('Name')}</th> |
|
|||
15 | <th class="left">${_('Permission')}</th> |
|
|||
16 | <th class="left">${_('Edit Permission')}</th> |
|
|||
17 | </thead> |
|
|||
18 | <tbody> |
|
|||
19 | %if section == 'global': |
|
12 | %if section == 'global': | |
|
13 | <thead> | |||
|
14 | <tr> | |||
|
15 | <th colspan="2" class="left">${_('Permission')}</th> | |||
|
16 | <th class="left">${_('Edit Permission')}</th> | |||
|
17 | </thead> | |||
|
18 | <tbody> | |||
20 | %for k in sorted(permissions[section], key=lambda s: s.lower()): |
|
19 | %for k in sorted(permissions[section], key=lambda s: s.lower()): | |
21 | <tr> |
|
20 | <tr> | |
22 | <td> |
|
21 | <td colspan="2"> | |
23 | ${h.get_permission_name(k)} |
|
22 | ${h.get_permission_name(k)} | |
24 | </td> |
|
23 | </td> | |
25 | <td> |
|
24 | <td> | |
26 | ${h.boolicon(k.split('.')[-1] != 'none')} |
|
|||
27 | </td> |
|
|||
28 | <td> |
|
|||
29 | <a href="${h.url('edit_permission', id='default')}">${_('edit')}</a> |
|
25 | <a href="${h.url('edit_permission', id='default')}">${_('edit')}</a> | |
30 | </td> |
|
26 | </td> | |
31 | </tr> |
|
27 | </tr> | |
32 | %endfor |
|
28 | %endfor | |
|
29 | </tbody> | |||
33 | %else: |
|
30 | %else: | |
|
31 | <thead> | |||
|
32 | <tr> | |||
|
33 | <th class="left">${_('Name')}</th> | |||
|
34 | <th class="left">${_('Permission')}</th> | |||
|
35 | <th class="left">${_('Edit Permission')}</th> | |||
|
36 | </thead> | |||
|
37 | <tbody> | |||
34 | %for k, section_perm in sorted(permissions[section].items(), key=lambda s: s[1]+s[0].lower()): |
|
38 | %for k, section_perm in sorted(permissions[section].items(), key=lambda s: s[1]+s[0].lower()): | |
35 | <tr> |
|
39 | <tr> | |
36 | <td> |
|
40 | <td> | |
@@ -38,6 +42,9 b'' | |||||
38 | <a href="${h.url('summary_home',repo_name=k)}">${k}</a> |
|
42 | <a href="${h.url('summary_home',repo_name=k)}">${k}</a> | |
39 | %elif section == 'repositories_groups': |
|
43 | %elif section == 'repositories_groups': | |
40 | <a href="${h.url('repos_group_home',group_name=k)}">${k}</a> |
|
44 | <a href="${h.url('repos_group_home',group_name=k)}">${k}</a> | |
|
45 | %elif section == 'user_groups': | |||
|
46 | ##<a href="${h.url('edit_users_group',id=k)}">${k}</a> | |||
|
47 | ${k} | |||
41 | %endif |
|
48 | %endif | |
42 | </td> |
|
49 | </td> | |
43 | <td> |
|
50 | <td> | |
@@ -48,13 +55,14 b'' | |||||
48 | <a href="${h.url('edit_repo',repo_name=k,anchor='permissions_manage')}">${_('edit')}</a> |
|
55 | <a href="${h.url('edit_repo',repo_name=k,anchor='permissions_manage')}">${_('edit')}</a> | |
49 | %elif section == 'repositories_groups': |
|
56 | %elif section == 'repositories_groups': | |
50 | <a href="${h.url('edit_repos_group',group_name=k,anchor='permissions_manage')}">${_('edit')}</a> |
|
57 | <a href="${h.url('edit_repos_group',group_name=k,anchor='permissions_manage')}">${_('edit')}</a> | |
|
58 | %elif section == 'user_groups': | |||
|
59 | ##<a href="${h.url('edit_users_group',id=k)}">${_('edit')}</a> | |||
51 | %endif |
|
60 | %endif | |
52 | </td> |
|
61 | </td> | |
53 | </tr> |
|
62 | </tr> | |
54 | %endfor |
|
63 | %endfor | |
|
64 | </tbody> | |||
55 | %endif |
|
65 | %endif | |
56 |
|
||||
57 | </tbody> |
|
|||
58 | </table> |
|
66 | </table> | |
59 | </div> |
|
67 | </div> | |
60 | %endif |
|
68 | %endif |
@@ -21,4 +21,4 b'' | |||||
21 | <div class="pagination-wh pagination-left"> |
|
21 | <div class="pagination-wh pagination-left"> | |
22 | ${c.pullrequests_pager.pager('$link_previous ~2~ $link_next')} |
|
22 | ${c.pullrequests_pager.pager('$link_previous ~2~ $link_next')} | |
23 | </div> |
|
23 | </div> | |
24 | </div> No newline at end of file |
|
24 | </div> |
@@ -33,7 +33,7 b' merge" class="tooltip" href="/vcs_test_h' | |||||
33 | ) |
|
33 | ) | |
34 |
|
34 | |||
35 | def test_repo_summary_with_anonymous_access_disabled(self): |
|
35 | def test_repo_summary_with_anonymous_access_disabled(self): | |
36 |
anon = User.get_ |
|
36 | anon = User.get_default_user() | |
37 | anon.active = False |
|
37 | anon.active = False | |
38 | Session().add(anon) |
|
38 | Session().add(anon) | |
39 | Session().commit() |
|
39 | Session().commit() | |
@@ -45,13 +45,13 b' merge" class="tooltip" href="/vcs_test_h' | |||||
45 | assert 'login' in response.location |
|
45 | assert 'login' in response.location | |
46 |
|
46 | |||
47 | finally: |
|
47 | finally: | |
48 |
anon = User.get_ |
|
48 | anon = User.get_default_user() | |
49 | anon.active = True |
|
49 | anon.active = True | |
50 | Session().add(anon) |
|
50 | Session().add(anon) | |
51 | Session().commit() |
|
51 | Session().commit() | |
52 |
|
52 | |||
53 | def test_index_with_anonymous_access_disabled(self): |
|
53 | def test_index_with_anonymous_access_disabled(self): | |
54 |
anon = User.get_ |
|
54 | anon = User.get_default_user() | |
55 | anon.active = False |
|
55 | anon.active = False | |
56 | Session().add(anon) |
|
56 | Session().add(anon) | |
57 | Session().commit() |
|
57 | Session().commit() | |
@@ -61,7 +61,7 b' merge" class="tooltip" href="/vcs_test_h' | |||||
61 | status=302) |
|
61 | status=302) | |
62 | assert 'login' in response.location |
|
62 | assert 'login' in response.location | |
63 | finally: |
|
63 | finally: | |
64 |
anon = User.get_ |
|
64 | anon = User.get_default_user() | |
65 | anon.active = True |
|
65 | anon.active = True | |
66 | Session().add(anon) |
|
66 | Session().add(anon) | |
67 | Session().commit() |
|
67 | Session().commit() |
@@ -34,7 +34,7 b' class TestPermissions(unittest.TestCase)' | |||||
34 | username=u'u3', password=u'qweqwe', |
|
34 | username=u'u3', password=u'qweqwe', | |
35 | email=u'u3@rhodecode.org', firstname=u'u3', lastname=u'u3' |
|
35 | email=u'u3@rhodecode.org', firstname=u'u3', lastname=u'u3' | |
36 | ) |
|
36 | ) | |
37 |
self.anon = User.get_ |
|
37 | self.anon = User.get_default_user() | |
38 | self.a1 = UserModel().create_or_update( |
|
38 | self.a1 = UserModel().create_or_update( | |
39 | username=u'a1', password=u'qweqwe', |
|
39 | username=u'a1', password=u'qweqwe', | |
40 | email=u'a1@rhodecode.org', firstname=u'a1', lastname=u'a1', admin=True |
|
40 | email=u'a1@rhodecode.org', firstname=u'a1', lastname=u'a1', admin=True |
General Comments 0
You need to be logged in to leave comments.
Login now