Sha256: e7ec1f6ab2d31a346b0b941f60ce55af71809e74fd6a99a4cf382b6027276961

Contents?: true

Size: 1.57 KB

Versions: 1

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

# TODO: mover a pg_scaffold

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

    # attr_accessor :profile_groups

    def initialize
      @global_domains = ['app.localhost.com', 'test.host', 'localhost']
      @navigators = [PgEngine::Navigator.new]
      @health_ssl_urls = []
      # @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

1 entries across 1 versions & 1 rubygems

Version Path
pg_rails-7.6.28 pg_engine/lib/pg_engine/configuracion.rb