Sha256: fadcb18d6ab6250261bd94e5b53166551bd0a6fdb46c229a0a9b9b2d1e593b31
Contents?: true
Size: 1.22 KB
Versions: 26
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true module Decidim # Defines a relation between a user and a participatory process, and what # kind of relation does the user has. class ParticipatoryProcessUserRole < ApplicationRecord include Traceable include Loggable belongs_to :user, foreign_key: "decidim_user_id", class_name: "Decidim::User", optional: true belongs_to :participatory_process, foreign_key: "decidim_participatory_process_id", class_name: "Decidim::ParticipatoryProcess", optional: true alias participatory_space participatory_process ROLES = %w(admin collaborator moderator).freeze validates :role, inclusion: { in: ROLES }, uniqueness: { scope: [:user, :participatory_process] } validate :user_and_participatory_process_same_organization def self.log_presenter_class_for(_log) Decidim::ParticipatoryProcesses::AdminLog::ParticipatoryProcessUserRolePresenter end private # Private: check if the process and the user have the same organization def user_and_participatory_process_same_organization return if !participatory_process || !user errors.add(:participatory_process, :invalid) unless user.organization == participatory_process.organization end end end
Version data entries
26 entries across 26 versions & 1 rubygems