Fix group prerequisite bug, fix some logic problems.
This commit is contained in:
parent
823c7c6743
commit
90064bdb63
1 changed files with 25 additions and 48 deletions
|
@ -17,25 +17,21 @@ def isAdmin(person):
|
||||||
try:
|
try:
|
||||||
if person.group_roles[admingroup].role_status == 'approved':
|
if person.group_roles[admingroup].role_status == 'approved':
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def canAdminGroup(person, group):
|
def canAdminGroup(person, group, role=None):
|
||||||
'''
|
'''
|
||||||
Returns True if the user is allowed to act as an admin for a group
|
Returns True if the user is allowed to act as an admin for a group
|
||||||
'''
|
'''
|
||||||
if isAdmin(person) or (group.owner == person):
|
if isAdmin(person) or (group.owner == person):
|
||||||
return True
|
return True
|
||||||
else:
|
if not role:
|
||||||
try:
|
try:
|
||||||
role = PersonRoles.query.filter_by(group=group, member=person).one()
|
role = PersonRoles.query.filter_by(group=group, member=person).one()
|
||||||
except IndexError:
|
|
||||||
''' Not in the group '''
|
|
||||||
return False
|
|
||||||
except InvalidRequestError:
|
except InvalidRequestError:
|
||||||
|
''' Not in the group '''
|
||||||
return False
|
return False
|
||||||
if role.role_status == 'approved' and role.role_type == 'administrator':
|
if role.role_status == 'approved' and role.role_type == 'administrator':
|
||||||
return True
|
return True
|
||||||
|
@ -45,21 +41,18 @@ def canSponsorGroup(person, group):
|
||||||
'''
|
'''
|
||||||
Returns True if the user is allowed to act as a sponsor for a group
|
Returns True if the user is allowed to act as a sponsor for a group
|
||||||
'''
|
'''
|
||||||
try:
|
|
||||||
if isAdmin(person) or \
|
if isAdmin(person) or \
|
||||||
group.owner == person:
|
group.owner == person:
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
try:
|
try:
|
||||||
role = PersonRoles.query.filter_by(group=group, member=person).one()
|
role = PersonRoles.query.filter_by(group=group, member=person).one()
|
||||||
except IndexError:
|
except InvalidRequestError:
|
||||||
''' Not in the group '''
|
''' Not in the group '''
|
||||||
return False
|
return False
|
||||||
if role.role_status == 'approved' and role.role_type == 'sponsor':
|
if (role.role_status == 'approved' and role.role_type == 'sponsor') \
|
||||||
|
or canAdminGroup(person, group, role):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
except:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def isApproved(person, group):
|
def isApproved(person, group):
|
||||||
'''
|
'''
|
||||||
|
@ -68,8 +61,6 @@ def isApproved(person, group):
|
||||||
try:
|
try:
|
||||||
if person.group_roles[group.name].role_status == 'approved':
|
if person.group_roles[group.name].role_status == 'approved':
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
@ -82,8 +73,6 @@ def CLADone(person):
|
||||||
try:
|
try:
|
||||||
if person.group_roles[cla_done_group].role_status == 'approved':
|
if person.group_roles[cla_done_group].role_status == 'approved':
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return False
|
return False
|
||||||
return False
|
return False
|
||||||
|
@ -96,7 +85,6 @@ def canEditUser(person, target):
|
||||||
return True
|
return True
|
||||||
elif isAdmin(person):
|
elif isAdmin(person):
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def canCreateGroup(person, group):
|
def canCreateGroup(person, group):
|
||||||
|
@ -106,7 +94,6 @@ def canCreateGroup(person, group):
|
||||||
# Should groupname restrictions go here?
|
# Should groupname restrictions go here?
|
||||||
if isAdmin(person):
|
if isAdmin(person):
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def canEditGroup(person, group):
|
def canEditGroup(person, group):
|
||||||
|
@ -115,7 +102,6 @@ def canEditGroup(person, group):
|
||||||
'''
|
'''
|
||||||
if canAdminGroup(person, group):
|
if canAdminGroup(person, group):
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def canViewGroup(person, group):
|
def canViewGroup(person, group):
|
||||||
|
@ -126,11 +112,8 @@ def canViewGroup(person, group):
|
||||||
# only people that can admin the group can view it
|
# only people that can admin the group can view it
|
||||||
privilegedViewGroups = config.get('privileged_view_groups')
|
privilegedViewGroups = config.get('privileged_view_groups')
|
||||||
if re.compile(privilegedViewGroups).match(group.name):
|
if re.compile(privilegedViewGroups).match(group.name):
|
||||||
if canAdminGroup(person, group):
|
if not canAdminGroup(person, group):
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
return False
|
||||||
else:
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def canApplyGroup(person, group, applicant):
|
def canApplyGroup(person, group, applicant):
|
||||||
|
@ -150,8 +133,6 @@ def canApplyGroup(person, group, applicant):
|
||||||
if (person == applicant) or \
|
if (person == applicant) or \
|
||||||
canSponsorGroup(person, group):
|
canSponsorGroup(person, group):
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
turbogears.flash(_('%s membership required before application to this group is allowed') % prerequisite.name)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def canSponsorUser(person, group, target):
|
def canSponsorUser(person, group, target):
|
||||||
|
@ -161,7 +142,6 @@ def canSponsorUser(person, group, target):
|
||||||
# This is just here in case we want to add more complex checks in the future
|
# This is just here in case we want to add more complex checks in the future
|
||||||
if canSponsorGroup(person, group):
|
if canSponsorGroup(person, group):
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def canRemoveUser(person, group, target):
|
def canRemoveUser(person, group, target):
|
||||||
|
@ -177,7 +157,6 @@ def canRemoveUser(person, group, target):
|
||||||
elif ((person == target) and (group.user_can_remove == True)) or \
|
elif ((person == target) and (group.user_can_remove == True)) or \
|
||||||
canSponsorGroup(person, group):
|
canSponsorGroup(person, group):
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def canUpgradeUser(person, group, target):
|
def canUpgradeUser(person, group, target):
|
||||||
|
@ -194,7 +173,6 @@ def canUpgradeUser(person, group, target):
|
||||||
elif canSponsorGroup(person, group) and \
|
elif canSponsorGroup(person, group) and \
|
||||||
not canSponsorGroup(target, group):
|
not canSponsorGroup(target, group):
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def canDowngradeUser(person, group, target):
|
def canDowngradeUser(person, group, target):
|
||||||
|
@ -210,6 +188,5 @@ def canDowngradeUser(person, group, target):
|
||||||
elif canSponsorGroup(person, group) and \
|
elif canSponsorGroup(person, group) and \
|
||||||
not canAdminGroup(person, group):
|
not canAdminGroup(person, group):
|
||||||
return True
|
return True
|
||||||
else:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue