mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-10 00:11:22 +08:00
25 lines
855 B
Ruby
25 lines
855 B
Ruby
# frozen_string_literal: true
|
|
|
|
class TeamSharedObject < ApplicationRecord
|
|
enum permission_level: Extends::SHARED_OBJECTS_PERMISSION_LEVELS.except(:not_shared)
|
|
|
|
belongs_to :team
|
|
belongs_to :shared_object, polymorphic: true, inverse_of: :team_shared_objects
|
|
belongs_to :shared_repository,
|
|
(lambda do |team_shared_object|
|
|
team_shared_object.shared_object_type == 'RepositoryBase' ? self : none
|
|
end),
|
|
optional: true,
|
|
class_name: 'RepositoryBase',
|
|
foreign_key: :shared_object_id
|
|
|
|
validates :permission_level, presence: true
|
|
validates :shared_object_type, uniqueness: { scope: %i(shared_object_id team_id) }
|
|
validate :team_cannot_be_the_same
|
|
|
|
private
|
|
|
|
def team_cannot_be_the_same
|
|
errors.add(:team_id, :same_team) if shared_object.team.id == team_id
|
|
end
|
|
end
|