Changeset aed3e6d for asadb/groups


Ignore:
Timestamp:
Dec 3, 2013, 12:31:49 AM (12 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, stable, stage
Children:
eab727a
Parents:
7dde669 (diff), d9624e8 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Alex Dehnert <adehnert@…> (12/03/13 00:31:49)
git-committer:
Alex Dehnert <adehnert@…> (12/03/13 00:31:49)
Message:

Merge branch 'membership-confirmations'

  • membership-confirmations: Link people lookup tool from membership update page People lookup: mention the data source People lookup: Support large numbers of people People lookup: make the UI more reasonable Basic people lookup support (ASA-#186) Reword membership definition text More thoroughly purge mention of membership lists Standarize on UK-style ndashes Remove the membership list Do my counting in the DB... Save some unnecessary queries with select_related Finish removing membership confirmation search box Include suspended groups in issues.csv (ASA-#195) Memberships: refactor issues.csv slightly Make issues.csv cycle-aware (ASA-#191) JSify the giant list of groups (ASA-#185) Show the group name on the update page List only adminned groups in anti-hazing select Add Group.admin_groups method (ASA-#181)
Location:
asadb/groups
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • asadb/groups/models.py

    r00ec3e4 r7431d13  
     1import collections
    12import datetime
    23import filecmp
     
    1415from django.db.models import Q
    1516from django.core.validators import RegexValidator
    16 from django.contrib.auth.models import User
     17from django.contrib.auth.models import User, Permission
     18from django.contrib.contenttypes.models import ContentType
    1719from django.template.defaultfilters import slugify
    1820
     
    112114        current_officers = OfficeHolder.current_holders.filter(person=username)
    113115        users_groups = Group.objects.filter(officeholder__in=current_officers).distinct()
     116
     117    @staticmethod
     118    def admin_groups(username, codename='admin_group'):
     119        holders = OfficeHolder.current_holders.filter_perm(codename=codename).filter(person=username)
     120        users_groups = Group.objects.filter(officeholder__in=holders).distinct()
    114121        return users_groups
    115122
     
    395402
    396403    @classmethod
     404    def getRolesGrantingPerm(cls, perm=None, model=Group, codename=None, ):
     405        """Get all OfficerRole objects granting a permission
     406
     407        Either `perm` or `codename` must be supplied, but not both. If
     408        `codename` is provided (and `perm` is None), then `perm` the
     409        permission corresponding to `model` (default: `Group`) and `codename`
     410        will be found and used."""
     411
     412        if perm is None:
     413            ct = ContentType.objects.get_for_model(model)
     414            print ct
     415            print Permission.objects.filter(content_type=ct)
     416            perm = Permission.objects.get(content_type=ct, codename=codename)
     417
     418        Q_user = Q(user_permissions=perm)
     419        Q_group = Q(groups__permissions=perm)
     420        users = User.objects.filter(Q_user|Q_group)
     421        roles = cls.objects.filter(grant_user__in=users)
     422        return roles
     423
     424    @classmethod
    397425    def retrieve(cls, slug, ):
    398426        return cls.objects.get(slug=slug)
     427
    399428reversion.register(OfficerRole)
    400429
     
    407436        )
    408437
     438    def filter_perm(self, perm=None, model=Group, codename=None, ):
     439        roles = OfficerRole.getRolesGrantingPerm(perm=perm, model=model, codename=codename)
     440        return self.get_query_set().filter(role__in=roles)
     441
    409442class OfficeHolder(models.Model):
    410443    EXPIRE_OFFSET   = datetime.timedelta(seconds=1)
     
    433466    def __repr__(self, ):
    434467        return str(self)
     468
    435469reversion.register(OfficeHolder)
    436470
  • asadb/groups/views.py

    r89165c1 r7dde669  
    696696            from_email='asa-admin@mit.edu',
    697697        )
    698         # XXX: Handle this better
    699         if officer_domain != 'mit.edu' or (create_group_list and group_domain != 'mit.edu'):
    700             accounts_mail.to = ['asa-groups@mit.edu']
    701             accounts_mail.cc = ['asa-db@mit.edu']
    702             accounts_mail.subject = "ERROR: " + accounts_mail.subject
    703             accounts_mail.body = "Bad domain on officer or group list\n\n" + accounts_mail.body
    704698
    705699    else:
     
    828822    return render_to_response('groups/create/startup.html', context, context_instance=RequestContext(request), )
    829823
     824def review_group_check_warnings(group_startup, group, ):
     825    warnings = []
     826
     827    if group.name.startswith("MIT "):
     828        warnings.append('Group name starts with "MIT". Generally, we prefer "Foo, MIT" instead.')
     829    if "mit" in group.athena_locker.lower():
     830        warnings.append('Athena locker name contains "mit", which may be redundant with paths like "http://web.mit.edu/mitfoo" or "/mit/foo/".')
     831
     832    if group_startup.president_kerberos == group_startup.treasurer_kerberos:
     833        warnings.append('President matches Treasurer.')
     834    if "%s@mit.edu" % (group_startup.president_kerberos, ) in (group.officer_email, group.group_email):
     835        warnings.append('President email matches officer and/or group email.')
     836    if group.officer_email == group.group_email:
     837        warnings.append('Officer email matches group email.')
     838
     839    if '@mit.edu' not in group.officer_email or '@mit.edu' not in group.group_email:
     840        warnings.append('Officer and/or group email are non-MIT. Ensure that they are not requesting the addresses be created, and consider suggesting they use an MIT list instead.')
     841
     842    if '.' in group.athena_locker:
     843        warnings.append('Athena locker contains a ".". This is not compatible with scripts.mit.edu\'s wildcard certificate, and may cause other problems.')
     844    if '_' in group.athena_locker:
     845        warnings.append('Athena locker contains a "_". If this locker name gets used in a URL (for example, locker.scripts.mit.edu), it will technically violate the hostname specification and may not work in some clients.')
     846    if len(group.athena_locker) > 12:
     847        warnings.append('Athena locker is more than twelve characters long. In general, twelve characters is the longest Athena locker an ASA-recognized group can get.')
     848
     849    return warnings
     850
    830851@permission_required('groups.recognize_group')
    831852def recognize_normal_group(request, pk, ):
     
    843864    if group_startup.stage != groups.models.GROUP_STARTUP_STAGE_SUBMITTED:
    844865        return render_to_response('groups/create/err.not-applying.html', context, context_instance=RequestContext(request), )
     866
     867    context['warnings'] = review_group_check_warnings(group_startup, group)
    845868
    846869    context['msg'] = ""
Note: See TracChangeset for help on using the changeset viewer.