Skip to content

Commit

Permalink
Merge pull request #43 from Harvard-University-iCommons/task/sapnamys…
Browse files Browse the repository at this point in the history
…ore/tlt-3241/tf-changes

Task/sapnamysore/tlt 3241/tf changes
  • Loading branch information
sapnamysore authored Feb 5, 2018
2 parents 4a25450 + a36a085 commit 1cf4d7b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
67 changes: 67 additions & 0 deletions manage_people/migrations/0004_mp_tf_role.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models, transaction

MANAGE_PEOPLE_ROLE_DATA = [
# NOTE:
# 1. This is similar to 001_mp_initial. This handles the new TF role(user_role_id=6)
# 2.this data does not need to vary between environments, as the ids
# in the user_role table are the same in both qa and prod oracle
# (user_role_id, xid_allowed)

(6, False)
]

# Note: This is similar to 002_mp_school_allowed_role. This handles TF role
# for the 2 schools that have currently requested it
SCHOOL_ALOWED_ROLE_DATA = [
('colgsas', 6, False),
('hds', 6, False)
]

def populate_manage_people_role(apps, schema_editor):
ManagePeopleRole = apps.get_model('manage_people', 'ManagePeopleRole')
fields = ('user_role_id', 'xid_allowed')
with transaction.atomic(): # wrap all the inserts in a transaction
for values in MANAGE_PEOPLE_ROLE_DATA:
ManagePeopleRole.objects.create(**dict(zip(fields, values)))


def reverse_manage_people_role_load(apps, schema_editor):
ManagePeopleRole = apps.get_model('manage_people', 'ManagePeopleRole')
ManagePeopleRole.objects.filter(user_role_id=6).delete()



def populate_school_allowed_role(apps, schema_editor):
SchoolAllowedRole = apps.get_model('manage_people', 'SchoolAllowedRole')
fields = ('school_id', 'user_role_id', 'xid_allowed')
with transaction.atomic(): # wrap all the inserts in a transaction
for values in SCHOOL_ALOWED_ROLE_DATA:
SchoolAllowedRole.objects.create(**dict(zip(fields, values)))


def reverse_load_school_role(apps, schema_editor):
SchoolAllowedRole = apps.get_model('manage_people', 'SchoolAllowedRole')
SchoolAllowedRole.objects.filter(user_role_id=6).delete()


class Migration(migrations.Migration):
dependencies = [
('manage_people', '0003_remove_managepeoplerole_canvas_role_label'),

]

operations = [

migrations.RunPython(
code=populate_manage_people_role,
reverse_code=reverse_manage_people_role_load,
),

migrations.RunPython(
code=populate_school_allowed_role,
reverse_code=reverse_load_school_role,
)
]
2 changes: 1 addition & 1 deletion manage_people/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def get_user_role_to_canvas_role_map(account_id='self'):

logger.debug(
u"Caching user_role_id:Canvas role map for Canvas account %s: %s",
account_id, json.dumps(role_map))
account_id, json.dumps(str(role_map)).replace("'", '"'))
cache.set(cache_key, role_map)
return role_map

Expand Down

0 comments on commit 1cf4d7b

Please sign in to comment.