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:
Sebastian Serth
2019-02-14 18:09:21 +01:00
parent 532416b9d3
commit 6e03939c10
8 changed files with 29 additions and 20 deletions

View File

@ -168,6 +168,7 @@ module Lti
end end
group.users |= [@current_user] # add current user if not already member of the group group.users |= [@current_user] # add current user if not already member of the group
group.save group.save
session[:study_group_id] = group.id
end end
def set_embedding_options def set_embedding_options

View File

@ -16,7 +16,8 @@ module SubmissionParameters
current_user_id = current_user.id current_user_id = current_user.id
current_user_class_name = current_user.class.name current_user_class_name = current_user.class.name
end 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) reject_illegal_file_attributes!(submission_params)
submission_params submission_params
end end

View File

@ -83,17 +83,10 @@ class RequestForCommentsController < ApplicationController
authorize! authorize!
end end
# GET /request_for_comments/new
def new
@request_for_comment = RequestForComment.new
authorize!
end
# GET /request_for_comments/1/edit # GET /request_for_comments/1/edit
def edit def edit
end end
# POST /request_for_comments
# POST /request_for_comments.json # POST /request_for_comments.json
def create def create
# Consider all requests as JSON # 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. # Never trust parameters from the scary internet, only allow the white list through.
def request_for_comment_params 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. # 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) 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 end
def comment_params def comment_params

View File

@ -1,12 +1,12 @@
# frozen_string_literal: true # frozen_string_literal: true
class StudyGroup < ApplicationRecord class StudyGroup < ApplicationRecord
has_many :study_group_memberships has_many :study_group_memberships, dependent: :destroy
# Use `ExternalUser` as `source_type` for now. # Use `ExternalUser` as `source_type` for now.
# Using `User` will lead ActiveRecord to access the inexistent table `users`. # Using `User` will lead ActiveRecord to access the inexistent table `users`.
# Issue created: https://github.com/rails/rails/issues/34531 # Issue created: https://github.com/rails/rails/issues/34531
has_many :users, through: :study_group_memberships, source_type: 'ExternalUser' has_many :users, through: :study_group_memberships, source_type: 'ExternalUser'
has_many :submissions has_many :submissions, dependent: :nullify
belongs_to :consumer belongs_to :consumer
def to_s def to_s

View File

@ -25,6 +25,22 @@ class ApplicationPolicy
end end
private :no_one 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) def initialize(user, record)
@user = user @user = user
@record = record @record = record

View File

@ -12,14 +12,8 @@ class SubmissionPolicy < ApplicationPolicy
admin? admin?
end 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 def show_study_group?
teacher? && everyone_in_study_group admin? || teacher_in_study_group
end end
private :teacher_in_study_group
end end

View File

@ -9,6 +9,9 @@
- testruns = Testrun.where(:submission_id => @request_for_comment.submission) - testruns = Testrun.where(:submission_id => @request_for_comment.submission)
= link_to_if(policy(user).show?, user.displayname, user) = link_to_if(policy(user).show?, user.displayname, user)
| | #{@request_for_comment.created_at.localtime} | | #{@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 .rfc
.description .description
h5 h5

View File

@ -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.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.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.cause', value: t("submissions.causes.#{@submission.cause}"))
= row(label: 'submission.score', value: @submission.score) = row(label: 'submission.score', value: @submission.score)