Changeset aed3e6d for asadb/groups
- Timestamp:
- Dec 3, 2013, 12:31:49 AM (12 years ago)
- 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)
- Location:
- asadb/groups
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
asadb/groups/models.py
r00ec3e4 r7431d13 1 import collections 1 2 import datetime 2 3 import filecmp … … 14 15 from django.db.models import Q 15 16 from django.core.validators import RegexValidator 16 from django.contrib.auth.models import User 17 from django.contrib.auth.models import User, Permission 18 from django.contrib.contenttypes.models import ContentType 17 19 from django.template.defaultfilters import slugify 18 20 … … 112 114 current_officers = OfficeHolder.current_holders.filter(person=username) 113 115 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() 114 121 return users_groups 115 122 … … 395 402 396 403 @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 397 425 def retrieve(cls, slug, ): 398 426 return cls.objects.get(slug=slug) 427 399 428 reversion.register(OfficerRole) 400 429 … … 407 436 ) 408 437 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 409 442 class OfficeHolder(models.Model): 410 443 EXPIRE_OFFSET = datetime.timedelta(seconds=1) … … 433 466 def __repr__(self, ): 434 467 return str(self) 468 435 469 reversion.register(OfficeHolder) 436 470 -
asadb/groups/views.py
r89165c1 r7dde669 696 696 from_email='asa-admin@mit.edu', 697 697 ) 698 # XXX: Handle this better699 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.subject703 accounts_mail.body = "Bad domain on officer or group list\n\n" + accounts_mail.body704 698 705 699 else: … … 828 822 return render_to_response('groups/create/startup.html', context, context_instance=RequestContext(request), ) 829 823 824 def 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 830 851 @permission_required('groups.recognize_group') 831 852 def recognize_normal_group(request, pk, ): … … 843 864 if group_startup.stage != groups.models.GROUP_STARTUP_STAGE_SUBMITTED: 844 865 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) 845 868 846 869 context['msg'] = ""
Note: See TracChangeset
for help on using the changeset viewer.