pg_rails 7.4.3 → 7.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/pg_associable/spec/system/associable_spec.rb +5 -4
  3. data/pg_engine/app/controllers/admin/accounts_controller.rb +4 -6
  4. data/pg_engine/app/controllers/admin/email_logs_controller.rb +0 -2
  5. data/pg_engine/app/controllers/admin/emails_controller.rb +0 -2
  6. data/pg_engine/app/controllers/admin/user_accounts_controller.rb +0 -2
  7. data/pg_engine/app/controllers/admin/users_controller.rb +2 -3
  8. data/pg_engine/app/controllers/concerns/pg_engine/require_tenant_set.rb +15 -0
  9. data/pg_engine/app/controllers/concerns/pg_engine/resource.rb +3 -0
  10. data/pg_engine/app/controllers/pg_engine/base_controller.rb +49 -7
  11. data/pg_engine/app/controllers/pg_engine/require_sign_in.rb +1 -1
  12. data/pg_engine/app/controllers/users/account_switcher_controller.rb +19 -0
  13. data/pg_engine/app/helpers/pg_engine/form_helper.rb +0 -1
  14. data/pg_engine/app/helpers/pg_engine/route_helper.rb +11 -5
  15. data/pg_engine/app/lib/pg_engine/filtros_builder.rb +2 -1
  16. data/pg_engine/app/models/account.rb +4 -0
  17. data/pg_engine/app/models/current.rb +5 -5
  18. data/pg_engine/app/models/user.rb +36 -5
  19. data/pg_engine/app/models/user_account.rb +1 -0
  20. data/pg_engine/app/policies/user_account_policy.rb +1 -0
  21. data/pg_engine/app/policies/user_policy.rb +6 -13
  22. data/pg_engine/app/views/admin/accounts/_form.html.slim +2 -0
  23. data/pg_engine/app/views/users/account_switcher/list.html.slim +6 -0
  24. data/pg_engine/config/initializers/acts_as_tenant.rb +38 -0
  25. data/pg_engine/config/routes.rb +4 -0
  26. data/pg_engine/db/migrate/20240905154330_account_tenant_columns.rb +10 -0
  27. data/pg_engine/db/seeds.rb +13 -4
  28. data/pg_engine/lib/pg_engine/configuracion.rb +3 -17
  29. data/pg_engine/lib/pg_engine/engine.rb +0 -1
  30. data/pg_engine/lib/pg_engine/utils/pg_logger.rb +2 -1
  31. data/pg_engine/lib/pg_engine.rb +5 -0
  32. data/pg_engine/spec/controllers/admin/accounts_controller_spec.rb +2 -2
  33. data/pg_engine/spec/controllers/admin/user_accounts_controller_spec.rb +4 -3
  34. data/pg_engine/spec/controllers/admin/users_controller_spec.rb +9 -3
  35. data/pg_engine/spec/models/user_spec.rb +11 -4
  36. data/pg_engine/spec/requests/base_controller_requests_spec.rb +1 -1
  37. data/pg_engine/spec/requests/users/base_controller_spec.rb +15 -0
  38. data/pg_engine/spec/requests/users/switcher_spec.rb +60 -0
  39. data/pg_engine/spec/system/breadcrumbs_spec.rb +6 -6
  40. data/pg_engine/spec/system/date_selector_spec.rb +1 -1
  41. data/pg_engine/spec/system/destroy_spec.rb +3 -3
  42. data/pg_engine/spec/system/modal_windows_spec.rb +5 -5
  43. data/pg_engine/spec/system/page_sizes_spec.rb +2 -2
  44. data/pg_engine/spec/system/signup_spec.rb +4 -4
  45. data/pg_engine/spec/system/tenants_spec.rb +55 -0
  46. data/pg_engine/spec/system/tooltips_spec.rb +0 -1
  47. data/pg_layout/app/views/devise/sessions/new.html.erb +4 -0
  48. data/pg_layout/app/views/pg_layout/_sidebar.html.erb +8 -0
  49. data/pg_rails/lib/version.rb +1 -1
  50. data/pg_scaffold/lib/generators/pg_pundit/templates/policy.rb +1 -1
  51. data/pg_scaffold/lib/generators/pg_rails/system_spec/templates/system_spec.rb +1 -1
  52. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +0 -2
  53. metadata +24 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c92bec79721ca86a7228a00acdf6ee2e968c240a1739cdd4b7c61a0f2a7784b5
4
- data.tar.gz: 0701cd071509d9ef7a0fbd7ed8d0cc6e4122b40fe865d021e981b94e96a618e5
3
+ metadata.gz: 99e5df3ed137be9ec63699ccfd381f75f63cf1a7a272c36e49177147be1ad958
4
+ data.tar.gz: f95e10f28d40ab3c513e0a9e680baf268fe500f3a740cbde18fe3754b4f6941e
5
5
  SHA512:
6
- metadata.gz: 9888c6b99cf12f74e07aee5bcd4b93d84aa8449ff4854926a8ba9357bf9a20144936337d4b9bb6e1bc8a4dc064d45eaccd44a38986a8816a9aef53939a96fd44
7
- data.tar.gz: 8acb411a451cc8685e3a3cf84bfdfe44ea2c90ae9ffe24d3bcf45ae566ae0c3efe2ea79e96dc74ded65c226ac698d6b660e0d4ce5a547984e65c0bba360bfc6c
6
+ metadata.gz: 69842b1daf20fce9bfb7a62196d44a83e5b16d6f18198fdf7afcaa229e7ce86f51383106e8d4158259af3eebc9190bc26724cd39cb00afb837902c34e45fe7ae
7
+ data.tar.gz: d27a734ecdd58f0d552b76a2fbc4225341572b24ba467b398be5e93f489eac4d60a116333a828b3382be9791f830aea715e506f4fda01a923f6d5c00ee41a16f
@@ -3,7 +3,7 @@ require 'rails_helper'
3
3
  describe 'Associable' do
4
4
  let(:user) { create :user, :developer }
5
5
 
6
- let(:path) { '/admin/cosas/new' }
6
+ let(:path) { '/a/cosas/new' }
7
7
 
8
8
  before do
9
9
  login_as user
@@ -16,16 +16,17 @@ describe 'Associable' do
16
16
  find('.cosa_categoria_de_cosa input[type=text]').click
17
17
  expect(page).to have_text :all, 'Nuevo'
18
18
  find('.cosa_categoria_de_cosa .list-group-item').click
19
+ select Account.first.to_s
19
20
  fill_in 'categoria_de_cosa_nombre', with: 'la categoría'
20
21
  select 'Completar', from: 'categoria_de_cosa_tipo'
21
22
  click_on 'Agregar Categoría de cosa'
22
23
  click_on 'Cargar Coso'
23
- expect(page).to have_text 'Creado por'
24
+ expect(page).to have_text 'La cosa'
24
25
  end
25
26
 
26
27
  context 'cuando crea desde el nested' do
27
28
  let!(:categ) { create :categoria_de_cosa }
28
- let(:path) { "/admin/categoria_de_cosas/#{categ.hashid}/cosas/new" }
29
+ let(:path) { "/a/categoria_de_cosas/#{categ.hashid}/cosas/new" }
29
30
 
30
31
  it do
31
32
  input = find_by_id('cosa_categoria_de_cosa')
@@ -36,7 +37,7 @@ describe 'Associable' do
36
37
  context 'cuando edita desde el nested' do
37
38
  let!(:categ) { create :categoria_de_cosa }
38
39
  let!(:cosa) { create :cosa, categoria_de_cosa: categ }
39
- let(:path) { "/admin/categoria_de_cosas/#{categ.hashid}/cosas/#{cosa.id}/edit" }
40
+ let(:path) { "/a/categoria_de_cosas/#{categ.hashid}/cosas/#{cosa.id}/edit" }
40
41
 
41
42
  it do
42
43
  ele = find_by_id('cosa_categoria_de_cosa_id', visible: :all)
@@ -12,24 +12,22 @@ module Admin
12
12
 
13
13
  before_action :set_instancia_modelo, only: %i[new create show edit update destroy]
14
14
 
15
- add_breadcrumb Account.nombre_plural, :admin_accounts_path
16
-
17
15
  private
18
16
 
19
17
  def atributos_permitidos
20
- %i[plan nombre]
18
+ %i[plan nombre domain subdomain]
21
19
  end
22
20
 
23
21
  def atributos_para_buscar
24
- %i[plan nombre]
22
+ atributos_permitidos
25
23
  end
26
24
 
27
25
  def atributos_para_listar
28
- %i[plan nombre]
26
+ atributos_permitidos
29
27
  end
30
28
 
31
29
  def atributos_para_mostrar
32
- %i[plan nombre]
30
+ atributos_permitidos
33
31
  end
34
32
  end
35
33
  end
@@ -12,8 +12,6 @@ module Admin
12
12
 
13
13
  before_action :set_instancia_modelo, only: %i[new create show edit update destroy]
14
14
 
15
- add_breadcrumb EmailLog.nombre_plural, :admin_email_logs_path
16
-
17
15
  before_action do
18
16
  @actions = [
19
17
  ["Mailgun sync: #{ENV.fetch('MAILGUN_DOMAIN', nil)}", mailgun_sync_admin_email_logs_path, {
@@ -12,8 +12,6 @@ module Admin
12
12
 
13
13
  before_action :set_instancia_modelo, only: %i[new create show edit update destroy]
14
14
 
15
- add_breadcrumb Email.nombre_plural, :admin_emails_path
16
-
17
15
  after_action only: :create do
18
16
  if @saved
19
17
  PgEngine::AdminMailer.with(email_object: @email).admin_mail.deliver_later
@@ -12,8 +12,6 @@ module Admin
12
12
 
13
13
  before_action :set_instancia_modelo, only: %i[new create show edit update destroy]
14
14
 
15
- add_breadcrumb UserAccount.nombre_plural, :admin_user_accounts_path
16
-
17
15
  private
18
16
 
19
17
  def atributos_permitidos
@@ -16,11 +16,10 @@ module Admin
16
16
 
17
17
  before_action :set_instancia_modelo, only: %i[new create show edit update destroy]
18
18
 
19
- add_breadcrumb User.nombre_plural, :admin_users_path
20
-
21
19
  def create
22
20
  @user.skip_confirmation!
23
- @user.user_accounts << UserAccount.new(account: Current.account)
21
+ @user.orphan = true
22
+
24
23
  pg_respond_create
25
24
  end
26
25
 
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgEngine
4
+ module RequireTenantSet
5
+ def self.included(klass)
6
+ klass.before_action :require_tenant_set
7
+ end
8
+
9
+ def require_tenant_set
10
+ return if ActsAsTenant.current_tenant.present?
11
+
12
+ redirect_to users_account_switcher_path
13
+ end
14
+ end
15
+ end
@@ -91,6 +91,9 @@ module PgEngine
91
91
  return if nested_id.blank?
92
92
 
93
93
  nested_class.find(nested_id)
94
+ rescue ActiveRecord::RecordNotFound => e
95
+ pg_warn(e)
96
+ raise PgEngine::PageNotFoundError
94
97
  end
95
98
 
96
99
  def accepts_turbo_stream?
@@ -2,12 +2,50 @@
2
2
 
3
3
  module PgEngine
4
4
  # rubocop:disable Rails/ApplicationController
5
+ # rubocop:disable Metrics/ClassLength
5
6
  class BaseController < ActionController::Base
7
+ # Importante que esta línea esté al principio
8
+ protect_from_forgery with: :exception
9
+
10
+ set_current_tenant_by_subdomain_or_domain(:account, :subdomain, :domain)
11
+ set_current_tenant_through_filter
12
+
6
13
  before_action do
14
+ Current.user = current_user
7
15
  Current.controller = self
8
- end
9
16
 
17
+ # if ActsAsTenant.current_tenant.blank? && !global_domain?
18
+ # raise ActsAsTenant::Errors::NoTenantSet
19
+ # end
20
+
21
+ if Current.user.present?
22
+ if ActsAsTenant.current_tenant.present?
23
+ unless Current.user.user_accounts.exists?(account: ActsAsTenant.current_tenant)
24
+ sign_out(Current.user)
25
+ throw :warden, scope: :user, message: :invalid
26
+ end
27
+
28
+ else
29
+ account = if session['current_user_account'].present?
30
+ UserAccount.where(id: session['current_user_account']).first&.account
31
+ elsif Current.user.user_accounts.count == 1
32
+ Current.user.user_accounts.first.account
33
+ end
34
+ set_current_tenant(account)
35
+ end
36
+ Current.account = ActsAsTenant.current_tenant
37
+ end
38
+ end
10
39
  # rubocop:enable Rails/ApplicationController
40
+
41
+ # :nocov:
42
+ def global_domain?
43
+ return true if Rails.env.test?
44
+
45
+ request.host.in? PgEngine.config.global_domains
46
+ end
47
+ # :nocov:
48
+
11
49
  include Pundit::Authorization
12
50
  include PrintHelper
13
51
  include PostgresHelper
@@ -25,10 +63,11 @@ module PgEngine
25
63
  end
26
64
  end
27
65
 
28
- protect_from_forgery with: :exception
29
-
30
66
  rescue_from StandardError, with: :internal_error
67
+ rescue_from ActsAsTenant::Errors::NoTenantSet, with: :no_tenant_set
68
+
31
69
  rescue_from PgEngine::BadUserInput, with: :bad_user_input
70
+
32
71
  rescue_from ActionController::InvalidAuthenticityToken,
33
72
  with: :invalid_authenticity_token
34
73
 
@@ -38,6 +77,12 @@ module PgEngine
38
77
  redirect_to e.url
39
78
  end
40
79
 
80
+ def no_tenant_set(error)
81
+ return internal_error(error) if Current.user.blank?
82
+
83
+ redirect_to users_account_switcher_path
84
+ end
85
+
41
86
  def bad_user_input(error)
42
87
  render_my_component(BadUserInputComponent.new(error_msg: error.message), :bad_request)
43
88
  end
@@ -63,10 +108,6 @@ module PgEngine
63
108
  render_my_component(InternalErrorComponent.new, :ok)
64
109
  end
65
110
 
66
- before_action do
67
- Current.user = current_user
68
- end
69
-
70
111
  helper_method :dev_user_or_env?
71
112
  def dev_user_or_env?
72
113
  Rails.env.development? || dev_user?
@@ -181,4 +222,5 @@ module PgEngine
181
222
  redirect_back fallback_location: root_path
182
223
  end
183
224
  end
225
+ # rubocop:enable Metrics/ClassLength
184
226
  end
@@ -4,7 +4,7 @@ module PgEngine
4
4
  module RequireSignIn
5
5
  def self.included(clazz)
6
6
  clazz.include RansackMemory::Concern
7
- clazz.before_action :authenticate_user!
7
+ clazz.prepend_before_action :authenticate_user!
8
8
  clazz.before_action :save_and_load_filters
9
9
  end
10
10
  end
@@ -0,0 +1,19 @@
1
+ module Users
2
+ class AccountSwitcherController < PgEngine.config.users_controller
3
+ rescue_from ActsAsTenant::Errors::NoTenantSet, with: :internal_error
4
+
5
+ before_action do
6
+ @no_main_frame = true
7
+ end
8
+
9
+ def list
10
+ @user_accounts = Current.user.user_accounts
11
+ end
12
+
13
+ def switch
14
+ user_account = UserAccount.find(params[:user_account_id])
15
+ session['current_user_account'] = user_account.id
16
+ redirect_to root_path
17
+ end
18
+ end
19
+ end
@@ -12,7 +12,6 @@ module PgEngine
12
12
  object.decorator_class <= PgEngine::BaseRecordDecorator
13
13
  object = object.decorate.target_object
14
14
  end
15
- # byebug
16
15
  options = args.extract_options!
17
16
 
18
17
  options[:builder] = PgFormBuilder
@@ -3,21 +3,25 @@
3
3
  module PgEngine
4
4
  module RouteHelper
5
5
  class NamespaceDeductor
6
- def self.request(context)
6
+ def self.controller(context)
7
7
  if context.respond_to?(:request) && context.request
8
8
  # Controllers
9
- context.request
9
+ context
10
10
  elsif context.respond_to?(:helpers) && context.helpers
11
11
  # Decorators
12
- context.helpers.request
12
+ context.helpers.controller
13
13
  elsif context.respond_to?(:template) && context.template
14
14
  # FormBuilders
15
- context.template.request
15
+ context.template.controller
16
16
  end
17
17
  end
18
18
 
19
19
  def self.current_route(context)
20
- req = request(context)
20
+ controller = controller(context)
21
+ # Sólo si hay un controller de verdá
22
+ return if controller.instance_of? ApplicationController
23
+
24
+ req = controller.request
21
25
  Rails.application.routes.recognize_path(req.path, method: req.env['REQUEST_METHOD'])
22
26
  end
23
27
 
@@ -25,6 +29,8 @@ module PgEngine
25
29
  return Current.namespace if Current.namespace.present?
26
30
 
27
31
  route = current_route(context)
32
+ return if route.blank?
33
+
28
34
  parts = route[:controller].split('/')
29
35
  return unless parts.length > 1
30
36
 
@@ -64,7 +64,8 @@ module PgEngine
64
64
  @filtros[campo][:scope_asociacion] = block
65
65
  end
66
66
 
67
- # FIXME: deprecar
67
+ deprecate :filtrar, deprecator: PgEngine.deprecator
68
+
68
69
  def filtrar(query, parametros = nil)
69
70
  parametros_controller if parametros.nil?
70
71
 
@@ -32,4 +32,8 @@ class Account < ApplicationRecord
32
32
  enumerize :plan, in: { completar: 0, los: 1, valores: 2 }
33
33
 
34
34
  validates :plan, :nombre, presence: true
35
+
36
+ def to_s
37
+ nombre
38
+ end
35
39
  end
@@ -4,9 +4,9 @@ class Current < ActiveSupport::CurrentAttributes
4
4
 
5
5
  # resets { Time.zone = nil }
6
6
 
7
- def user=(user)
8
- super
9
- self.account = user&.current_account
10
- # Time.zone = user.time_zone
11
- end
7
+ # def user=(user)
8
+ # super
9
+ #
10
+ # Time.zone = user.time_zone
11
+ # end
12
12
  end
@@ -37,7 +37,22 @@ class User < ApplicationRecord
37
37
  include Discard::Model
38
38
 
39
39
  has_many :user_accounts
40
+
41
+ # Hace falta?
40
42
  has_many :accounts, through: :user_accounts
43
+
44
+ # default_scope lambda {
45
+ # if ActsAsTenant.current_tenant.present?
46
+ # joins(:user_accounts).where('user_accounts.account_id': ActsAsTenant.current_tenant.id)
47
+ # else
48
+ # raise ActsAsTenant::Errors::NoTenantSet unless Current.user.blank? || ActsAsTenant.unscoped?
49
+
50
+ # # Aún no autenticó devise o es el admin
51
+ # all
52
+
53
+ # end
54
+ # }
55
+
41
56
  has_many :notifications, as: :recipient, class_name: 'Noticed::Notification'
42
57
 
43
58
  validates :nombre, :apellido, presence: true
@@ -57,14 +72,23 @@ class User < ApplicationRecord
57
72
  attr_accessor :orphan
58
73
 
59
74
  after_create do
60
- # TODO: si fue invitado, sumar a la account del invitador
61
75
  create_account unless orphan
62
76
  end
63
77
 
64
78
  def create_account
65
- account = Account.create(nombre: email, plan: 0)
79
+ # rubocop:disable Rails/Presence
80
+ account =
81
+ if ActsAsTenant.current_tenant.present?
82
+ # FIXME!: raise PgEngine::Error unless invited
83
+ ActsAsTenant.current_tenant
84
+ else
85
+ Account.create(nombre: email, plan: 0)
86
+ end
87
+ # rubocop:enable Rails/Presence
88
+
66
89
  ua = user_accounts.create(account:)
67
- raise(ActiveRecord::Rollback) unless ua.persisted?
90
+
91
+ raise(Error, 'no se pudo crear la cuenta') unless ua.persisted?
68
92
  end
69
93
 
70
94
  def password_required?
@@ -87,9 +111,16 @@ class User < ApplicationRecord
87
111
 
88
112
  class Error < PgEngine::Error; end
89
113
 
90
- def current_account
114
+ def default_account
91
115
  raise Error, 'El usuario debe tener cuenta' if accounts.empty?
92
116
 
93
- accounts.first
117
+ user_accounts.first.account
118
+ # throw :warden, scope: :user, message: :user_not_belongs_to_account
119
+ end
120
+
121
+ deprecate :current_account, deprecator: PgEngine.deprecator
122
+
123
+ def current_account
124
+ ActsAsTenant.current_tenant
94
125
  end
95
126
  end
@@ -23,6 +23,7 @@
23
23
 
24
24
  class UserAccount < ApplicationRecord
25
25
  audited
26
+ include Hashid::Rails
26
27
 
27
28
  belongs_to :user
28
29
  belongs_to :account
@@ -4,6 +4,7 @@
4
4
 
5
5
  class UserAccountPolicy < ApplicationPolicy
6
6
  class Scope < ApplicationPolicy::Scope
7
+ # FIXME: quizá scopear las user_accounts según user y/o según account
7
8
  # def resolve
8
9
  # if policy.acceso_total?
9
10
  # scope.all
@@ -4,17 +4,6 @@
4
4
 
5
5
  class UserPolicy < ApplicationPolicy
6
6
  class Scope < ApplicationPolicy::Scope
7
- def resolve
8
- if policy.acceso_total?
9
- if Current.account.present?
10
- scope.joins(:user_accounts).where('user_accounts.account_id': Current.account.id)
11
- else
12
- scope.none
13
- end
14
- else
15
- scope.none
16
- end
17
- end
18
7
  end
19
8
 
20
9
  # def puede_editar?
@@ -29,7 +18,11 @@ class UserPolicy < ApplicationPolicy
29
18
  # acceso_total? && !record.readonly?
30
19
  # end
31
20
 
32
- def acceso_total?
33
- user.present?
21
+ def base_access_to_record?
22
+ user.developer? || user == record
34
23
  end
24
+
25
+ # def base_access_to_collection?
26
+ # user&.present?
27
+ # end
35
28
  end
@@ -4,5 +4,7 @@ div style="max-width: 22em"
4
4
  = pg_form_for(@account || object) do |f|
5
5
  = f.input :plan
6
6
  = f.input :nombre
7
+ = f.input :domain
8
+ = f.input :subdomain
7
9
  .mt-2
8
10
  = f.button :submit
@@ -0,0 +1,6 @@
1
+ h1 Switcher
2
+
3
+ ul
4
+ - @user_accounts.each do |user_account|
5
+ li = link_to user_account.account, users_account_switch_path(user_account),
6
+ 'data-turbo-method': :post
@@ -0,0 +1,38 @@
1
+ ActsAsTenant.configure do |config|
2
+ config.require_tenant = true
3
+ # config.require_tenant = lambda do |options|
4
+ # # if options[:scope] == User && true # global_domain?
5
+ # # # tal vez en algunos casos de devise sí requeriría el tenant?
6
+ # # # creería que no, el único lugar en donde se debería queriar
7
+ # # # User es en devise y es para obtener el current_user
8
+ # # # hay que ver luego qué pasa con invitable
9
+ # # false
10
+ # # else
11
+ # # true
12
+ # # end
13
+ # end
14
+
15
+ # Customize the query for loading the tenant in background jobs
16
+ # config.job_scope = ->{ all }
17
+ end
18
+
19
+ SET_TENANT_PROC = lambda do
20
+ if defined?(Rails::Console)
21
+ puts "> ActsAsTenant.current_tenant = Account.first"
22
+ ActsAsTenant.current_tenant = Account.first
23
+ end
24
+ end
25
+
26
+ Rails.application.configure do
27
+ if Rails.env.development?
28
+ # Set the tenant to the first account in development on load
29
+ config.after_initialize do
30
+ SET_TENANT_PROC.call
31
+ end
32
+
33
+ # Reset the tenant after calling 'reload!' in the console
34
+ ActiveSupport::Reloader.to_complete do
35
+ SET_TENANT_PROC.call
36
+ end
37
+ end
38
+ end
@@ -21,6 +21,10 @@ Rails.application.routes.draw do
21
21
  post 'notifications/mark_as_seen', to: 'notifications#mark_as_seen'
22
22
  post 'notifications/mark_as_unseen', to: 'notifications#mark_as_unseen'
23
23
  get 'date_jumper/jump'
24
+ scope controller: 'account_switcher', path: 'switcher' do
25
+ get '', action: 'list', as: 'account_switcher'
26
+ post ':user_account_id', action: 'switch', as: 'account_switch'
27
+ end
24
28
  end
25
29
  namespace :admin, path: 'a' do
26
30
  pg_resource(:emails)
@@ -0,0 +1,10 @@
1
+ class AccountTenantColumns < ActiveRecord::Migration[7.2]
2
+ def change
3
+ add_column :accounts, :domain, :string
4
+ add_column :accounts, :subdomain, :string
5
+
6
+ add_reference :audits, :account, index: true, foreign_key: true
7
+ add_reference :emails, :account, index: true, foreign_key: true
8
+ add_reference :email_logs, :account, index: true, foreign_key: true
9
+ end
10
+ end
@@ -1,6 +1,15 @@
1
- DatabaseCleaner.clean_with(:truncation, except: %w(ar_internal_metadata))
1
+ ActsAsTenant.without_tenant do
2
+ DatabaseCleaner.clean_with(:truncation, except: %w(ar_internal_metadata))
2
3
 
3
- FactoryBot.create :user, email: 'mrosso10@gmail.com', nombre: 'Martín', apellido: 'Rosso', password: 'admin123',
4
- confirmed_at: Time.now, developer: true
5
4
 
6
- Account.first.users << FactoryBot.create(:user, orphan: true)
5
+ bien = FactoryBot.create :account, nombre: 'Bien', subdomain: 'bien'
6
+ uno = FactoryBot.create :user, email: 'mrosso10@gmail.com', nombre: 'Martín', apellido: 'Rosso', password: 'admin123',
7
+ confirmed_at: Time.now, developer: true, orphan: true
8
+ bien.users << uno
9
+
10
+ mal = FactoryBot.create :account, nombre: 'Mal', subdomain: 'mal'
11
+ otro = FactoryBot.create :user, email: 'mal@gmail.com', nombre: 'Mal', apellido: 'Mal', password: 'admin123',
12
+ confirmed_at: Time.now, developer: true, orphan: true
13
+
14
+ mal.users << otro
15
+ end
@@ -4,30 +4,16 @@
4
4
 
5
5
  module PgEngine
6
6
  class Configuracion
7
- attr_accessor :sistema_iconos, :clase_botones_chicos,
8
- :boton_destroy, :boton_edit, :boton_show,
9
- :boton_light, :icono_destroy, :icono_edit,
10
- :icono_show, :boton_export, :bootstrap_version,
11
- :users_controller
7
+ attr_accessor :users_controller, :global_domains
12
8
 
13
9
  def initialize
14
- @sistema_iconos = 'bi'
15
- @clase_botones_chicos = 'btn-sm'
16
- @boton_destroy = 'light'
17
- @boton_export = 'warning'
18
- @boton_edit = 'light'
19
- @boton_show = 'light'
20
- @boton_light = 'light'
21
- @icono_destroy = 'trash-fill'
22
- @icono_edit = 'pencil'
23
- @icono_show = 'eye-fill'
24
- @bootstrap_version = 5
25
-
26
10
  if defined? UsersController
27
11
  @users_controller = UsersController
28
12
  elsif defined? FrontendController
29
13
  @users_controller = FrontendController
30
14
  end
15
+
16
+ @global_domains = ['app.localhost.com', 'test.host', 'localhost']
31
17
  end
32
18
  end
33
19
  end
@@ -59,7 +59,6 @@ module PgEngine
59
59
 
60
60
  initializer 'byebug_bullet' do
61
61
  if Rails.env.local?
62
- # Byebug
63
62
  # :nocov:
64
63
  if ENV['RUBY_DEBUG_OPEN']
65
64
  require 'byebug/core'
@@ -3,9 +3,10 @@
3
3
  require 'rainbow'
4
4
 
5
5
  # TODO: poder pasar blocks
6
+ # TODO: loguear paralelamente a otro file
6
7
 
7
8
  def pg_err(*args)
8
- if ENV.fetch('RAISE_ERRORS', false)
9
+ if ENV.fetch('RAISE_ERRORS', false) == '1'
9
10
  # :nocov:
10
11
  raise args.first if args.first.is_a?(Exception)
11
12
 
@@ -16,6 +16,7 @@ require 'rails'
16
16
  require 'anycable'
17
17
  require 'anycable-rails'
18
18
  require 'anycable-rails-jwt'
19
+ require 'acts_as_tenant'
19
20
  require 'cable_ready'
20
21
  require 'caxlsx_rails'
21
22
  require 'draper'
@@ -105,4 +106,8 @@ module PgEngine
105
106
  https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,300;0,400;\
106
107
  0,500;0,700;1,300;1,400;1,500;1,700&display=swap
107
108
  URL
109
+
110
+ def self.deprecator
111
+ @deprecator ||= ActiveSupport::Deprecation.new('7.5', 'PgEngine')
112
+ end
108
113
  end