Sha256: 1cfa65f89e367d7cbac5f3ceeef8a1559289981bdb665dca59158c3f83ed2367

Contents?: true

Size: 1.53 KB

Versions: 13

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

# TODO: mover a pg_scaffold

module PgEngine
  class Configuracion
    attr_accessor :users_controller, :global_domains, :navigators, :user_profiles

    # attr_accessor :profile_groups

    def initialize
      @global_domains = ['app.localhost.com', 'test.host', 'localhost']
      @navigators = [PgEngine::Navigator.new]
      # @profile_groups = [:account]
      @user_profiles = {
        account__owner: 0
      }
      user_profiles.merge!(
        user_accounts__read: 1000 + 1
      )
      # add_profiles(:user_accounts, 1000)
    end

    def add_profiles(key, base)
      # profile_groups.push(key)
      user_profiles.merge!(
        "#{key}__read": base + 1,
        "#{key}__update": base + 10,
        "#{key}__create": base + 30,
        "#{key}__archive": base + 50,
        "#{key}__export": base + 80,
        "#{key}__destroy": base + 100
      )

      return unless defined? UserAccount

      # :nocov:
      UserAccount.class_eval do
        enumerize :profiles, in: PgEngine.configuracion.user_profiles, multiple: true
      end
      # :nocov:
    end

    def profile_groups_options
      groups = user_profiles.keys.map { |v| v.to_s.split('__').first }.uniq

      groups = groups.excluding('account') unless Current.namespace == :admin

      groups.map do |group|
        options = user_profiles.keys.select { |va| va.starts_with?(group) }.map do |va|
          [va, I18n.t(va.to_s.split('__').last, scope: 'profile_member')]
        end
        { name: group, options: }
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
pg_rails-7.6.27 pg_engine/lib/pg_engine/configuracion.rb
pg_rails-7.6.26 pg_engine/lib/pg_engine/configuracion.rb
pg_rails-7.6.25 pg_engine/lib/pg_engine/configuracion.rb
pg_rails-7.6.24 pg_engine/lib/pg_engine/configuracion.rb
pg_rails-7.6.24.pre.5 pg_engine/lib/pg_engine/configuracion.rb
pg_rails-7.6.24.pre.4 pg_engine/lib/pg_engine/configuracion.rb
pg_rails-7.6.24.pre.3 pg_engine/lib/pg_engine/configuracion.rb
pg_rails-7.6.23 pg_engine/lib/pg_engine/configuracion.rb
pg_rails-7.6.22 pg_engine/lib/pg_engine/configuracion.rb
pg_rails-7.6.22.pre.3 pg_engine/lib/pg_engine/configuracion.rb
pg_rails-7.6.22.pre.2 pg_engine/lib/pg_engine/configuracion.rb
pg_rails-7.6.22.pre.1 pg_engine/lib/pg_engine/configuracion.rb
pg_rails-7.6.21 pg_engine/lib/pg_engine/configuracion.rb