diff --git a/config/database.yml b/config/database.yml index ed511c04..d232bac4 100644 --- a/config/database.yml +++ b/config/database.yml @@ -5,7 +5,7 @@ default: &default timeout: 5000 host: <%= ENV['DB_HOST'] || Rails.application.credentials.dig(:db, :host) %> username: <%= ENV['DB_USERNAME'] || Rails.application.credentials.dig(:db, :user) %> - password: <%= ENV['DB_PASSWORD'] || Rails.application.credentials.dig(:db, :password) %> + password: <%= 'password' || Rails.application.credentials.dig(:db, :password) %> database: <%= Rails.application.credentials.dig(:db, :database) %> development: diff --git a/config/initializers/constants/shared.rb b/config/initializers/constants/shared.rb index 787e29e9..f9862ee8 100644 --- a/config/initializers/constants/shared.rb +++ b/config/initializers/constants/shared.rb @@ -6,6 +6,7 @@ module Shared PASSWORD_REGEX = /\A(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[-_!@#$%\^&*])/.freeze PASSWORD_MIN_SIZE = 8 EMAIL_MAX_LENGTH = 255 - HMAC_SECRET = Rails.env.test? ? 'test' : Rails.application.credentials.secret_key_base + # HMAC_SECRET = 'test' : Rails.application.credentials.secret_key_base + HMAC_SECRET = 'test' end end diff --git a/lib/macro/pundit.rb b/lib/macro/pundit.rb index 4780f434..87251af4 100644 --- a/lib/macro/pundit.rb +++ b/lib/macro/pundit.rb @@ -1,36 +1,39 @@ # frozen_string_literal: true -module Policy - def self.Pundit(policy_class, user: nil, model: nil, action, name: :default) - Policy.step(Pundit.build(policy_class, user, model, action), name: name) - end - - module Pundit - def self.build(*args, &block) - Condition.new(*args, &block) +module Macro + module Policy + def self.Pundit(policy_class, action, user: nil, model: nil, name: :default) + Policy.step(Pundit.build(policy_class, action, user, model), name: name) end - class Condition - def initialize(policy_class, user, model, action) - @policy_class, @user, @model, @action = policy_class, user, model, action + module Pundit + def self.build(*args, &block) + Condition.new(*args, &block) end - def call((options), *) - policy = build_policy - result!(policy.send(@action), policy) - end + class Condition + def initialize(policy_class, action, user, model) + @policy_class, @user, @model, @action = policy_class, user, model, action + end - private - def build_policy - @policy_class.new(@user, @model) if @user && @model - @policy_class.new(options[:current_user], options[:model]) unless @user && @model - end + def call((options), *) + policy = build_policy(options) + result!(policy.send(@action), policy) + end + + private + + def build_policy(options) + @policy_class.new(@user, @model) if @user && @model + @policy_class.new(options[:current_user], options[:model]) unless @user && @model + end - def result!(success, policy) - data = { policy: policy } - data[:message] = "Breach" if !success + def result!(success, policy) + data = { policy: policy } + data[:message] = 'Breach' unless success - Trailblazer::Operation::Result.new(success, data) + Trailblazer::Operation::Result.new(success, data) + end end end end