Add ProgrammingGroup & ProgrammingGroupMembership

* User can create programming group with other users for exercise
* Submission is shared in a group
* Also adjust specs
This commit is contained in:
kiragrammel
2023-08-10 17:07:04 +02:00
committed by Sebastian Serth
parent 0234414bae
commit 319c3ab3b4
42 changed files with 715 additions and 276 deletions

View File

@ -0,0 +1,15 @@
# frozen_string_literal: true
class ProgrammingGroupMembership < ApplicationRecord
belongs_to :user, polymorphic: true
belongs_to :programming_group
validate :unique_membership_for_exercise
validates :user_id, uniqueness: {scope: %i[programming_group_id user_type]}
def unique_membership_for_exercise
if user.programming_groups.where(exercise: programming_group.exercise).any?
errors.add(:base, :already_exists, id_with_type: user.id_with_type)
end
end
end