Sha256: f0b9bd12aee5d464ad43e73d3ca3121e51ba453186b067c22335b33db611756d

Contents?: true

Size: 1.05 KB

Versions: 23

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Decidim
  # Defines a relation between a user and an assembly, and what kind of relation
  # does the user have.
  class AssemblyUserRole < ApplicationRecord
    include Traceable
    include Loggable

    belongs_to :user, foreign_key: "decidim_user_id", class_name: "Decidim::User", optional: true
    belongs_to :assembly, foreign_key: "decidim_assembly_id", class_name: "Decidim::Assembly", optional: true
    alias participatory_space assembly

    ROLES = %w(admin collaborator moderator valuator).freeze
    validates :role, inclusion: { in: ROLES }, uniqueness: { scope: [:user, :assembly] }
    validate :user_and_assembly_same_organization

    def self.log_presenter_class_for(_log)
      Decidim::Assemblies::AdminLog::AssemblyUserRolePresenter
    end

    private

    # Private: check if the process and the user have the same organization
    def user_and_assembly_same_organization
      return if !assembly || !user

      errors.add(:assembly, :invalid) unless user.organization == assembly.organization
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
decidim-assemblies-0.25.2 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.25.1 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.25.0 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.25.0.rc4 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.25.0.rc3 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.25.0.rc2 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.25.0.rc1 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.24.3 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.23.6 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.24.2 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.23.5 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.24.1 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.24.0 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.24.0.rc2 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.23.4 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.24.0.rc1 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.23.3 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.23.2 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.23.1 app/models/decidim/assembly_user_role.rb
decidim-assemblies-0.23.1.rc1 app/models/decidim/assembly_user_role.rb