From b875f4e1ff8f4164c4cb3a345e48f430985bda46 Mon Sep 17 00:00:00 2001 From: Ricky Zhou Date: Tue, 18 Mar 2008 18:39:26 -0400 Subject: [PATCH] Various group fixes. --- fas/fas/auth.py | 11 ++++------- fas/fas/group.py | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/fas/fas/auth.py b/fas/fas/auth.py index 05b5deb..712b880 100644 --- a/fas/fas/auth.py +++ b/fas/fas/auth.py @@ -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) diff --git a/fas/fas/group.py b/fas/fas/group.py index c96b92c..d4edfc7 100644 --- a/fas/fas/group.py +++ b/fas/fas/group.py @@ -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()