Files
codeocean/app/policies/exercise_policy.rb
kiragrammel 175c8933f3 Automatically submit LTI grade on each score run
With this commit, we refactor the overall score handling of CodeOcean. Previously, "Score" and "Submit" were two distinct actions, requiring users to confirm the LTI transmission of their score (after assessing their submission). This yielded many questions and was unnecessary, since LTI parameters are no longer expiring after each use. Therefore, we can now transmit the current grade on each score run with the very same LTI parameters. As a consequence, the LTI consumer gets a more detailed history of the scores, enabling further analytical insights.

For users, the previous "Submit" button got replaced with a notification that is shown as soon as the full score got reached. Then, learners can decide to "finalize" their work on the given exercise, which will initiate a redirect to a follow-up action (as defined in the RedirectBehavior). This RedirectBehavior has also been unified and simplified for better readability.

As part of this refactoring, we rephrased the notifications and UX workflow of a) the LTI transmission, b) the finalization of an exercise (measured by reaching the full score) and c) the deadline handling (on time, within grace period, too late). Those information are now separately shown, potentially resulting in multiple notifications. As a side effect, they are much better maintainable, and the LTI transmission is more decoupled from this notification handling.
2023-11-23 14:42:10 +01:00

63 lines
2.0 KiB
Ruby

# frozen_string_literal: true
class ExercisePolicy < AdminOrAuthorPolicy
def batch_update?
admin?
end
%i[show? feedback? statistics? external_user_statistics? rfcs_for_exercise?].each do |action|
define_method(action) { admin? || teacher_in_study_group? || (teacher? && @record.public?) || author? }
end
def study_group_dashboard?
admin? || teacher_in_study_group?
end
def submission_statistics?
admin? || teacher_in_study_group?
end
def detailed_statistics?
admin?
end
%i[clone? destroy? edit? update?].each do |action|
define_method(action) { admin? || teacher_in_study_group? || author? }
end
%i[export_external_check? export_external_confirm?].each do |action|
define_method(action) { (admin? || teacher_in_study_group? || author?) && @user.codeharbor_link }
end
%i[implement? working_times? intervention? reload?].each do |action|
define_method(action) do
return no_one unless @record.files.any? {|f| f.hidden == false } && @record.execution_environment.present?
admin? || teacher_in_study_group? || author? || (everyone && !@record.unpublished?)
end
end
def programming_groups_for_exercise?
admin?
end
class Scope < Scope
def resolve
if @user.admin?
@scope.all
elsif @user.teacher?
@scope.distinct
.joins('LEFT OUTER JOIN study_group_memberships ON exercises.user_type = study_group_memberships.user_type AND exercises.user_id = study_group_memberships.user_id')
# The exercise's author is a teacher in the study group
.where(study_group_memberships: {role: StudyGroupMembership.roles[:teacher]})
# The current user is a teacher in the *same* study group
.where(study_group_memberships: {study_group_id: @user.study_group_memberships.where(role: :teacher).select(:study_group_id)})
.or(@scope.distinct.where(user: @user))
.or(@scope.distinct.where(public: true))
else
@scope.none
end
end
end
end