Changeset 89be44c


Ignore:
Timestamp:
Aug 5, 2011, 3:42:44 AM (15 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage, test-hooks
Children:
7444bbe
Parents:
a8d80c2
git-author:
Alex Dehnert <adehnert@…> (08/05/11 03:42:44)
git-committer:
Alex Dehnert <adehnert@…> (08/05/11 03:42:44)
Message:

Validate new officers

This fills two former voids:

  • President and Treasurer now must be students
  • All people must have Athena accounts

Per brief discussion on -c asa, people holding a position that they can no
longer hold (deactivated student account, non-student president and treasurer)
will (normally) produce warnings but will not be forcibly removed.

Location:
asadb/groups
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • asadb/groups/admin.py

    rd241a05 r89be44c  
    2525        'slug',
    2626        'max_count',
     27        'require_student',
    2728    )
    2829    list_display_links = ('id', 'display_name', 'slug', )
  • asadb/groups/models.py

    ra8d80c2 r89be44c  
    6161    description = models.TextField()
    6262    max_count = models.IntegerField(default=UNLIMITED, help_text='Maximum number of holders of this role. Use %d for no limit.' % UNLIMITED)
     63    require_student = models.BooleanField(default=False)
    6364
    6465    def __str__(self, ):
     
    101102
    102103
     104class AthenaMoiraAccount_ActiveManager(models.Manager):
     105    def get_query_set(self, ):
     106        return super(AthenaMoiraAccount_ActiveManager, self).get_query_set().filter(del_date=None)
     107
    103108class AthenaMoiraAccount(models.Model):
    104109    username = models.CharField(max_length=8)
     
    111116    del_date        = models.DateField(help_text="Date when this person was removed from the dump.", blank=True, null=True, )
    112117    mod_date        = models.DateField(help_text="Date when this person's record was last changed.", blank=True, null=True, )
     118
     119    objects = models.Manager()
     120    active_accounts = AthenaMoiraAccount_ActiveManager()
     121
     122    def is_student(self, ):
     123        # XXX: Is this... right?
     124        return self.account_class == 'G' or self.account_class.isdigit()
     125
    113126    def __str__(self, ):
    114127        if self.mutable:
  • asadb/groups/views.py

    ree679c6 r89be44c  
    163163
    164164        new_people = {}
     165        moira_accounts = {}
    165166        for i in range(max_new):
    166167            key = "extra.%d" % (i, )
    167             if key in request.POST:
    168                 # TODO: validate as real usernames
    169                 new_people[i] = request.POST[key]
     168            if key in request.POST and request.POST[key] != "":
     169                username = request.POST[key]
     170                try:
     171                    moira_accounts[username] = groups.models.AthenaMoiraAccount.active_accounts.get(username=username)
     172                    new_people[i] = username
     173                except groups.models.AthenaMoiraAccount.DoesNotExist:
     174                    msgs.append('Athena account "%s" appears not to exist. Changes involving them have been ignored.' % (username, ))
     175        for person in people:
     176            try:
     177                moira_accounts[person] = groups.models.AthenaMoiraAccount.active_accounts.get(username=person)
     178            except groups.models.AthenaMoiraAccount.DoesNotExist:
     179                msgs.append('Athena account "%s" appears not to exist. They can not be added to new roles. You should remove them from any roles they hold, if you have not already.' % (person, ))
    170180        for role in roles:
    171181            key = "holders.%s" % (role.slug, )
     
    180190                for person in people:
    181191                    if person in new_holders:
    182                         # TODO: validate student status of appropriate officers
    183192                        if (person, role) in officers_map:
     193                            if role.require_student and not moira_accounts[person].is_student():
     194                                msgs.append('Only students can have the %s role, and %s does not appear to be a student. You should replace this person ASAP.' % (role, person, ))
    184195                            #changes.append(("Kept", "yellow", person, role))
    185196                            kept += 1
    186197                        else:
    187                             holder = groups.models.OfficeHolder(person=person, role=role, group=group,)
    188                             holder.save()
    189                             changes.append(("Added", "green", person, role))
     198                            if person not in moira_accounts:
     199                                msgs.append('Could not add nonexistent Athena account "%s" as %s.' % (person, role, ))
     200                            elif role.require_student and not moira_accounts[person].is_student():
     201                                msgs.append('Only students can have the %s role, and %s does not appear to be a student.' % (role, person, ))
     202                            else:
     203                                holder = groups.models.OfficeHolder(person=person, role=role, group=group,)
     204                                holder.save()
     205                                changes.append(("Added", "green", person, role))
    190206                    else:
    191207                        if (person, role) in officers_map:
     
    199215                        if i in new_people:
    200216                            person = new_people[i]
    201                             holder = groups.models.OfficeHolder(person=person, role=role, group=group,)
    202                             holder.save()
    203                             changes.append(("Added", "green", person, role))
     217                            if role.require_student and not moira_accounts[person].is_student():
     218                                msgs.append('Only students can have the %s role, and %s does not appear to be a student.' % (role, person, ))
     219                            else:
     220                                holder = groups.models.OfficeHolder(person=person, role=role, group=group,)
     221                                holder.save()
     222                                changes.append(("Added", "green", person, role))
    204223
    205224        # reload the data
Note: See TracChangeset for help on using the changeset viewer.