pg_rails 7.4.2 → 7.5.0

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/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/resource.rb +3 -0
  9. data/pg_engine/app/controllers/pg_engine/base_controller.rb +50 -7
  10. data/pg_engine/app/controllers/pg_engine/require_sign_in.rb +1 -1
  11. data/pg_engine/app/controllers/users/account_switcher_controller.rb +19 -0
  12. data/pg_engine/app/helpers/pg_engine/form_helper.rb +0 -1
  13. data/pg_engine/app/helpers/pg_engine/route_helper.rb +11 -5
  14. data/pg_engine/app/lib/pg_engine/filtros_builder.rb +2 -1
  15. data/pg_engine/app/models/account.rb +4 -0
  16. data/pg_engine/app/models/current.rb +5 -5
  17. data/pg_engine/app/models/user.rb +36 -5
  18. data/pg_engine/app/models/user_account.rb +1 -0
  19. data/pg_engine/app/policies/user_account_policy.rb +1 -0
  20. data/pg_engine/app/policies/user_policy.rb +6 -13
  21. data/pg_engine/app/views/admin/accounts/_form.html.slim +2 -0
  22. data/pg_engine/app/views/pg_engine/base/index.html.slim +1 -1
  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/components/previews/alert_component_preview/tables.html.slim +18 -12
  33. data/pg_engine/spec/controllers/admin/accounts_controller_spec.rb +2 -2
  34. data/pg_engine/spec/controllers/admin/user_accounts_controller_spec.rb +4 -3
  35. data/pg_engine/spec/controllers/admin/users_controller_spec.rb +9 -3
  36. data/pg_engine/spec/models/user_spec.rb +11 -4
  37. data/pg_engine/spec/requests/base_controller_requests_spec.rb +1 -1
  38. data/pg_engine/spec/requests/users/base_controller_spec.rb +15 -0
  39. data/pg_engine/spec/requests/users/switcher_spec.rb +60 -0
  40. data/pg_engine/spec/system/breadcrumbs_spec.rb +6 -6
  41. data/pg_engine/spec/system/date_selector_spec.rb +1 -1
  42. data/pg_engine/spec/system/destroy_spec.rb +3 -3
  43. data/pg_engine/spec/system/modal_windows_spec.rb +5 -5
  44. data/pg_engine/spec/system/page_sizes_spec.rb +2 -2
  45. data/pg_engine/spec/system/signup_spec.rb +4 -4
  46. data/pg_engine/spec/system/tenants_spec.rb +55 -0
  47. data/pg_engine/spec/system/tooltips_spec.rb +0 -1
  48. data/pg_layout/app/views/devise/sessions/new.html.erb +4 -0
  49. data/pg_layout/app/views/pg_layout/_sidebar.html.erb +8 -0
  50. data/pg_rails/lib/version.rb +1 -1
  51. data/pg_rails/scss/pg_rails.scss +1 -0
  52. data/pg_scaffold/lib/generators/pg_pundit/templates/policy.rb +1 -1
  53. data/pg_scaffold/lib/generators/pg_rails/system_spec/templates/system_spec.rb +1 -1
  54. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +0 -2
  55. metadata +23 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55cfb59ec05d90c2944001cb69e2625c8d4f8e8a1eb460427dca95daf25b4ba4
4
- data.tar.gz: eb5c2a073a6a1d69a0307e2ae16e9550dc852e2a45bd28aebb2ccc0ef6b0d5d6
3
+ metadata.gz: c9044a5f343884a27bcfdb2be81907fcaaa743b4c1419c4dd1646214a50c5f7e
4
+ data.tar.gz: 2542d054eb7ec2ae29e95fdff5a7a0d8cccdef4d57e5a7073b4c0fe945f91fff
5
5
  SHA512:
6
- metadata.gz: 890f2a67f70994285f1c5cefd90f8cd36c3604bcb368345e9e5331afa805fa99bb5f15e5bfd81e9e78e0948621f6356df0c855c22fb70d0c10722f974e0438f4
7
- data.tar.gz: db292c14db052409f0b27c9d11fafce68471f387c633799a7caf2c9f3b49e59829ad14ee3d41976a133d3f5912c56a087fa54068974cd2b42194b97a1d8f4cee
6
+ metadata.gz: 19ebd2bc479aab28961ba3280a2c0bf276e202501eecfc0474863a00e89882c79bef6c369e9d1ae7a533ad9118716389af0964ae66395a34ff0572011fb5e4ac
7
+ data.tar.gz: 5a37d34ab77355940e8c8988af1a9c4d839069b9b37bf645088ea5325c18f8e4829c99ae31877c53195d08caf22bae6ba01efa0d55cf8d95872056a481d51473
@@ -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
 
@@ -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,51 @@
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
33
+ end
34
+ set_current_tenant(account)
35
+ # FIXME: un concern que redirija al switcher si no hay current tenant
36
+ end
37
+ Current.account = ActsAsTenant.current_tenant
38
+ end
39
+ end
10
40
  # rubocop:enable Rails/ApplicationController
41
+
42
+ # :nocov:
43
+ def global_domain?
44
+ return true if Rails.env.test?
45
+
46
+ request.host.in? PgEngine.config.global_domains
47
+ end
48
+ # :nocov:
49
+
11
50
  include Pundit::Authorization
12
51
  include PrintHelper
13
52
  include PostgresHelper
@@ -25,10 +64,11 @@ module PgEngine
25
64
  end
26
65
  end
27
66
 
28
- protect_from_forgery with: :exception
29
-
30
67
  rescue_from StandardError, with: :internal_error
68
+ rescue_from ActsAsTenant::Errors::NoTenantSet, with: :no_tenant_set
69
+
31
70
  rescue_from PgEngine::BadUserInput, with: :bad_user_input
71
+
32
72
  rescue_from ActionController::InvalidAuthenticityToken,
33
73
  with: :invalid_authenticity_token
34
74
 
@@ -38,6 +78,12 @@ module PgEngine
38
78
  redirect_to e.url
39
79
  end
40
80
 
81
+ def no_tenant_set(error)
82
+ return internal_error(error) if Current.user.blank?
83
+
84
+ redirect_to users_account_switcher_path
85
+ end
86
+
41
87
  def bad_user_input(error)
42
88
  render_my_component(BadUserInputComponent.new(error_msg: error.message), :bad_request)
43
89
  end
@@ -63,10 +109,6 @@ module PgEngine
63
109
  render_my_component(InternalErrorComponent.new, :ok)
64
110
  end
65
111
 
66
- before_action do
67
- Current.user = current_user
68
- end
69
-
70
112
  helper_method :dev_user_or_env?
71
113
  def dev_user_or_env?
72
114
  Rails.env.development? || dev_user?
@@ -181,4 +223,5 @@ module PgEngine
181
223
  redirect_back fallback_location: root_path
182
224
  end
183
225
  end
226
+ # rubocop:enable Metrics/ClassLength
184
227
  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
@@ -22,7 +22,7 @@ div
22
22
  thead.table-light
23
23
  tr
24
24
  - atributos_para_listar.each do |att|
25
- th = encabezado att, ordenable: true
25
+ th.text-nowrap style="font-size: 0.8em" = encabezado att, ordenable: true
26
26
  th.text-end
27
27
  - unless @export_link == false
28
28
  = @clase_modelo.new.decorate.export_link(request.url)
@@ -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