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

Version Path
decidim-core-0.18.1 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.17.2 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.18.0 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.17.1 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.16.1 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.17.0 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.16.0 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.15.2 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.15.1 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.15.0 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.14.4 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.14.3 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.14.2 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.14.1 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.13.1 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.12.2 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.13.0 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.12.1 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.13.0.pre1 app/models/decidim/participatory_process_user_role.rb
decidim-core-0.12.0 app/models/decidim/participatory_process_user_role.rb