From ea35376bfb1fd6ff7e313471634b3fce138410ac Mon Sep 17 00:00:00 2001 From: Nate Armstrong Date: Thu, 14 May 2020 12:37:18 -0600 Subject: [PATCH] Add context_name to calendar events api flag=none refs: MBL-14399 Test plan: - Enroll a student in a course - Create and publish an assignment in the course and set its due date to some day this month - Create a calendar event on the user's calendar - As the student, query the calendar_events api for the assignment - Something like: /api/v1/calendar_events ?type=assignment &start_date=2020-05-01 &end_date=2020-05-30 &context_codes[]=course_1 - The context_name should be included - As the student, give the course a nickname - The context_name should be the nickname of the course - As the student, query the calendar_events api for the calendar event - Something like: /api/v1/calendar_events ?start_date=2020-05-01 &end_date=2020-05-30 - The context_name should be included Change-Id: Ie5336637824d3241d39b7fbb6dcb083e3ec25cdc Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/237393 Tested-by: Service Cloud Jenkins Reviewed-by: Ben Nelson Reviewed-by: Rob Orton QA-Review: Ben Nelson Product-Review: Ben Nelson --- app/controllers/calendar_events_api_controller.rb | 5 +++++ lib/api/v1/calendar_event.rb | 2 ++ spec/apis/v1/calendar_events_api_spec.rb | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/calendar_events_api_controller.rb b/app/controllers/calendar_events_api_controller.rb index da7f12affed..b79e4022ddc 100644 --- a/app/controllers/calendar_events_api_controller.rb +++ b/app/controllers/calendar_events_api_controller.rb @@ -71,6 +71,11 @@ require 'atom' # "description": "if specified, it indicates which calendar this event should be displayed on. for example, a section-level event would have the course's context code here, while the section's context code would be returned above)", # "type": "string" # }, +# "context_name": { +# "description": "the context name of the calendar this event belongs to (course, user or group)", +# "example": "Chemistry 101", +# "type": "string" +# }, # "all_context_codes": { # "description": "a comma-separated list of all calendar contexts this event is part of", # "example": "course_123,course_456", diff --git a/lib/api/v1/calendar_event.rb b/lib/api/v1/calendar_event.rb index fc49753bc98..c87d8882b65 100644 --- a/lib/api/v1/calendar_event.rb +++ b/lib/api/v1/calendar_event.rb @@ -97,6 +97,7 @@ module Api::V1::CalendarEvent hash['all_context_codes'] = Context.context_code_for(event) end hash['context_code'] ||= Context.context_code_for(event) + hash['context_name'] = context.try(:nickname_for, user) hash['parent_event_id'] = event.parent_calendar_event_id # events are hidden when section-specific events override them @@ -193,6 +194,7 @@ module Api::V1::CalendarEvent hash['html_url'] = hash['assignment']['html_url'] if hash['assignment'].include?('html_url') end hash['context_code'] = Context.context_code_for(assignment) + hash['context_name'] = assignment.context.try(:nickname_for, user) hash['start_at'] = hash['end_at'] = assignment.due_at hash['url'] = api_v1_calendar_event_url("assignment_#{assignment.id}") if assignment.applied_overrides.present? diff --git a/spec/apis/v1/calendar_events_api_spec.rb b/spec/apis/v1/calendar_events_api_spec.rb index 41343a5d637..a1d5d588233 100644 --- a/spec/apis/v1/calendar_events_api_spec.rb +++ b/spec/apis/v1/calendar_events_api_spec.rb @@ -30,7 +30,7 @@ describe CalendarEventsApiController, type: :request do 'all_context_codes', 'all_day', 'all_day_date', 'child_events', 'child_events_count', 'comments', 'context_code', 'created_at', 'description', 'duplicates', 'end_at', 'hidden', 'html_url', 'id', 'location_address', 'location_name', 'parent_event_id', 'start_at', - 'title', 'type', 'updated_at', 'url', 'workflow_state' + 'title', 'type', 'updated_at', 'url', 'workflow_state', 'context_name' ] expected_slot_fields = (expected_fields + ['appointment_group_id', 'appointment_group_url', 'can_manage_appointment_group', 'available_slots', 'participants_per_appointment', 'reserve_url', 'participant_type', 'effective_context_code']) expected_reservation_event_fields = (expected_fields + ['appointment_group_id', 'appointment_group_url', 'can_manage_appointment_group', 'effective_context_code', 'participant_type']) @@ -1458,7 +1458,7 @@ describe CalendarEventsApiController, type: :request do expected_fields = [ 'all_day', 'all_day_date', 'assignment', 'context_code', 'created_at', 'description', 'end_at', 'html_url', 'id', 'start_at', 'title', 'type', 'updated_at', - 'url', 'workflow_state' + 'url', 'workflow_state', 'context_name' ] it 'should return assignments within the given date range' do