Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only return administrating courses in LTI picker #5124

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/controllers/lti_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@
end

def content_selection
return head :unauthorized unless current_user&.a_course_admin?

@supported = @lti_message.accept_types.include?(LTI::Messages::Types::DeepLinkingResponse::LtiResourceLink::TYPE)
@grouped_courses = policy_scope(Course.all).group_by(&:year)
@grouped_courses = current_user.administrating_courses.group_by(&:year)
@multiple = @lti_message.accept_multiple
end

def series_and_activities
# Eager load the activities
@course = Course.includes(series: [:activities]).find_by(id: params[:id])

return head :unauthorized unless current_user&.admin_of?(@course)

Check warning on line 50 in app/controllers/lti_controller.rb

View check run for this annotation

Codecov / codecov/patch

app/controllers/lti_controller.rb#L50

Added line #L50 was not covered by tests

@series = policy_scope(@course.series)
@multiple = ActiveModel::Type::Boolean.new.cast(params[:multiple])
end
Expand Down
39 changes: 39 additions & 0 deletions test/controllers/lti_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ def setup
end

test 'content selection shows courses' do
user = create :staff
courses = create_list :course, 2
user.administrating_courses << courses
payload = lti_payload('nonce', 'target', 'LtiDeepLinkingRequest')
id_token = encode_jwt(payload)

sign_in user

get content_selection_path, params: {
id_token: id_token,
provider_id: @provider.id
Expand All @@ -33,6 +37,41 @@ def setup
end
end

test 'content selection should not show courses that are not administrated by the user' do
user = create :staff
courses = create_list :course, 2
payload = lti_payload('nonce', 'target', 'LtiDeepLinkingRequest')
id_token = encode_jwt(payload)

sign_in user

get content_selection_path, params: {
id_token: id_token,
provider_id: @provider.id
}

assert_response :ok
courses.each do |course|
assert_select 'option', { text: course.name, count: 0 }
end
end

test 'content selection should return unauthorized if the user is not administrating any courses' do
user = create :student
create_list :course, 2
payload = lti_payload('nonce', 'target', 'LtiDeepLinkingRequest')
id_token = encode_jwt(payload)

sign_in user

get content_selection_path, params: {
id_token: id_token,
provider_id: @provider.id
}

assert_response :unauthorized
end

test 'content selection payload is correct' do
series = create :series, exercise_count: 1
payload = lti_payload('nonce', 'target', 'LtiDeepLinkingRequest')
Expand Down
Loading