Not very thoroughly tested. Attempt to trade off memory for number of selects (?)
This commit is contained in:
parent
3f94ff13d7
commit
dbdf0325ab
2 changed files with 27 additions and 25 deletions
|
@ -15,14 +15,13 @@ def isAdmin(person):
|
||||||
'''
|
'''
|
||||||
admingroup = config.get('admingroup')
|
admingroup = config.get('admingroup')
|
||||||
try:
|
try:
|
||||||
group = Groups.by_name(admingroup)
|
if person.group_roles[admingroup].role_status == 'approved':
|
||||||
except InvalidRequestError:
|
|
||||||
print '%s - Your admin group could not be found!' % admingroup
|
|
||||||
return False
|
|
||||||
if group in person.approved_memberships:
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
except KeyError:
|
||||||
|
print '%s - Your admin group could not be found!' % admingroup
|
||||||
|
return False
|
||||||
|
|
||||||
def canAdminGroup(person, group):
|
def canAdminGroup(person, group):
|
||||||
'''
|
'''
|
||||||
|
@ -74,30 +73,27 @@ def signedCLAPrivs(person):
|
||||||
'''
|
'''
|
||||||
Returns True if the user has completed the GPG-signed CLA
|
Returns True if the user has completed the GPG-signed CLA
|
||||||
'''
|
'''
|
||||||
|
cla_sign_group =config.get('cla_sign_group')
|
||||||
try:
|
try:
|
||||||
cla_sign_group = Groups.by_name(config.get('cla_sign_group'))
|
if person.group_roles[cla_sign_group].role_status == 'approved':
|
||||||
except InvalidRequestError:
|
|
||||||
turbogears.flash(_("cla_sign_group Does not exist! Please create it!"))
|
|
||||||
return False
|
|
||||||
if isApproved(person, cla_sign_group):
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
except KeyError:
|
||||||
|
return False
|
||||||
|
|
||||||
def clickedCLAPrivs(person):
|
def clickedCLAPrivs(person):
|
||||||
'''
|
'''
|
||||||
Returns True if the user has completed the click-through CLA
|
Returns True if the user has completed the click-through CLA
|
||||||
'''
|
'''
|
||||||
|
cla_click_group = config.get('cla_click_group')
|
||||||
try:
|
try:
|
||||||
cla_click_group = Groups.by_name(config.get('cla_click_group'))
|
if person.group_roles[cla_click_group].role_status == 'approved':
|
||||||
except InvalidRequestError:
|
|
||||||
turbogears.flash(_("cla_click_group Does not exist! Please create it!"))
|
|
||||||
return False
|
|
||||||
if signedCLAPrivs(person) or \
|
|
||||||
isApproved(person, cla_click_group):
|
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
except KeyError:
|
||||||
|
return False
|
||||||
|
|
||||||
def canEditUser(person, target):
|
def canEditUser(person, target):
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -34,7 +34,7 @@ from sqlalchemy.orm import relation
|
||||||
from sqlalchemy import String, Unicode, Integer, DateTime
|
from sqlalchemy import String, Unicode, Integer, DateTime
|
||||||
# A few sqlalchemy tricks:
|
# A few sqlalchemy tricks:
|
||||||
# Allow viewing foreign key relations as a dictionary
|
# Allow viewing foreign key relations as a dictionary
|
||||||
from sqlalchemy.orm.collections import column_mapped_collection
|
from sqlalchemy.orm.collections import column_mapped_collection, attribute_mapped_collection
|
||||||
# Allow us to reference the remote table of a many:many as a simple list
|
# Allow us to reference the remote table of a many:many as a simple list
|
||||||
from sqlalchemy.ext.associationproxy import association_proxy
|
from sqlalchemy.ext.associationproxy import association_proxy
|
||||||
from sqlalchemy import select, and_
|
from sqlalchemy import select, and_
|
||||||
|
@ -294,6 +294,7 @@ class PersonRoles(SABase):
|
||||||
'''Record people that are members of groups.'''
|
'''Record people that are members of groups.'''
|
||||||
def __repr__(cls):
|
def __repr__(cls):
|
||||||
return "PersonRole(%s,%s,%s,%s)" % (cls.member.username, cls.group.name, cls.role_type, cls.role_status)
|
return "PersonRole(%s,%s,%s,%s)" % (cls.member.username, cls.group.name, cls.role_type, cls.role_status)
|
||||||
|
groupname = association_proxy('group', 'name')
|
||||||
|
|
||||||
class Configs(SABase):
|
class Configs(SABase):
|
||||||
'''Configs for applications that a Fedora Contributor uses.'''
|
'''Configs for applications that a Fedora Contributor uses.'''
|
||||||
|
@ -412,10 +413,10 @@ class VisitIdentity(SABase):
|
||||||
# mappers for filtering roles
|
# mappers for filtering roles
|
||||||
#
|
#
|
||||||
mapper(ApprovedRoles, ApprovedRolesSelect, properties = {
|
mapper(ApprovedRoles, ApprovedRolesSelect, properties = {
|
||||||
'group': relation(Groups, backref='approved_roles')
|
'group': relation(Groups, backref='approved_roles', lazy = False)
|
||||||
})
|
})
|
||||||
mapper(UnApprovedRoles, UnApprovedRolesSelect, properties = {
|
mapper(UnApprovedRoles, UnApprovedRolesSelect, properties = {
|
||||||
'group': relation(Groups, backref='unapproved_roles')
|
'group': relation(Groups, backref='unapproved_roles', lazy = False)
|
||||||
})
|
})
|
||||||
|
|
||||||
mapper(People, PeopleTable, properties = {
|
mapper(People, PeopleTable, properties = {
|
||||||
|
@ -425,6 +426,10 @@ mapper(People, PeopleTable, properties = {
|
||||||
'person_emails': relation(PersonEmails, backref = 'person',
|
'person_emails': relation(PersonEmails, backref = 'person',
|
||||||
collection_class = column_mapped_collection(
|
collection_class = column_mapped_collection(
|
||||||
PersonEmailsTable.c.email)),
|
PersonEmailsTable.c.email)),
|
||||||
|
# This name is kind of confusing. It's to allow person.group_roles['groupname'] in order to make auth.py (hopefully) slightly faster.
|
||||||
|
'group_roles': relation(PersonRoles,
|
||||||
|
collection_class = attribute_mapped_collection('groupname'),
|
||||||
|
primaryjoin = PeopleTable.c.id==PersonRolesTable.c.person_id),
|
||||||
'approved_roles': relation(ApprovedRoles, backref='member',
|
'approved_roles': relation(ApprovedRoles, backref='member',
|
||||||
primaryjoin = PeopleTable.c.id==ApprovedRoles.c.person_id),
|
primaryjoin = PeopleTable.c.id==ApprovedRoles.c.person_id),
|
||||||
'unapproved_roles': relation(UnApprovedRoles, backref='member',
|
'unapproved_roles': relation(UnApprovedRoles, backref='member',
|
||||||
|
@ -438,7 +443,8 @@ mapper(EmailPurposes, EmailPurposesTable, properties = {
|
||||||
mapper(PersonRoles, PersonRolesTable, properties = {
|
mapper(PersonRoles, PersonRolesTable, properties = {
|
||||||
'member': relation(People, backref = 'roles', lazy = False,
|
'member': relation(People, backref = 'roles', lazy = False,
|
||||||
primaryjoin=PersonRolesTable.c.person_id==PeopleTable.c.id),
|
primaryjoin=PersonRolesTable.c.person_id==PeopleTable.c.id),
|
||||||
'group': relation(Groups, backref='roles'),
|
'group': relation(Groups, backref='roles', lazy = False,
|
||||||
|
primaryjoin=PersonRolesTable.c.group_id==GroupsTable.c.id),
|
||||||
'sponsor': relation(People, uselist=False,
|
'sponsor': relation(People, uselist=False,
|
||||||
primaryjoin = PersonRolesTable.c.sponsor_id==PeopleTable.c.id)
|
primaryjoin = PersonRolesTable.c.sponsor_id==PeopleTable.c.id)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue