Add CRUD operations for Programming Groups
* Correct sorting in table * Modify page when nested in exercises * Fix links between pages * Link from statistics page to programming_groups/index * Link from submission page to programming_groups/<id> * Allow filtering for exercise ID on ProgrammingGroup#index * Add search fields for internal and external user id on pg/index
This commit is contained in:

committed by
Sebastian Serth

parent
f1ca5da44d
commit
79ce069f68
@ -36,6 +36,7 @@ class Exercise < ApplicationRecord
|
||||
has_many :request_for_comments
|
||||
|
||||
scope :with_submissions, -> { where('id IN (SELECT exercise_id FROM submissions)') }
|
||||
scope :with_programming_groups, -> { where('id IN (SELECT exercise_id FROM programming_groups)') }
|
||||
|
||||
validate :valid_main_file?
|
||||
validate :valid_submission_deadlines?
|
||||
@ -612,7 +613,7 @@ class Exercise < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.ransackable_attributes(_auth_object = nil)
|
||||
%w[title internal_title]
|
||||
%w[title id internal_title]
|
||||
end
|
||||
|
||||
def self.ransackable_associations(_auth_object = nil)
|
||||
|
@ -9,10 +9,10 @@ class ProgrammingGroup < ApplicationRecord
|
||||
has_many :internal_users, through: :programming_group_memberships, source_type: 'InternalUser', source: :user
|
||||
has_many :testruns, through: :submissions
|
||||
has_many :runners, as: :contributor, dependent: :destroy
|
||||
has_many :events
|
||||
has_many :events_synchronized_editor, class_name: 'Event::SynchronizedEditor'
|
||||
has_many :pair_programming_exercise_feedbacks
|
||||
has_many :pair_programming_waiting_users
|
||||
has_many :events, dependent: :destroy
|
||||
has_many :events_synchronized_editor, class_name: 'Event::SynchronizedEditor', dependent: :destroy
|
||||
has_many :pair_programming_exercise_feedbacks, dependent: :destroy
|
||||
has_many :pair_programming_waiting_users, dependent: :destroy
|
||||
belongs_to :exercise
|
||||
|
||||
validate :min_group_size
|
||||
@ -20,11 +20,6 @@ class ProgrammingGroup < ApplicationRecord
|
||||
validate :no_erroneous_users
|
||||
accepts_nested_attributes_for :programming_group_memberships
|
||||
|
||||
def initialize(attributes = nil)
|
||||
@erroneous_users = []
|
||||
super
|
||||
end
|
||||
|
||||
def external_user?
|
||||
false
|
||||
end
|
||||
@ -76,15 +71,27 @@ class ProgrammingGroup < ApplicationRecord
|
||||
def users=(users)
|
||||
self.internal_users = []
|
||||
self.external_users = []
|
||||
users.each do |user|
|
||||
next @erroneous_users << user unless user.is_a?(User)
|
||||
users&.each do |user|
|
||||
next erroneous_users << user unless user.is_a?(User)
|
||||
|
||||
add(user)
|
||||
end
|
||||
end
|
||||
|
||||
def self.ransackable_associations(_auth_object = nil)
|
||||
%w[exercise programming_group_memberships]
|
||||
end
|
||||
|
||||
def self.ransortable_attributes(_auth_object = nil)
|
||||
%w[id created_at]
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def erroneous_users
|
||||
@erroneous_users ||= []
|
||||
end
|
||||
|
||||
def min_group_size
|
||||
if users.size < 2
|
||||
errors.add(:base, :size_too_small)
|
||||
@ -98,7 +105,7 @@ class ProgrammingGroup < ApplicationRecord
|
||||
end
|
||||
|
||||
def no_erroneous_users
|
||||
@erroneous_users.each do |partner_id|
|
||||
erroneous_users.each do |partner_id|
|
||||
errors.add(:base, :invalid_partner_id, partner_id:)
|
||||
end
|
||||
end
|
||||
|
@ -12,4 +12,8 @@ class ProgrammingGroupMembership < ApplicationRecord
|
||||
errors.add(:base, :already_exists, id_with_type: user.id_with_type)
|
||||
end
|
||||
end
|
||||
|
||||
def self.ransackable_associations(_auth_object = nil)
|
||||
%w[user]
|
||||
end
|
||||
end
|
||||
|
@ -111,9 +111,9 @@ class User < ApplicationRecord
|
||||
|
||||
def self.ransackable_attributes(auth_object)
|
||||
if auth_object.present? && auth_object.admin?
|
||||
%w[name email external_id consumer_id platform_admin]
|
||||
%w[name email external_id consumer_id platform_admin id]
|
||||
else
|
||||
%w[name external_id]
|
||||
%w[name external_id id]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user