show name of user who performed sync in blueprint history

test plan:
 - set up a blueprint course and associated course
 - perform a sync
 - the sync history in the blueprint course's sidebar should show
   "X changes pushed by (name of user)"
 - the blueprint information in the associated course's settings
   should also show the name of the user who performed the last sync

flag = none
closes LS-1263

Change-Id: Iee4e2326d773a72d109566291a873c922108e173
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/249760
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: James Williams <jamesw@instructure.com>
QA-Review: Robin Kuss <rkuss@instructure.com>
Product-Review: Peyton Craighill <pcraighill@instructure.com>
This commit is contained in:
Jeremy Stanley 2020-10-09 16:35:14 -06:00
parent 7250aba4bf
commit 3c798a4115
6 changed files with 33 additions and 3 deletions

View File

@ -515,6 +515,7 @@ class MasterCourses::MasterTemplatesController < ApplicationController
def migrations_index
# sort id desc
migrations = Api.paginate(@template.master_migrations.order("id DESC"), self, api_v1_course_blueprint_migrations_url)
ActiveRecord::Associations::Preloader.new.preload(migrations, :user)
render :json => migrations.map{|migration| master_migration_json(migration, @current_user, session) }
end
@ -591,6 +592,7 @@ class MasterCourses::MasterTemplatesController < ApplicationController
where(:migration_type => 'master_course_import', :child_subscription_id => @subscription).
order('id DESC')
migrations = Api.paginate(migrations, self, api_v1_course_blueprint_imports_url)
ActiveRecord::Associations::Preloader.new.preload(migrations, :user)
render :json => migrations.map{ |migration| master_migration_json(migration.master_migration, @current_user,
session, :child_migration => migration,
:subscription => @subscription) }

View File

@ -37,7 +37,12 @@ const SyncHistoryItem = ({migration, heading, ChangeComponent}) => {
<FriendlyDatetime dateTime={date} format={I18n.t('#date.formats.full_with_weekday')} />
</Heading>
<Text color="secondary" size="small">
{I18n.t('%{count} pushed changes', {count: changes.length})}
{migration.user?.display_name
? I18n.t('%{count} changes pushed by %{user}', {
count: changes.length,
user: migration.user.display_name
})
: I18n.t('%{count} pushed changes', {count: changes.length})}
</Text>
</header>
{comment && <Text as="p" color="secondary" size="small">{`"${comment}"`}</Text>}

View File

@ -16,6 +16,8 @@
# with this program. If not, see <http://www.gnu.org/licenses/>.
module Api::V1::MasterCourses
include Api::V1::User
def master_template_json(template, user, session, opts={})
hash = api_json(template, user, session, :only => %w(id course_id), :methods => %w{last_export_completed_at associated_course_count})
migration = template.active_migration
@ -33,6 +35,7 @@ module Api::V1::MasterCourses
hash['template_id'] = migration.master_template_id
end
hash['id'] = opts[:child_migration].id if opts[:child_migration]
hash['user'] = user_display_json(migration.user)
hash
end

View File

@ -230,6 +230,7 @@ describe MasterCourses::MasterTemplatesController, type: :request do
json = api_call(:get, "/api/v1/courses/#{@course.id}/blueprint_templates/default/migrations/#{@migration.id}",
@base_params.merge(:action => 'migrations_show', :id => @migration.to_param))
expect(json['workflow_state']).to eq 'queued'
expect(json['user']['display_name']).to eq @user.short_name
expect(json['comment']).to eq 'Hark!'
end
@ -239,6 +240,7 @@ describe MasterCourses::MasterTemplatesController, type: :request do
migration2 = MasterCourses::MasterMigration.start_new_migration!(@template, @user)
json = api_call(:get, "/api/v1/courses/#{@course.id}/blueprint_templates/default/migrations", @base_params.merge(:action => 'migrations_index'))
expect(json[0]['user']['display_name']).to eq @user.short_name
pairs = json.map{|hash| [hash['id'], hash['workflow_state']]}
expect(pairs).to eq [[migration2.id, 'queued'], [@migration.id, 'completed']]
end
@ -263,6 +265,7 @@ describe MasterCourses::MasterTemplatesController, type: :request do
@base_params.merge(:subscription_id => @sub.to_param, :course_id => @child_course.to_param, :action => 'imports_show', :id => @minion_migration.to_param))
expect(json['workflow_state']).to eq 'completed'
expect(json['subscription_id']).to eq @sub.id
expect(json['user']['display_name']).to eq @user.short_name
expect(json['comment']).to eq 'Hark!'
end
@ -272,6 +275,7 @@ describe MasterCourses::MasterTemplatesController, type: :request do
expect(json.size).to eq 1
expect(json[0]['id']).to eq @minion_migration.id
expect(json[0]['subscription_id']).to eq @sub.id
expect(json[0]['user']['display_name']).to eq @user.short_name
end
it "filters by subscription and enumerates old subscriptions" do

View File

@ -58,3 +58,10 @@ test('renders changes using the appropriate prop component', () => {
const node = tree.find('.bcs__history-item .test-change')
equal(node.length, props.migration.changes.length)
})
test('includes the name of the person who started the sync', () => {
const tree = enzyme.mount(<SyncHistoryItem {...defaultProps()} />)
const node = tree.find('.bcs__history-item__title')
const text = node.text()
notEqual(text.indexOf('changes pushed by Bob Jones'), -1)
})

View File

@ -18,8 +18,14 @@
export default function getSampleData() {
return {
terms: [{id: '1', name: 'Term One'}, {id: '2', name: 'Term Two'}],
subAccounts: [{id: '1', name: 'Account One'}, {id: '2', name: 'Account Two'}],
terms: [
{id: '1', name: 'Term One'},
{id: '2', name: 'Term Two'}
],
subAccounts: [
{id: '1', name: 'Account One'},
{id: '2', name: 'Account Two'}
],
childCourse: {
id: '1',
enrollment_term_id: '1',
@ -67,6 +73,9 @@ export default function getSampleData() {
id: '2',
workflow_state: 'completed',
created_at: '2013-08-28T23:59:00-06:00',
user: {
display_name: 'Bob Jones'
},
changes: [
{
asset_id: '2',