From a06b02c090dc756f9263b6ddbab0c35f8ff7c56b Mon Sep 17 00:00:00 2001 From: Xander Moffatt Date: Thu, 12 Sep 2019 08:15:43 -0600 Subject: [PATCH] add user_sis_id and user_login to live events * specifically to user_created and user_updated closes PLAT-4829 test plan: * enable live events (see doc/live_events.md) on your local machine * create a user with a sis id * the live event generated should contain these 2 new fields * update that user * the live event generated should contain these 2 new fields Change-Id: Ic199173ba9cd54723dba73dcc381be7b6de644aa Reviewed-on: https://gerrit.instructure.com/209171 Reviewed-by: Marc Phillips Tested-by: Jenkins QA-Review: Weston Dransfield Product-Review: Xander Moffatt --- doc/live_events.md | 7 +++++ lib/canvas/live_events.rb | 4 ++- spec/lib/canvas/live_events_spec.rb | 44 +++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/doc/live_events.md b/doc/live_events.md index f9099a11fcc..c21682b833c 100644 --- a/doc/live_events.md +++ b/doc/live_events.md @@ -48,6 +48,13 @@ You can view the stream with the `tail_kinesis` tool: docker-compose run --rm web script/tail_kinesis http://kinesis:4567 live-events ``` +#### Stubbing Kinesis + +Instead of viewing events in the kinesis stream, you can also add this env variable +to your docker compose configuration: `STUB_LIVE_EVENTS_KINESIS`, with any value. +This will redirect live events from the kinesis stream to stdout. You still have +to configure the live events plugin for this to work. + #### Connecting to local Publisher Lambda The `live-events-publish repo should be checked out and running locally. diff --git a/lib/canvas/live_events.rb b/lib/canvas/live_events.rb index 98c37580d25..cc782fa4747 100644 --- a/lib/canvas/live_events.rb +++ b/lib/canvas/live_events.rb @@ -317,7 +317,9 @@ module Canvas::LiveEvents short_name: user.short_name, workflow_state: user.workflow_state, created_at: user.created_at, - updated_at: user.updated_at + updated_at: user.updated_at, + user_login: user.primary_pseudonym&.unique_id, + user_sis_id: user.primary_pseudonym&.sis_user_id } end diff --git a/spec/lib/canvas/live_events_spec.rb b/spec/lib/canvas/live_events_spec.rb index d7394a06545..46e4e1e8789 100644 --- a/spec/lib/canvas/live_events_spec.rb +++ b/spec/lib/canvas/live_events_spec.rb @@ -1163,4 +1163,48 @@ describe Canvas::LiveEvents do end end end + + describe 'user' do + context 'created' do + it 'should trigger a user_created live event' do + user_with_pseudonym + + expect_event('user_created', { + user_id: @user.global_id.to_s, + uuid: @user.uuid, + name: @user.name, + short_name: @user.short_name, + workflow_state: @user.workflow_state, + created_at: @user.created_at, + updated_at: @user.updated_at, + user_login: @pseudonym&.unique_id, + user_sis_id: @pseudonym&.sis_user_id + }.compact!).once + + Canvas::LiveEvents.user_created(@user) + end + end + + context 'updated' do + it 'should trigger a user_updated live event' do + user_with_pseudonym + + @user.update!(name: "Test Name") + + expect_event('user_updated', { + user_id: @user.global_id.to_s, + uuid: @user.uuid, + name: @user.name, + short_name: @user.short_name, + workflow_state: @user.workflow_state, + created_at: @user.created_at, + updated_at: @user.updated_at, + user_login: @pseudonym&.unique_id, + user_sis_id: @pseudonym&.sis_user_id + }.compact!).once + + Canvas::LiveEvents.user_updated(@user) + end + end + end end