Various group fixes.

This commit is contained in:
Ricky Zhou (周家杰) 2008-03-18 18:39:26 -04:00
parent 729c32a54d
commit b875f4e1ff
2 changed files with 18 additions and 9 deletions

View file

@ -141,17 +141,14 @@ def canApplyGroup(person, group, applicant):
# This is bypassed for people already in the group and for the
# owner of the group (when they initially make it).
prerequisite = group.prerequisite
# TODO: Make this return more useful info.
# TODO: Make this raise more useful info.
if prerequisite:
if prerequisite in person.approved_memberships:
pass
else:
if prerequisite not in applicant.approved_memberships:
turbogears.flash(_('%s membership required before application to this group is allowed') % prerequisite.name)
return False
# A user can apply themselves, and FAS admins can apply other people.
# A user can apply themselves, and group sponsors can apply other people.
if (person == applicant) or \
canAdminGroup(person, group):
canSponsorGroup(person, group):
return True
else:
turbogears.flash(_('%s membership required before application to this group is allowed') % prerequisite.name)

View file

@ -34,6 +34,16 @@ class UnknownGroup(validators.FancyValidator):
else:
raise validators.Invalid(_("The group '%s' already exists.") % value, value, state)
class ValidGroupType(validators.FancyValidator):
'''Make sure that a group type is valid'''
def _to_python(self, value, state):
return value.strip()
def validate_python(self, value, state):
if value not in ('system', 'bugzilla','cvs', 'bzr', 'git', \
'hg', 'mtn', 'svn', 'shell', 'torrent', 'tracker', \
'tracking', 'user'):
raise validators.Invalid(_("Invalid group type.") % value, value, state)
class GroupCreate(validators.Schema):
name = validators.All(
@ -47,14 +57,14 @@ class GroupCreate(validators.Schema):
validators.NotEmpty,
)
prerequisite = KnownGroup
#group_type = something
group_type = ValidGroupType
class GroupSave(validators.Schema):
groupname = validators.All(KnownGroup, validators.String(max=32, min=3))
display_name = validators.NotEmpty
owner = KnownUser
prerequisite = KnownGroup
#group_type = something
group_type = ValidGroupType
class GroupApply(validators.Schema):
groupname = KnownGroup
@ -231,6 +241,8 @@ class Group(controllers.Controller):
if prerequisite:
prerequisite = Groups.by_name(prerequisite)
group.prerequisite = prerequisite
else:
group.prerequisite = None
group.joinmsg = joinmsg
# Log here
session.flush()