Add StudyGroup to submissions and show it for submissions and RfCs
Also take care of deleting a StudyGroup for existing submissions
This commit is contained in:
@ -168,6 +168,7 @@ module Lti
|
||||
end
|
||||
group.users |= [@current_user] # add current user if not already member of the group
|
||||
group.save
|
||||
session[:study_group_id] = group.id
|
||||
end
|
||||
|
||||
def set_embedding_options
|
||||
|
@ -16,7 +16,8 @@ module SubmissionParameters
|
||||
current_user_id = current_user.id
|
||||
current_user_class_name = current_user.class.name
|
||||
end
|
||||
submission_params = params[:submission].present? ? params[:submission].permit(:cause, :exercise_id, files_attributes: file_attributes).merge(user_id: current_user_id, user_type: current_user_class_name) : {}
|
||||
# The study_group_id might not be present in the session (e.g. for internal users), resulting in session[:study_group_id] = nil which is intended.
|
||||
submission_params = params[:submission].present? ? params[:submission].permit(:cause, :exercise_id, files_attributes: file_attributes).merge(user_id: current_user_id, user_type: current_user_class_name, study_group_id: session[:study_group_id]) : {}
|
||||
reject_illegal_file_attributes!(submission_params)
|
||||
submission_params
|
||||
end
|
||||
|
@ -83,17 +83,10 @@ class RequestForCommentsController < ApplicationController
|
||||
authorize!
|
||||
end
|
||||
|
||||
# GET /request_for_comments/new
|
||||
def new
|
||||
@request_for_comment = RequestForComment.new
|
||||
authorize!
|
||||
end
|
||||
|
||||
# GET /request_for_comments/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /request_for_comments
|
||||
# POST /request_for_comments.json
|
||||
def create
|
||||
# Consider all requests as JSON
|
||||
@ -149,8 +142,8 @@ class RequestForCommentsController < ApplicationController
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def request_for_comment_params
|
||||
# we are using the current_user.id here, since internal users are not able to create comments. The external_user.id is a primary key and does not require the consumer_id to be unique.
|
||||
params.require(:request_for_comment).permit(:exercise_id, :file_id, :question, :requested_at, :solved, :submission_id).merge(user_id: current_user.id, user_type: current_user.class.name)
|
||||
# The study_group_id might not be present in the session (e.g. for internal users), resulting in session[:study_group_id] = nil which is intended.
|
||||
params.require(:request_for_comment).permit(:exercise_id, :file_id, :question, :requested_at, :solved, :submission_id).merge(user_id: current_user.id, user_type: current_user.class.name, study_group_id: session[:study_group_id])
|
||||
end
|
||||
|
||||
def comment_params
|
||||
|
@ -1,12 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class StudyGroup < ApplicationRecord
|
||||
has_many :study_group_memberships
|
||||
has_many :study_group_memberships, dependent: :destroy
|
||||
# Use `ExternalUser` as `source_type` for now.
|
||||
# Using `User` will lead ActiveRecord to access the inexistent table `users`.
|
||||
# Issue created: https://github.com/rails/rails/issues/34531
|
||||
has_many :users, through: :study_group_memberships, source_type: 'ExternalUser'
|
||||
has_many :submissions
|
||||
has_many :submissions, dependent: :nullify
|
||||
belongs_to :consumer
|
||||
|
||||
def to_s
|
||||
|
@ -25,6 +25,22 @@ class ApplicationPolicy
|
||||
end
|
||||
private :no_one
|
||||
|
||||
def everyone_in_study_group
|
||||
study_group = @record.study_group
|
||||
return false if study_group.blank?
|
||||
|
||||
users_in_same_study_group = study_group.users
|
||||
return false if users_in_same_study_group.blank?
|
||||
|
||||
users_in_same_study_group.include? @user
|
||||
end
|
||||
private :everyone_in_study_group
|
||||
|
||||
def teacher_in_study_group
|
||||
teacher? && everyone_in_study_group
|
||||
end
|
||||
private :teacher_in_study_group
|
||||
|
||||
def initialize(user, record)
|
||||
@user = user
|
||||
@record = record
|
||||
|
@ -12,14 +12,8 @@ class SubmissionPolicy < ApplicationPolicy
|
||||
admin?
|
||||
end
|
||||
|
||||
def everyone_in_study_group
|
||||
users_in_same_study_group = @record.study_groups.users
|
||||
users_in_same_study_group.include? @user
|
||||
end
|
||||
private :everyone_in_study_group
|
||||
|
||||
def teacher_in_study_group
|
||||
teacher? && everyone_in_study_group
|
||||
def show_study_group?
|
||||
admin? || teacher_in_study_group
|
||||
end
|
||||
private :teacher_in_study_group
|
||||
end
|
||||
|
@ -9,6 +9,9 @@
|
||||
- testruns = Testrun.where(:submission_id => @request_for_comment.submission)
|
||||
= link_to_if(policy(user).show?, user.displayname, user)
|
||||
| | #{@request_for_comment.created_at.localtime}
|
||||
- if @request_for_comment.submission.study_group.present? && policy(@request_for_comment.submission).show_study_group?
|
||||
= ' | '
|
||||
= link_to_if(policy(@request_for_comment.submission.study_group).show?, @request_for_comment.submission.study_group, @request_for_comment.submission.study_group)
|
||||
.rfc
|
||||
.description
|
||||
h5
|
||||
|
@ -9,6 +9,7 @@ h1 = @submission
|
||||
|
||||
= row(label: 'submission.exercise', value: link_to_if(policy(@submission.exercise).show?, @submission.exercise, @submission.exercise))
|
||||
= row(label: 'submission.user', value: link_to_if(policy(@submission.user).show?, @submission.user, @submission.user))
|
||||
= row(label: 'submission.study_group', value: link_to_if(policy(@submission.study_group).show?, @submission.study_group, @submission.study_group))
|
||||
= row(label: 'submission.cause', value: t("submissions.causes.#{@submission.cause}"))
|
||||
= row(label: 'submission.score', value: @submission.score)
|
||||
|
||||
|
Reference in New Issue
Block a user