pg_rails 7.6.21.pre.11 → 7.6.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/pg_associable/app/helpers/pg_associable/form_builder_methods.rb +1 -0
  3. data/pg_engine/app/controllers/pg_engine/base_controller.rb +2 -0
  4. data/pg_engine/app/controllers/pg_engine/base_users_controller.rb +2 -0
  5. data/pg_engine/app/controllers/tenant/user_accounts_controller.rb +7 -16
  6. data/pg_engine/app/controllers/users/accounts_controller.rb +1 -1
  7. data/pg_engine/app/controllers/users/invitations_controller.rb +10 -4
  8. data/pg_engine/app/controllers/users/registrations_controller.rb +0 -2
  9. data/pg_engine/app/decorators/account_decorator.rb +3 -1
  10. data/pg_engine/app/decorators/pg_engine/base_record_decorator.rb +3 -2
  11. data/pg_engine/app/decorators/user_account_decorator.rb +4 -1
  12. data/pg_engine/app/helpers/pg_engine/flash_helper.rb +1 -1
  13. data/pg_engine/app/lib/pg_engine/default_url_options.rb +16 -12
  14. data/pg_engine/app/mailers/pg_engine/base_devise_mailer.rb +4 -0
  15. data/pg_engine/app/mailers/pg_engine/base_mailer.rb +16 -1
  16. data/pg_engine/app/models/account.rb +2 -6
  17. data/pg_engine/app/models/current.rb +1 -2
  18. data/pg_engine/app/models/email.rb +1 -1
  19. data/pg_engine/app/models/user.rb +6 -8
  20. data/pg_engine/app/models/user_account.rb +0 -4
  21. data/pg_engine/app/policies/account_policy.rb +9 -4
  22. data/pg_engine/app/policies/user_account_policy.rb +1 -5
  23. data/pg_engine/app/views/layouts/_logo.html.slim +8 -0
  24. data/pg_engine/app/views/users/accounts/show.html.slim +4 -3
  25. data/pg_engine/config/locales/es.rb +2 -0
  26. data/pg_engine/config/locales/es.yml +7 -2
  27. data/pg_engine/lib/pg_engine/active_job_extensions.rb +15 -0
  28. data/pg_engine/lib/pg_engine/configuracion.rb +2 -0
  29. data/pg_engine/lib/pg_engine/engine.rb +0 -3
  30. data/pg_engine/lib/pg_engine/site_brand.rb +39 -0
  31. data/pg_engine/lib/pg_engine/test/dummy_brand.rb +81 -0
  32. data/pg_engine/lib/pg_engine.rb +11 -1
  33. data/pg_engine/spec/factories/users.rb +6 -3
  34. data/pg_engine/spec/mailers/pg_engine/base_mailer_spec.rb +53 -0
  35. data/pg_engine/spec/requests/devise/invitations_spec.rb +13 -4
  36. data/pg_engine/spec/requests/users/accounts_spec.rb +19 -10
  37. data/pg_engine/spec/requests/users/base_controller_spec.rb +13 -12
  38. data/pg_engine/spec/requests/users/registrations_spec.rb +19 -18
  39. data/pg_engine/spec/requests/users/user_accounts_spec.rb +37 -1
  40. data/pg_layout/app/views/devise/invitations/new.html.erb +2 -1
  41. data/pg_layout/app/views/devise/mailer/invitation_instructions.html.erb +1 -1
  42. data/pg_layout/app/views/devise/mailer/invitation_instructions.text.erb +1 -1
  43. data/pg_layout/app/views/layouts/pg_layout/base.html.slim +1 -1
  44. data/pg_layout/app/views/layouts/pg_layout/container_logo.html.slim +2 -3
  45. data/pg_layout/app/views/layouts/pg_layout/containerized.html.slim +2 -1
  46. data/pg_layout/app/views/layouts/pg_layout/devise_mailer.html.slim +3 -7
  47. data/pg_layout/app/views/layouts/pg_layout/devise_mailer.text.erb +2 -4
  48. data/pg_layout/app/views/layouts/pg_layout/mailer.html.slim +3 -7
  49. data/pg_layout/app/views/layouts/pg_layout/mailer.text.erb +2 -4
  50. data/pg_layout/app/views/pg_layout/_navbar.html.slim +7 -8
  51. data/pg_layout/app/views/pg_layout/_sidebar.html.slim +1 -1
  52. data/pg_layout/app/views/pg_layout/_sidebar_mobile.html.slim +1 -1
  53. data/pg_layout/app/views/pg_layout/_signed_in_links.html.slim +4 -4
  54. data/pg_rails/lib/version.rb +1 -1
  55. metadata +7 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f442d786ae4cf36b38c87e72307bb1fe1dfd4c77fb2e697566adfb1d48bbb1b6
4
- data.tar.gz: d1028638b9acd8817adbc33a0680f270c46b96c1b9f96d66d6ac964d46b96eaf
3
+ metadata.gz: 3b28992b6ab1d70765599e7b9cb91d80c7205e4568a8d3de1bdab30b475c6e87
4
+ data.tar.gz: 3bcd1df50768a9d0a97e6e33f747e2fc9981d0b8ceedba6e63270be3d9ae35eb
5
5
  SHA512:
6
- metadata.gz: 184210806bdd1ed1c9c4e4e6f2e4d481751cae4375f1cf5df01b74b66ff66bc685e8cb01ad5405ad63e6e147c9eebf68a5795851040612ee1c830d4f9acc2261
7
- data.tar.gz: 44544f1fd6549dc40ca21b0666a500538567320bbb6170e29ffc0a1773ae31e8c2c5a9faf869137465dce6c12f29a8a42d765d4d00dd3cf9e34f4f852f2f9821
6
+ metadata.gz: ef507cf518054e617a1678d7b29df9dc3bf24b916c26475a835e168054fd1418d794a5210187c7604b018f0d070b016dcbaf88e8a259230db791015164a56b07
7
+ data.tar.gz: c8b47adeb7ee28e9da2efe5f61a1bd071de1e415654639b4a13d288becac7d752eea6b526a943342dcfde95fd0e323b1716ded877c9cf1e810136b3c40a6c7da
@@ -53,6 +53,7 @@ module PgAssociable
53
53
  reflect = associacion_for(atributo)
54
54
  fkid = object.send(reflect.foreign_key)
55
55
  if fkid
56
+ # FIXME: write some tests
56
57
  collection = collection.or(klass.where(id: fkid))
57
58
  end
58
59
 
@@ -16,6 +16,8 @@ module PgEngine
16
16
  Current.user = current_user
17
17
  Current.controller = self
18
18
 
19
+ Current.app_name = PgEngine.site_brand.detect(request)
20
+
19
21
  if Current.user.present?
20
22
  active_user_accounts = Current.user.user_accounts.ua_active.to_a
21
23
  if ActsAsTenant.current_tenant.present? && !Rails.env.test?
@@ -6,6 +6,8 @@ module PgEngine
6
6
  # TODO!: requisito que esto esté seteado
7
7
  Current.namespace = :users
8
8
 
9
+ # FIXME: ver que esto esté en todas las pantallas en que esté signed in, ej: en la home y en mi perfil
10
+ # desduplicar en tenant controller
9
11
  @other_active_accounts = ActsAsTenant.without_tenant do
10
12
  Current.user.user_accounts.ua_active.to_a
11
13
  end
@@ -12,24 +12,11 @@ module Tenant
12
12
  before_action do
13
13
  @sidebar = false
14
14
  unless modal_targeted? || frame_embedded?
15
- add_breadcrumb Account.model_name.human(count: 2), ->(h) { h.users_accounts_path(tid: nil) }
15
+ add_breadcrumb Account.nombre_plural, ->(h) { h.users_accounts_path(tid: nil) }
16
16
  add_breadcrumb ActsAsTenant.current_tenant, users_account_path(Current.account, tid: nil)
17
17
  end
18
18
  unless modal_targeted?
19
- add_breadcrumb 'Usuarios', tenant_user_accounts_path
20
- end
21
- @actions = [
22
- [
23
- 'Agregar usuario',
24
- new_user_invitation_path(tid: Current.tid),
25
- { class: 'me-1 btn btn-warning btn-sm', 'data-turbo-frame': :_top }
26
- ]
27
- ]
28
- end
29
-
30
- before_action do
31
- unless modal_targeted?
32
- # add_breadcrumb @user_account.account, users_account_path(@user_account.account, tid: nil)
19
+ add_breadcrumb UserAccount.nombre_plural, tenant_user_accounts_path
33
20
  end
34
21
  end
35
22
 
@@ -50,7 +37,11 @@ module Tenant
50
37
  end
51
38
 
52
39
  def atributos_para_listar
53
- %i[user user_email_f profiles_f estado_f]
40
+ if Current.user_account_owner?
41
+ %i[user user_email_f profiles_f estado_f]
42
+ else
43
+ %i[user user_email_f]
44
+ end
54
45
  end
55
46
  end
56
47
  end
@@ -15,7 +15,7 @@ module Users
15
15
  self.clase_modelo = Account
16
16
  self.skip_default_breadcrumb = true
17
17
 
18
- add_breadcrumb Account.model_name.human(count: 2), ->(h) { h.users_accounts_path(tid: nil) }
18
+ add_breadcrumb Account.nombre_plural, ->(h) { h.users_accounts_path(tid: nil) }
19
19
 
20
20
  layout :set_layout
21
21
  def set_layout
@@ -1,14 +1,20 @@
1
1
  module Users
2
2
  class InvitationsController < Devise::InvitationsController
3
3
  include PgEngine::TenantHelper
4
+
4
5
  before_action only: %i[new create] do
5
6
  set_tenant_from_params_or_fail!
6
7
 
7
- add_breadcrumb Account.model_name.human(count: 2), ->(h) { h.users_accounts_path(tid: nil) }
8
+ authorize UserAccount
9
+
10
+ add_breadcrumb Account.nombre_plural, users_accounts_path(tid: nil)
8
11
  add_breadcrumb ActsAsTenant.current_tenant, users_account_path(ActsAsTenant.current_tenant)
9
- add_breadcrumb 'Usuarios'
10
- add_breadcrumb 'Agregar usuario'
11
- @sidebar = false
12
+ add_breadcrumb UserAccount.nombre_plural
13
+ add_breadcrumb UserAccount.new.decorate.submit_default_value
14
+
15
+ # Porque el link for new no tiene turbo-frame="_top"
16
+ @turbo_page_requires_reload = true
17
+
12
18
  @no_main_frame = true
13
19
  @container_class = 'container border pb-3 my-3'
14
20
  @container_style = 'max-width: 50em; xborder-left: 1px solid grey'
@@ -1,7 +1,6 @@
1
1
  module Users
2
2
  class RegistrationsController < Devise::RegistrationsController
3
3
  before_action do
4
- @sidebar = false
5
4
  authorize resource, nil, policy_class: UserRegistrationPolicy
6
5
  end
7
6
 
@@ -12,7 +11,6 @@ module Users
12
11
  resource.save
13
12
  yield resource if block_given?
14
13
  if resource.persisted?
15
- # FIXME: no va más
16
14
  create_account_for(resource) if ActsAsTenant.current_tenant.blank?
17
15
 
18
16
  expire_data_after_sign_in!
@@ -22,9 +22,11 @@ class AccountDecorator < PgEngine::BaseRecordDecorator
22
22
  ua.reject_invitation_link].compact.join.html_safe
23
23
  end
24
24
 
25
- def show_link(text: 'Usuarios', klass: 'btn-secondary')
25
+ def show_link(text: nil, klass: 'btn-secondary')
26
26
  return unless Pundit.policy!(Current.user, object).show?
27
27
 
28
+ text = 'Usuarios' # rubocop:disable Lint/ShadowedArgument
29
+
28
30
  helpers.content_tag :span do
29
31
  helpers.link_to object_url, class: "btn btn-sm #{klass}" do
30
32
  helpers.content_tag(:span, nil, class: clase_icono('person')) + text
@@ -27,10 +27,11 @@ module PgEngine
27
27
  truncate(object.to_s)
28
28
  end
29
29
 
30
+ # Texto para la opción de crear en los pg_associables
30
31
  def text_for_new
31
32
  klass = object.class
32
33
  verb = klass.gender == 'f' ? 'Nueva' : 'Nuevo'
33
- "#{verb} #{klass.model_name.human.downcase}"
34
+ "#{verb} #{klass.nombre_singular.downcase}"
34
35
  end
35
36
 
36
37
  # rubocop:disable Style/MissingRespondToMissing
@@ -200,7 +201,7 @@ module PgEngine
200
201
  # actionview-7.1.3.2/lib/action_view/helpers/form_helper.rb
201
202
  def submit_default_value
202
203
  key = :create
203
- model = object.model_name.human.downcase
204
+ model = object.class.nombre_singular.downcase
204
205
  defaults = []
205
206
  defaults << :"helpers.submit.#{object.model_name.i18n_key}.#{key}"
206
207
  defaults << :"helpers.submit.#{key}"
@@ -4,6 +4,9 @@
4
4
 
5
5
  class UserAccountDecorator < PgEngine::BaseRecordDecorator
6
6
  delegate_all
7
+ def new_object_url
8
+ helpers.new_user_invitation_path
9
+ end
7
10
 
8
11
  def ingresar_link
9
12
  return unless Pundit.policy!(Current.user, object).ingresar?
@@ -44,7 +47,7 @@ class UserAccountDecorator < PgEngine::BaseRecordDecorator
44
47
  h.link_to [:update_invitation, :users, account, { sign_off: 1 }].flatten,
45
48
  'data-turbo-method': :put,
46
49
  class: 'btn btn-sm btn-outline-danger' do
47
- 'Dejar la cuenta'
50
+ I18n.t('pg_engine.leave_account', model: Account)
48
51
  end
49
52
  end
50
53
 
@@ -10,7 +10,7 @@ module PgEngine
10
10
 
11
11
  def render_turbo_stream_title
12
12
  title = [breadcrumbs.last&.name, ActsAsTenant.current_tenant,
13
- I18n.t(Current.app_name, scope: 'app_name')].compact.join(' - ')
13
+ PgEngine.site_brand.name].compact.join(' - ')
14
14
  turbo_stream.update_all 'title', title
15
15
  end
16
16
  end
@@ -1,21 +1,25 @@
1
1
  module PgEngine
2
+ # Setea el tid
3
+ #
4
+ # Se usa en controllers, y en todo contexto dentro de la webapp
5
+ # NO se usa en Mailers, ya que no requieren tid
2
6
  module DefaultUrlOptions
3
- # Aunque parece intuitivo que se podría definir solamente url_options,
4
- # es importante que default_url_options también esté definido
7
+ # Aparentemente es necesario definir url_options cuando los parámetros
8
+ # pueden cambiar a lo largo del lifecycle de la request
5
9
  def url_options
6
- if Current.active_user_account
7
- super.merge(tid: Current.active_user_account.to_param)
8
- else
9
- super.merge(tid: nil)
10
- end
10
+ super.merge(PgEngine.site_brand.default_url_options).merge(tid: _current_tid)
11
11
  end
12
12
 
13
+ # Aunque parece intuitivo que se podría definir solamente url_options,
14
+ # es importante que default_url_options también esté definido
13
15
  def default_url_options
14
- if Current.active_user_account
15
- { tid: Current.active_user_account.to_param }
16
- else
17
- { tid: nil }
18
- end
16
+ PgEngine.site_brand.default_url_options.merge(tid: _current_tid)
17
+ end
18
+
19
+ def _current_tid
20
+ return unless Current.active_user_account
21
+
22
+ Current.active_user_account.to_param
19
23
  end
20
24
  end
21
25
  end
@@ -1,5 +1,9 @@
1
1
  module PgEngine
2
2
  class BaseDeviseMailer < ApplicationMailer
3
3
  layout 'pg_layout/devise_mailer'
4
+
5
+ def logo_footer_name
6
+ PgEngine.site_brand.mailer_devise_footer_image_src
7
+ end
4
8
  end
5
9
  end
@@ -2,13 +2,28 @@ module PgEngine
2
2
  class BaseMailer < ActionMailer::Base # rubocop:disable Rails/ApplicationMailer
3
3
  class MailNotDelivered < StandardError; end
4
4
 
5
+ def default_url_options
6
+ super.merge(PgEngine.site_brand.default_url_options)
7
+ end
8
+
5
9
  before_action { @email_object = params[:email_object] }
6
10
 
11
+ before_action do
12
+ png_data = File.read(File.expand_path("app/assets/images/#{logo_footer_name}", Rails.root))
13
+ attachments.inline[logo_footer_name] = png_data
14
+ @footer_image_src = attachments[logo_footer_name].url
15
+ end
16
+
17
+ def logo_footer_name
18
+ PgEngine.site_brand.mailer_base_footer_image_src
19
+ end
20
+
7
21
  default from: lambda { |_mailer|
8
22
  if @email_object.present?
9
23
  email_address_with_name(@email_object.from_address, @email_object.from_name)
10
24
  else
11
- email_address_with_name(ENV.fetch('DEFAULT_MAIL_FROM'), ENV.fetch('DEFAULT_MAIL_FROM_NAME'))
25
+ email_address_with_name(PgEngine.site_brand.default_mail_from,
26
+ PgEngine.site_brand.default_mail_from_name)
12
27
  end
13
28
  },
14
29
  reply_to: ->(_mailer) { @email_object.reply_to if @email_object.present? },
@@ -30,7 +30,7 @@ class Account < ApplicationRecord
30
30
  belongs_to :creado_por, optional: true, class_name: 'User'
31
31
  belongs_to :actualizado_por, optional: true, class_name: 'User'
32
32
 
33
- enumerize :plan, in: { factura: 0, procura: 1 }
33
+ enumerize :plan, in: PgEngine.site_brand.account_plan_options
34
34
 
35
35
  validates :plan, :nombre, presence: true
36
36
 
@@ -56,10 +56,6 @@ class Account < ApplicationRecord
56
56
  self.plan = 0 if plan.blank?
57
57
  end
58
58
 
59
- def self.gender
60
- 'm'
61
- end
62
-
63
59
  def to_s
64
60
  # TODO: nombre_in_database?
65
61
  nombre
@@ -71,7 +67,7 @@ class Account < ApplicationRecord
71
67
  user_accounts.ua_active.owners.first&.user
72
68
  end
73
69
 
74
- raise PgEngine::Error, 'orphan account' if @owner.nil?
70
+ raise PgEngine::Error, 'orphan account' if @owner.nil? && Current.namespace != :admin
75
71
 
76
72
  @owner
77
73
  end
@@ -1,6 +1,5 @@
1
1
  class Current < ActiveSupport::CurrentAttributes
2
- attribute :user, :namespace, :controller, :active_user_account
3
- attribute :app_name, default: :procura
2
+ attribute :user, :namespace, :controller, :active_user_account, :app_name
4
3
  # attribute :request_id, :user_agent, :ip_address
5
4
 
6
5
  # resets { Time.zone = nil }
@@ -77,7 +77,7 @@ class Email < ApplicationRecord
77
77
  format: { with: /\A[^\n<>&]*\z/, message: 'contiene caracteres inválidos' }
78
78
 
79
79
  after_initialize do
80
- self.from_address = ENV.fetch('DEFAULT_MAIL_FROM') if from_address.blank?
80
+ self.from_address = PgEngine.site_brand.default_mail_from if from_address.blank?
81
81
  end
82
82
 
83
83
  # validates_format_of :subject, with: /\A[[[:alpha:]]\(\)\w\s.,;!¡?¿-]+\z/
@@ -89,14 +89,6 @@ class User < ApplicationRecord
89
89
  user_accounts.first.invitation_status = :ist_invited
90
90
  end
91
91
 
92
- def invited_to_app
93
- user_accounts.first.account.plan || 'procura'
94
- rescue StandardError => e
95
- pg_err(e)
96
-
97
- 'procura'
98
- end
99
-
100
92
  attr_accessor :orphan
101
93
 
102
94
  def active_for_authentication?
@@ -140,6 +132,12 @@ class User < ApplicationRecord
140
132
 
141
133
  def first_first_name
142
134
  nombre.strip.split.first.presence || to_s
135
+ rescue StandardError => e
136
+ # :nocov:
137
+ pg_warn(e)
138
+
139
+ to_s
140
+ # :nocov:
143
141
  end
144
142
 
145
143
  class Error < PgEngine::Error; end
@@ -32,10 +32,6 @@ class UserAccount < ApplicationRecord
32
32
 
33
33
  acts_as_tenant :account
34
34
 
35
- def self.gender
36
- 'f'
37
- end
38
-
39
35
  belongs_to :creado_por, optional: true, class_name: 'User'
40
36
  belongs_to :actualizado_por, optional: true, class_name: 'User'
41
37
 
@@ -37,7 +37,7 @@ class AccountPolicy < ApplicationPolicy
37
37
  end
38
38
 
39
39
  def show?
40
- base_access_to_record?
40
+ Current.namespace == :admin || (base_access_to_record? && !user_account.ua_invite_pending?)
41
41
  end
42
42
 
43
43
  def index?
@@ -49,11 +49,16 @@ class AccountPolicy < ApplicationPolicy
49
49
  end
50
50
 
51
51
  def base_access_to_record?
52
- ua = user.user_account_for(record)
53
- Current.namespace == :admin || (ua.present? && !ua.ua_invite_pending?)
52
+ Current.namespace == :admin || user_belongs_to_account?
54
53
  end
55
54
 
56
55
  def user_belongs_to_account?
57
- user.user_account_for(record).present?
56
+ user_account.present?
57
+ end
58
+
59
+ private
60
+
61
+ def user_account
62
+ @user_account ||= user.user_account_for(record)
58
63
  end
59
64
  end
@@ -17,10 +17,6 @@ class UserAccountPolicy < ApplicationPolicy
17
17
  end
18
18
  end
19
19
 
20
- def index?
21
- super && (Current.namespace == :admin || Current.active_user_account.present?)
22
- end
23
-
24
20
  def sign_off?
25
21
  user_is_user_account_user? &&
26
22
  !record.ua_invite_pending? &&
@@ -28,7 +24,7 @@ class UserAccountPolicy < ApplicationPolicy
28
24
  end
29
25
 
30
26
  def puede_crear?
31
- Current.namespace == :admin
27
+ Current.namespace == :admin || Current.user_account_owner?
32
28
  end
33
29
 
34
30
  def accept_invitation_link?
@@ -0,0 +1,8 @@
1
+ - href = Current.tid.present? ? tenant_root_path(tid: Current.tid) : root_path
2
+ a.navbar-brand href="#{ href }"
3
+ = image_tag(PgEngine.site_brand.logo_navbar_url, alt: PgEngine.site_brand.name)
4
+
5
+ css:
6
+ a.navbar-brand img {
7
+ max-height: 31px;
8
+ }
@@ -19,6 +19,7 @@
19
19
  - if @user_account.membership_status.ms_disabled?
20
20
  p.text-danger Deshabilitado
21
21
 
22
- - if @account.owner == Current.user
23
- = turbo_frame_tag 'embedded__user_accounts',
24
- src: tenant_user_accounts_path(tid: Current.user.user_account_for(@account).to_param)
22
+ - ActsAsTenant.with_tenant(@account) do
23
+ - if policy(UserAccount).index?
24
+ = turbo_frame_tag 'embedded__user_accounts',
25
+ src: tenant_user_accounts_path(tid: Current.user.user_account_for(@account).to_param)
@@ -18,6 +18,8 @@ end
18
18
  {
19
19
  :es => {
20
20
  pg_engine: {
21
+ leave_account: PgEngine::I18nRules.rule('Dejar %{genderize(la,el)} %{singular_model}'),
22
+
21
23
  resource_destroyed: PgEngine::I18nRules.rule("Se eliminó %{genderize(la,el)} %{singular_model}"),
22
24
  resource_not_destroyed: PgEngine::I18nRules.rule("Hubo un error al intentar eliminar %{genderize(la,el)} %{singular_model}"),
23
25
  resource_not_updated: PgEngine::I18nRules.rule("Hubo un error al intentar actualizar %{genderize(la,el)} %{singular_model}"),
@@ -1,4 +1,9 @@
1
1
  es:
2
+ helpers:
3
+ # submit_default_value
4
+ submit:
5
+ user_account:
6
+ create: Agregar %{model}
2
7
  profile_group:
3
8
  account: Cuenta
4
9
  user_accounts: Usuarios
@@ -170,8 +175,8 @@ es:
170
175
  activerecord:
171
176
  models:
172
177
  user_account:
173
- one: Cuenta de usuario
174
- other: Cuentas de usuario
178
+ one: Usuario
179
+ other: Usuarios
175
180
  account:
176
181
  one: Espacio
177
182
  other: Espacios
@@ -0,0 +1,15 @@
1
+ module PgEngine
2
+ module ActiveJobExtensions
3
+ def serialize
4
+ super.merge(
5
+ 'app_name' => ::Current.app_name
6
+ )
7
+ end
8
+
9
+ def deserialize(job_data)
10
+ ::Current.app_name = job_data.delete('app_name')
11
+
12
+ super
13
+ end
14
+ end
15
+ end
@@ -34,9 +34,11 @@ module PgEngine
34
34
 
35
35
  return unless defined? UserAccount
36
36
 
37
+ # :nocov:
37
38
  UserAccount.class_eval do
38
39
  enumerize :profiles, in: PgEngine.configuracion.user_profiles, multiple: true
39
40
  end
41
+ # :nocov:
40
42
  end
41
43
 
42
44
  def profile_groups_options
@@ -53,9 +53,6 @@ module PgEngine
53
53
  end
54
54
 
55
55
  initializer 'configurar_pg_rails' do
56
- # Ensure required env variables are set
57
- ENV.fetch('DEFAULT_MAIL_FROM')
58
- ENV.fetch('DEFAULT_MAIL_FROM_NAME')
59
56
  # SimpleForm
60
57
  require "#{PgEngine::Engine.root}/config/simple_form/simple_form"
61
58
  require "#{PgEngine::Engine.root}/config/simple_form/simple_form_bootstrap"
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgEngine
4
+ class SiteBrand
5
+ attr_accessor :default_site_brand
6
+
7
+ def initialize
8
+ @options = {}
9
+ end
10
+
11
+ def value_for(key)
12
+ options = @options[key.to_sym]
13
+
14
+ raise PgEngine::Error, 'Key not found' if options.nil?
15
+
16
+ if Current.app_name.present? && options.keys.include?(Current.app_name)
17
+ options[Current.app_name]
18
+ elsif options.keys.include?(:default)
19
+ options[:default]
20
+ elsif default_site_brand.present? && options.keys.include?(default_site_brand)
21
+ pg_warn('Default site brand chosen')
22
+
23
+ options[default_site_brand]
24
+ else
25
+ # :nocov:
26
+ raise PgEngine::Error, 'No site brand found'
27
+ # :nocov:
28
+ end
29
+ end
30
+
31
+ def method_missing(method)
32
+ value_for(method)
33
+ end
34
+
35
+ def respond_to_missing?(method, include_private)
36
+ @options.key?(method.to_sym) or super
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,81 @@
1
+ module PgEngine
2
+ module Test
3
+ class DummyBrand < PgEngine::SiteBrand
4
+ def initialize(include_all: false) # rubocop:disable Metrics/MethodLength
5
+ super()
6
+
7
+ @default_site_brand = :factura
8
+
9
+ @options = {
10
+ landing_site_url: {
11
+ procura: 'https://bien.com.ar/procura',
12
+ factura: 'https://bien.com.ar/factura'
13
+ },
14
+ logo_navbar_url: {
15
+ procura: 'procura-logo-navbar-1.png',
16
+ factura: 'logo-navbar-1.png'
17
+ },
18
+ logo_xl_url: {
19
+ procura: 'procura-logo-xl-light.png',
20
+ factura: 'logo-xl-light.png'
21
+ },
22
+ favicon_prefix: {
23
+ procura: 'procura-favicon',
24
+ factura: 'favicon'
25
+ },
26
+ mailer_devise_footer_image_src: {
27
+ factura: 'mail-footer-lg.png',
28
+ procura: 'procura-mail-footer-lg.png'
29
+ },
30
+ mailer_base_footer_image_src: {
31
+ factura: 'footer-mail-dark-light.png',
32
+ procura: 'procura-mail-footer-sm.png'
33
+ },
34
+ default_mail_from: {
35
+ procura: 'noreply@procura',
36
+ factura: 'noreply@factura'
37
+ },
38
+ name: {
39
+ procura: 'Procura Bien',
40
+ factura: 'Factura Bien'
41
+ },
42
+ default_mail_from_name: {
43
+ procura: 'Procura Bien',
44
+ factura: 'Factura Bien'
45
+ },
46
+ default_url_options: {
47
+ default: {}
48
+ }
49
+ }
50
+
51
+ return unless Rails.env.development? || include_all
52
+
53
+ @options.merge!({
54
+ default_url_options: {
55
+ procura: {
56
+ host: 'procura.localhost',
57
+ port: '3000'
58
+ },
59
+ factura: {
60
+ host: 'factura.localhost',
61
+ port: '3000'
62
+ }
63
+ }
64
+ })
65
+ end
66
+
67
+ def account_plan_options
68
+ { factura: 0, procura: 1 }
69
+ end
70
+
71
+ def detect(request)
72
+ return :procura if request.host.match(/procura/)
73
+ return :factura if request.host.match(/factura/)
74
+
75
+ pg_warn 'default site_brand assigned'
76
+
77
+ :factura
78
+ end
79
+ end
80
+ end
81
+ end