Ignore:
Timestamp:
Jun 5, 2013, 5:53:11 AM (13 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, stable, stage
Children:
17c118f
Parents:
242566d (diff), 72a3d90 (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@…> (06/05/13 05:53:05)
git-committer:
Alex Dehnert <adehnert@…> (06/05/13 05:53:11)
Message:

Merge branch 'space-access'

This branch was created to fix ASA-#96 ("Differentiate between spaces CAC does
and does not manage access to"), but also fixes a wide variety of other
space-related issues.

  • space-access: (23 commits) Fill in the office access timeframe Fix grammar ({e,a}ffect) Punt another spurious slash Use "Space Access" more consistently Add "Details" link to "Space access" page Rename 50-030 to 50-032 and set its lock type Space: tell groups CAC should reply (ASA-#235) Warn people off the "Space access" page (ASA-#233) Don't let people edit spaces the DB doesn't manage More Walker rooms Correct Walker room access Add info_url to the admin Incorporate feedback from CAC Update the space emails with non-DB-managed info Comment space/diffs.py's locker code a bit better Show lock types on manage access page Describe the lock types and list on space summary Add list of lock types and assign them to rooms Use pagename "groups", not "group" WIP: more non-CAC space work ...
File:
1 edited

Legend:

Unmodified
Added
Removed
  • asadb/space/diffs.py

    rc8f4eea r27e09a9  
    88    cur_file = os.path.abspath(__file__)
    99    django_dir = os.path.abspath(os.path.join(os.path.dirname(cur_file), '..'))
     10    django_dir_parent = os.path.abspath(os.path.join(os.path.dirname(cur_file), '../..'))
    1011    sys.path.append(django_dir)
     12    sys.path.append(django_dir_parent)
    1113    os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
    1214
    1315from django.core.mail import EmailMessage
     16from django.core.urlresolvers import reverse
    1417from django.db import connection
    1518from django.db.models import Q
     
    100103
    101104    def list_office_changes(self, ):
    102         cac_lines = []
     105        systems_lines = {
     106            'cac-card': [],
     107            'none': [],
     108        }
    103109        group_lines = []
    104         def append_change(mit_id, verb, name):
    105             cac_lines.append("%s:\t%s:\t%s" % (mit_id, verb, name))
    106             group_lines.append("%s:\t%s" % (verb, name))
    107110        for space_pk, space_data in self.offices.items():
     111            lock_type = all_spaces[space_pk].lock_type
     112            system_lines = systems_lines[lock_type.db_update]
     113            def append_change(mit_id, verb, name):
     114                system_lines.append("%s:\t%s:\t%s" % (mit_id, verb, name))
     115                group_lines.append("%s:\t%s" % (verb, name))
     116
    108117            line = "Changes in %s:" % (all_spaces[space_pk].number, )
    109             cac_lines.append(line)
     118            system_lines.append(line)
    110119            group_lines.append(line)
     120
     121            if lock_type.db_update == 'none':
     122                tmpl =  'Warning: You submitted changes affecting this space, but this space is ' + \
     123                        'a "%s" space, and is not managed through the ASA DB. See ' + \
     124                        'https://asa.mit.edu%s for details on how to update spaces of this type.'
     125                line = tmpl % (lock_type.name, reverse('space-lock-type'), )
     126                group_lines.append(line)
     127
    111128            for mit_id, (old_names, new_names) in space_data.items():
    112129                if mit_id is None: mit_id = "ID unknown"
     
    125142                        else:
    126143                            append_change(mit_id, "Add", name)
    127             cac_lines.append("")
     144            system_lines.append("")
    128145            group_lines.append("")
    129146
    130         cac_msg = "\n".join(cac_lines)
     147        systems_msg = dict([
     148            (system, '\n'.join(lines), ) for (system, lines) in systems_lines.items()
     149        ])
    131150        group_msg = "\n".join(group_lines)
    132         return cac_msg, group_msg
     151        return systems_msg, group_msg
    133152
    134153    def add_locker_signatories(self, space_access, time):
     
    177196
    178197def safe_add_change_real(change_by_name, change):
     198    """Add a new change to our dict of pending changes.
     199
     200    If a different change has already been added for this person (eg, "Remove"
     201    instead of "Keep", or with a different list of groups), error.  This should
     202    always succeed; if it doesn't, the code is buggy. We worry about this
     203    because we want to be really sure that the email that goes to just CAC is
     204    compatible with the emails that go to each groups. Since we iterate over
     205    the changes once per group, we want to be sure that for each group
     206    iteration we're building compatible information.
     207    """
     208
    179209    name = change.name
    180210    if name in change_by_name:
     
    200230        print "ID=%s (%s):\n\t%s\t(%s)\n\t%s\t(%s)\n" % (mit_id, unchanged, old_by_names, old_by_group, new_by_names, new_by_group, ),
    201231        for group_pk in joint_keys(old_by_group, new_by_group):
     232            # TODO: Do we need to do an iteration for each group? This seems
     233            # slightly questionable. Can we just loop over all known names?
     234
    202235            old_names = old_by_group[group_pk]
    203236            new_names = new_by_group[group_pk]
     
    267300    cac_locker_msgs = []
    268301
    269     process_spaces =  space.models.Space.objects.all()
     302    process_spaces =  space.models.Space.objects.all().select_related('lock_type')
    270303    for the_space in process_spaces:
    271304        new_cac_msgs = space_specific_access(the_space, group_data, old_time, new_time)
     
    274307
    275308    changed_groups = []
     309    cac_chars = 0
    276310    for group_pk, group_info in group_data.items():
    277311        group_info.add_office_signatories(old_time, new_time)
    278         cac_changes, group_office_changes = group_info.list_office_changes()
     312        systems_changes, group_office_changes = group_info.list_office_changes()
    279313        if group_info.changes:
    280             changed_groups.append((group_info.group, cac_changes, group_office_changes, group_info.locker_messages, ))
     314            cac_chars += len(systems_changes['cac-card'])
     315            changed_groups.append((group_info.group, systems_changes['cac-card'], group_office_changes, group_info.locker_messages, ))
    281316
    282317    asa_rcpts = ['asa-space@mit.edu', 'asa-db@mit.edu', ]
    283     if changed_groups:
     318    if cac_chars > 0 or cac_locker_msgs:
    284319        util.emails.email_from_template(
    285320            tmpl='space/cac-change-email.txt',
Note: See TracChangeset for help on using the changeset viewer.