Limit programming groups to two people
* adapt text on programming_groups/new site * in German change from 'Sie' to 'du'
This commit is contained in:

committed by
Sebastian Serth

parent
0e4a239960
commit
97764bd02e
@ -11,7 +11,8 @@ class ProgrammingGroup < ApplicationRecord
|
||||
has_many :runners, as: :contributor, dependent: :destroy
|
||||
belongs_to :exercise
|
||||
|
||||
validate :group_size
|
||||
validate :min_group_size
|
||||
validate :max_group_size
|
||||
validate :no_erroneous_users
|
||||
accepts_nested_attributes_for :programming_group_memberships
|
||||
|
||||
@ -71,12 +72,18 @@ class ProgrammingGroup < ApplicationRecord
|
||||
|
||||
private
|
||||
|
||||
def group_size
|
||||
def min_group_size
|
||||
if users.size < 2
|
||||
errors.add(:base, :size_too_small)
|
||||
end
|
||||
end
|
||||
|
||||
def max_group_size
|
||||
if users.size > 2
|
||||
errors.add(:base, :size_too_large)
|
||||
end
|
||||
end
|
||||
|
||||
def no_erroneous_users
|
||||
@erroneous_users.each do |partner_id|
|
||||
errors.add(:base, :invalid_partner_id, partner_id:)
|
||||
|
Reference in New Issue
Block a user