* Lays out framework for getting and caching Microsoft API tokens and
hitting the Microsoft Graph API.
* Simple sync job which creates a group for the class if it doesn't
exist and sets the extra LMS/SIS metadata.
NOTE: I discovered the MS API is eventually consistent -- it does not
immediately create a group when we hit the POST /education/classes
endpoint. In a future commit (I added a new ticket) we can work replace
the "sleep" with polling with sleeping or launching a new delayed job.
closes INTEROP-6567
flag=microsoft_group_enrollments_syncing
Test plan:
* Get creds from me and put in dynamic_settings.yml
* Try getting a token and observe it is cached (only the first time you
run will you see "get service:timeouts:microsoft_sync_login:error_count"
and "set microsoft_sync_login/<OURTESTTENANT>" calls to the redis cache):
MicrosoftSync::LoginService.token(<OURTESTTENANT>)
* Put our test tenant (you can get that from me) into your root
account's settings[:microsoft_sync_tenant]
* Create a course with a name and description that clearly label it
as your test course for the Microsoft sync project
* From a rails console run:
c = Course.find(...) # your new test course
g = MicrosoftSync::Group.create(course: c)
syncer = MicrosoftSync::Syncer.new(g)
syncer.sync
* Run the syncer again and observe (from the MicrosoftSync::GraphClient:
log lines) that we do not create or delete anything.
* Check that the group looks OK on the Microsoft side:
g = MicrosoftSync::Group.last
syncer = MicrosoftSync::Syncer.new(MicrosoftSync::Group.last)
cgs = syncer.canvas_graph_service
gs = cgs.graph_service
gs.get_group(g.ms_group_id)
* Check that the extra properties on the group have been set:
gs.get_group(g.ms_group_id, select:
%w[microsoft_EducationClassLmsExt microsoft_EducationClassSisExt])
* Update the group's ms_group_id to nil in the database:
g.update! ms_group_id: nil
Then rename the course to something similar but slightly different and
re-rerun the sync job (you may have to run syncer.course.reload and/or
syncer.group.reload to make the syncer get new values). Then repeat
the last two steps. In the first of those two steps, the group name,
but in the second step, the data in microsoft_EducationClassLmsExt
should be updated. This is because the syncer assumes if a group has
been created it was created correctly, but it doesn't assume the extra
metadata was ever set to it re-sets it. Also check that ms_group_id
has been re-filled in on the group record.
* Change your creds to something invalid and clear the rails cache.
Run the sync. It should raise an error. Then check that the Group
record has been updated with workflow_state=errored and
last_error="Invalid Status Code: Login service returned 401 for tenant
<OURTENANT>". This is what will be shown to the user (teacher).
* If you need/want to look at the Microsoft admin web console, you can
get those creds from me. From there you can delete your group, if
needed. You can also delete your group by using:
gs.request(:delete, "groups/#{ms_group_id}")
Change-Id: I077497c1c412095420079ea80d461bd172425bca
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/260232
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Wagner Goncalves <wagner.goncalves@instructure.com>
Reviewed-by: Weston Dransfield <wdransfield@instructure.com>
QA-Review: Wagner Goncalves <wagner.goncalves@instructure.com>
Product-Review: Evan Battaglia <ebattaglia@instructure.com>