##// END OF EJS Templates
auth: added additional name filters to the acl helpers....
marcink -
r2037:910a6a72 default
parent child Browse files
Show More
@@ -1004,7 +1004,7 b' class AuthUser(object):'
1004 1004 x[0] for x in self.permissions['user_groups'].iteritems()
1005 1005 if x[1] == 'usergroup.admin']
1006 1006
1007 def repo_acl_ids(self, perms=None, cache=False):
1007 def repo_acl_ids(self, perms=None, name_filter=None, cache=False):
1008 1008 """
1009 1009 Returns list of repository ids that user have access to based on given
1010 1010 perms. The cache flag should be only used in cases that are used for
@@ -1015,16 +1015,22 b' class AuthUser(object):'
1015 1015 perms = [
1016 1016 'repository.read', 'repository.write', 'repository.admin']
1017 1017
1018 def _cached_repo_acl(user_id, perm_def):
1019 return [x.repo_id for x in RepoList(
1020 Repository.query().all(), perm_set=perm_def)]
1018 def _cached_repo_acl(user_id, perm_def, name_filter):
1019 qry = Repository.query()
1020 if name_filter:
1021 ilike_expression = u'%{}%'.format(safe_unicode(name_filter))
1022 qry = qry.filter(
1023 Repository.repo_name.ilike(ilike_expression))
1024
1025 return [x.repo_id for x in
1026 RepoList(qry, perm_set=perm_def)]
1021 1027
1022 1028 compute = caches.conditional_cache(
1023 1029 'long_term', 'repo_acl_ids',
1024 1030 condition=cache, func=_cached_repo_acl)
1025 return compute(self.user_id, perms)
1031 return compute(self.user_id, perms, name_filter)
1026 1032
1027 def repo_group_acl_ids(self, perms=None, cache=False):
1033 def repo_group_acl_ids(self, perms=None, name_filter=None, cache=False):
1028 1034 """
1029 1035 Returns list of repository group ids that user have access to based on given
1030 1036 perms. The cache flag should be only used in cases that are used for
@@ -1035,16 +1041,22 b' class AuthUser(object):'
1035 1041 perms = [
1036 1042 'group.read', 'group.write', 'group.admin']
1037 1043
1038 def _cached_repo_group_acl(user_id, perm_def):
1039 return [x.group_id for x in RepoGroupList(
1040 RepoGroup.query().all(), perm_set=perm_def)]
1044 def _cached_repo_group_acl(user_id, perm_def, name_filter):
1045 qry = RepoGroup.query()
1046 if name_filter:
1047 ilike_expression = u'%{}%'.format(safe_unicode(name_filter))
1048 qry = qry.filter(
1049 RepoGroup.group_name.ilike(ilike_expression))
1050
1051 return [x.group_id for x in
1052 RepoGroupList(qry, perm_set=perm_def)]
1041 1053
1042 1054 compute = caches.conditional_cache(
1043 1055 'long_term', 'repo_group_acl_ids',
1044 1056 condition=cache, func=_cached_repo_group_acl)
1045 return compute(self.user_id, perms)
1057 return compute(self.user_id, perms, name_filter)
1046 1058
1047 def user_group_acl_ids(self, perms=None, cache=False):
1059 def user_group_acl_ids(self, perms=None, name_filter=None, cache=False):
1048 1060 """
1049 1061 Returns list of user group ids that user have access to based on given
1050 1062 perms. The cache flag should be only used in cases that are used for
@@ -1055,14 +1067,20 b' class AuthUser(object):'
1055 1067 perms = [
1056 1068 'usergroup.read', 'usergroup.write', 'usergroup.admin']
1057 1069
1058 def _cached_user_group_acl(user_id, perm_def):
1059 return [x.users_group_id for x in UserGroupList(
1060 UserGroup.query().all(), perm_set=perm_def)]
1070 def _cached_user_group_acl(user_id, perm_def, name_filter):
1071 qry = UserGroup.query()
1072 if name_filter:
1073 ilike_expression = u'%{}%'.format(safe_unicode(name_filter))
1074 qry = qry.filter(
1075 UserGroup.users_group_name.ilike(ilike_expression))
1076
1077 return [x.users_group_id for x in
1078 UserGroupList(qry, perm_set=perm_def)]
1061 1079
1062 1080 compute = caches.conditional_cache(
1063 1081 'long_term', 'user_group_acl_ids',
1064 1082 condition=cache, func=_cached_user_group_acl)
1065 return compute(self.user_id, perms)
1083 return compute(self.user_id, perms, name_filter)
1066 1084
1067 1085 @property
1068 1086 def ip_allowed(self):
General Comments 0
You need to be logged in to leave comments. Login now