Skip to content
Open
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ student-work/
.byebug_history
coverage/
_history

# Institution specific config
config/*_setting.rb
!config/no_institution_setting.rb
21 changes: 13 additions & 8 deletions app/api/lti_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,22 @@ class LtiApi < Grape::API
error!({ error: "Missing required fields: #{missing.join(', ')}" }, 400)
end

if current_user.role_id != Role.student_id
return status 204
end
# if current_user.role_id != Role.student_id
# return status 204
# end

role = unit.role_for(current_user)
if !role.nil? && role != Role.student
# error!({ error: 'Failed to enrol, user is already staff.' }, 400)
return status 204
# role = unit.role_for(current_user)
# if !role.nil? && role != Role.student
# # error!({ error: 'Failed to enrol, user is already staff.' }, 400)
# return status 204
# end

unit_role = Doubtfire::Application.config.institution_settings.should_employ_lti_member(member)
unless unit_role.nil?
unit.employ_staff(current_user, unit_role)
end

unless Doubtfire::Application.config.institution_settings.should_enrol_lti_member(token['member'])
unless Doubtfire::Application.config.institution_settings.should_enrol_lti_member(member)
# error!({ error: 'User can not be enrolled into this unit.' }, 404)
return status 204
end
Expand Down
16 changes: 15 additions & 1 deletion app/sidekiq/import_students_lti_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,23 @@ def perform(unit_id, members)
end

if user.valid?
unit_role = Doubtfire::Application.config.institution_settings.should_employ_lti_member(member)
unless unit_role.nil?
staff = unit.employ_staff(user, unit_role)
if staff.valid?
result[:success] << { row: member, message: "Successfully added staff (#{unit_role.role.name})" }
next
end
end

unless Doubtfire::Application.config.institution_settings.should_enrol_lti_member(member)
result[:ignored] << { row: member, message: "Enrolment skipped by institution setting" }
next
end

project = unit.enrol_student(user, nil)
if project.valid?
result[:success] << { row: member, message: "Successfully enrolled user." }
result[:success] << { row: member, message: "Successfully enrolled user" }
else
result[:errors] << { row: member, message: "Failed to enrol student" }
end
Expand Down
9 changes: 9 additions & 0 deletions config/no_institution_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ def update_user_from_lti_response(user, user_id_data, member)
user
end

# If this returns nil, LTI will move on to check if this member should be enrolled as a student
def should_employ_lti_member(member)
return nil if member['roles'].include?('Student') || member['roles'].include?('Learner')
return Role.convenor if member['roles'].include?("http://purl.imsglobal.org/vocab/lis/v2/person#Administrator")
return Role.tutor if member['roles'].include?("Instructor")

nil
end

def should_enrol_lti_member(member)
# Example "roles" for a Student => ["Learner"]
# Example "roles" for an Instructor, who is a global Administrator => ["Instructor", "http://purl.imsglobal.org/vocab/lis/v2/person#Administrator"],
Expand Down
Loading