Sha256: 81b6ff70c98be8c2c6e523ad95f5936c6991e7b326c11312c61f27666b55995a

Contents?: true

Size: 1.41 KB

Versions: 30

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module Decidim
  # A UserGroup is an organization of citizens
  class UserGroup < ApplicationRecord
    belongs_to :organization, foreign_key: "decidim_organization_id", class_name: "Decidim::Organization"

    has_many :memberships, class_name: "Decidim::UserGroupMembership", foreign_key: :decidim_user_group_id
    has_many :users, through: :memberships, class_name: "Decidim::User", foreign_key: :decidim_user_id

    validates :name, presence: true, uniqueness: { scope: :decidim_organization_id }
    validates :document_number, presence: true, uniqueness: { scope: :decidim_organization_id }
    validates :phone, presence: true
    validates :avatar, file_size: { less_than_or_equal_to: 5.megabytes }

    validate :correct_state

    mount_uploader :avatar, Decidim::AvatarUploader

    scope :verified, -> { where.not(verified_at: nil) }
    scope :rejected, -> { where.not(rejected_at: nil) }

    # Public: Checks if the user group is verified.
    def verified?
      verified_at.present?
    end

    # Public: Checks if the user group is rejected.
    def rejected?
      rejected_at.present?
    end

    # Public: Checks if the user group is pending.
    def pending?
      verified_at.blank? && rejected_at.blank?
    end

    private

    # Private: Checks if the state user group is correct.
    def correct_state
      errors.add(:base, :invalid) if verified? && rejected?
    end
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
decidim-core-0.6.8 app/models/decidim/user_group.rb
decidim-0.6.8 decidim-core/app/models/decidim/user_group.rb
decidim-core-0.6.7 app/models/decidim/user_group.rb
decidim-0.6.7 decidim-core/app/models/decidim/user_group.rb
decidim-core-0.6.6 app/models/decidim/user_group.rb
decidim-0.6.6 decidim-core/app/models/decidim/user_group.rb
decidim-core-0.6.5 app/models/decidim/user_group.rb
decidim-0.6.5 decidim-core/app/models/decidim/user_group.rb
decidim-core-0.6.4 app/models/decidim/user_group.rb
decidim-0.6.4 decidim-core/app/models/decidim/user_group.rb
decidim-core-0.6.3 app/models/decidim/user_group.rb
decidim-0.6.3 decidim-core/app/models/decidim/user_group.rb
decidim-core-0.6.2 app/models/decidim/user_group.rb
decidim-0.6.2 decidim-core/app/models/decidim/user_group.rb
decidim-core-0.6.1 app/models/decidim/user_group.rb
decidim-0.6.1 decidim-core/app/models/decidim/user_group.rb
decidim-core-0.6.0 app/models/decidim/user_group.rb
decidim-0.6.0 decidim-core/app/models/decidim/user_group.rb
decidim-core-0.5.1 app/models/decidim/user_group.rb
decidim-0.5.1 decidim-core/app/models/decidim/user_group.rb