Sha256: f1457850aa2c39d01aba4db7eb1a7351e3f1053141ea818451392ca78f695fd8
Contents?: true
Size: 1010 Bytes
Versions: 37
Compression:
Stored size: 1010 Bytes
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 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 ROLES = %w(admin collaborator moderator).freeze validates :role, inclusion: { in: ROLES }, uniqueness: { scope: [:user, :participatory_process] } validate :user_and_participatory_process_same_organization 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
37 entries across 37 versions & 2 rubygems