Skip to content

Commit

Permalink
Merge pull request #5124 from dodona-edu/fix/ufora-js
Browse files Browse the repository at this point in the history
Only return administrating courses in LTI picker
  • Loading branch information
jorg-vr authored Nov 9, 2023
2 parents 8bc9e84 + 3b619e6 commit fcc0d3c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
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 @@ def do_redirect
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)

@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

0 comments on commit fcc0d3c

Please sign in to comment.