add option to include all context codes in appointment show api

fixes CNVS-32911

test plan
- create an appointment group that has two courses as contexts
- as a teacher in one course but not the other, get the
 appointment group using the api
- ensure that only the teacher's course is listed under context
 codes
- get the appointment group via api again but with the
 ?include[]=all_context_codes param specified
- ensure that there is an all_context_codes field in the result
 that lists both context codes

Change-Id: If7852d7ba8489706b2f87571b66aa34fb5163ea7
Reviewed-on: https://gerrit.instructure.com/93659
Reviewed-by: Frederick Polgardy <fpolgardy@instructure.com>
Reviewed-by: Dan Minkevitch <dan@instructure.com>
Tested-by: Jenkins
QA-Review: Heath Hales <hhales@instructure.com>
Product-Review: Joel Hough <joel@instructure.com>
This commit is contained in:
Joel Hough 2016-10-25 17:41:02 -06:00
parent 61218a3e8a
commit 0d9f23e7a4
3 changed files with 17 additions and 3 deletions

View File

@ -228,7 +228,7 @@ class AppointmentGroupsController < ApplicationController
# @argument include_past_appointments [Boolean]
# Defaults to false. If true, includes past appointment groups
#
# @argument include[] ["appointments"|"child_events"|"participant_count"|"reserved_times"]
# @argument include[] ["appointments"|"child_events"|"participant_count"|"reserved_times"|"all_context_codes"]
# Array of additional information to include.
#
# "appointments":: calendar event time slots for this appointment group
@ -236,6 +236,7 @@ class AppointmentGroupsController < ApplicationController
# "participant_count":: number of reservations
# "reserved_times":: the event id, start time and end time of reservations
# the current user has made)
# "all_context_codes":: all context codes associated with this appointment group
def index
return web_index unless request.format == :json
@ -363,12 +364,13 @@ class AppointmentGroupsController < ApplicationController
#
# Returns information for a single appointment group
#
# @argument include[] ["child_events"|"appointments"]
# Array of additional information to include. Ssee include[] argument of
# @argument include[] ["child_events"|"appointments"|"all_context_codes"]
# Array of additional information to include. See include[] argument of
# "List appointment groups" action.
#
# "child_events":: reservations of time slots time slots
# "appointments":: will always be returned
# "all_context_codes":: all context codes associated with this appointment group
def show
if authorized_action(@group, @current_user, :read)
return web_show unless request.format == :json

View File

@ -191,6 +191,7 @@ module Api::V1::CalendarEvent
:start_at => event.start_at,
:end_at => event.end_at}} if include.include?('reserved_times')
hash['context_codes'] = group.context_codes_for_user(user)
hash['all_context_codes'] = group.context_codes if include.include?('all_context_codes') && group.grants_right?(user, session, :manage)
hash['requiring_action'] = group.requiring_action?(user)
if group.new_appointments.present?
hash['new_appointments'] = group.new_appointments.map{ |event| calendar_event_json(event, user, session, :skip_details => true, :appointment_group_id => group.id) }

View File

@ -190,6 +190,17 @@ describe AppointmentGroupsController, type: :request do
expect(cjson.first['user']['id']).to eql @student1.id
end
it 'should include all associated context codes, if requested' do
ag = AppointmentGroup.create!(:title => "something", :new_appointments => [["2012-01-01 12:00:00", "2012-01-01 13:00:00"]], :contexts => [@course])
json = api_call(:get, "/api/v1/appointment_groups/#{ag.id}?include[]=all_context_codes", {
:controller => 'appointment_groups', :action => 'show', :format => 'json', :id => ag.id.to_s, :include => ['all_context_codes']})
expect(json.keys.sort).to eql((expected_fields + ['all_context_codes', 'appointments']).sort)
expect(json['id']).to eql ag.id
ccs = json['all_context_codes']
expect(ccs).to eql [@course.asset_string]
end
it 'should get a manageable appointment group' do
ag = AppointmentGroup.create!(:title => "something", :new_appointments => [["2012-01-01 12:00:00", "2012-01-01 13:00:00"]], :contexts => [@course])