pg_rails 7.5.0 → 7.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/pg_associable/app/javascript/modal_controller.js +8 -3
  3. data/pg_engine/app/controllers/admin/users_controller.rb +0 -17
  4. data/pg_engine/app/controllers/concerns/pg_engine/require_tenant_set.rb +15 -0
  5. data/pg_engine/app/controllers/pg_engine/base_admin_controller.rb +19 -0
  6. data/pg_engine/app/controllers/pg_engine/base_controller.rb +1 -3
  7. data/pg_engine/app/controllers/pg_engine/base_public_controller.rb +17 -0
  8. data/pg_engine/app/controllers/pg_engine/base_users_controller.rb +17 -0
  9. data/pg_engine/app/controllers/users/account_switcher_controller.rb +1 -0
  10. data/pg_engine/app/models/current.rb +2 -0
  11. data/pg_engine/app/models/email.rb +4 -1
  12. data/pg_engine/app/models/email_log.rb +2 -1
  13. data/pg_engine/app/models/user.rb +4 -4
  14. data/pg_engine/app/overrides/audited_audit.rb +15 -0
  15. data/pg_engine/app/views/admin/users/show.html.slim +1 -1
  16. data/pg_engine/config/routes.rb +6 -1
  17. data/pg_engine/lib/pg_engine/configuracion.rb +0 -2
  18. data/pg_engine/spec/controllers/admin/email_logs_controller_spec.rb +3 -1
  19. data/pg_engine/spec/overrides/audited_audit_spec.rb +16 -0
  20. data/pg_engine/spec/system/breadcrumbs_spec.rb +0 -1
  21. data/pg_engine/spec/system/date_selector_spec.rb +0 -1
  22. data/pg_engine/spec/system/login_spec.rb +1 -1
  23. data/pg_engine/spec/system/modal_windows_spec.rb +0 -1
  24. data/pg_engine/spec/system/tenants_spec.rb +1 -0
  25. data/pg_layout/app/javascript/controllers/popover_toggler_controller.js +5 -1
  26. data/pg_layout/app/javascript/controllers/tooltip_controller.js +5 -1
  27. data/pg_layout/app/views/devise/sessions/new.html.erb +1 -1
  28. data/pg_layout/app/views/pg_layout/_sidebar.html.erb +2 -3
  29. data/pg_rails/lib/version.rb +1 -1
  30. data/pg_scaffold/spec/generators_spec.rb +4 -4
  31. metadata +8 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c9044a5f343884a27bcfdb2be81907fcaaa743b4c1419c4dd1646214a50c5f7e
4
- data.tar.gz: 2542d054eb7ec2ae29e95fdff5a7a0d8cccdef4d57e5a7073b4c0fe945f91fff
3
+ metadata.gz: cbc9c1b9067850c9f99c3a28d9252248c8657cacbd7cade188c50bced6d4559d
4
+ data.tar.gz: 4a9b8e39d04fa9837a488262f679c93f946461140229d7da84c124ade30bd120
5
5
  SHA512:
6
- metadata.gz: 19ebd2bc479aab28961ba3280a2c0bf276e202501eecfc0474863a00e89882c79bef6c369e9d1ae7a533ad9118716389af0964ae66395a34ff0572011fb5e4ac
7
- data.tar.gz: 5a37d34ab77355940e8c8988af1a9c4d839069b9b37bf645088ea5325c18f8e4829c99ae31877c53195d08caf22bae6ba01efa0d55cf8d95872056a481d51473
6
+ metadata.gz: dec0fda9ea266e4a8b57d186f70bf3395bb4ee2220cbc302556048d600014c7fee086e6dbec2fbfa3189cfe381221b06966e2a5d0afd2fe5d2754044067aee6d
7
+ data.tar.gz: a6dd1b4a963542a169fd2a3e67ef9003e4f37b0c549ddf59118f4b402f373c64708d92bca3a257342b75c9b83af74d39edbff162a4e91f9dcbd01bc98ebb5ddb
@@ -105,9 +105,14 @@ export default class extends Controller {
105
105
  // this.modalPuntero.hide()
106
106
  // pero tiraba a veces error:
107
107
  // TypeError: can't convert null to object, _isWithActiveTrigger
108
- document.querySelectorAll('.modal-backdrop').forEach((el) => {
109
- el.remove()
110
- })
108
+ // document.querySelectorAll('.modal-backdrop').forEach((el) => {
109
+ // el.remove()
110
+ // })
111
+ // UPDATE: 11-09-2024, vuelvo a poner el hide, porque en parece que
112
+ // el problema de _isWithActiveTrigger viene por el lado de los
113
+ // tooltips:
114
+ // https://github.com/twbs/bootstrap/issues/37474
115
+ this.modalPuntero.hide()
111
116
  document.dispatchEvent(new Event('hidden.bs.modal'))
112
117
  this.modalPuntero.dispose()
113
118
  }
@@ -28,23 +28,6 @@ module Admin
28
28
  pg_respond_update
29
29
  end
30
30
 
31
- # TODO: sacar este método a otro lado, que no sea AdminController
32
- skip_before_action :authenticate_user!, only: [:login_as]
33
-
34
- # :nocov:
35
- def login_as
36
- return unless dev_user_or_env?
37
-
38
- usuario = User.find(params[:id])
39
- if usuario.confirmed_at.present?
40
- sign_in(:user, usuario)
41
- redirect_to after_sign_in_path_for(usuario)
42
- else
43
- go_back('No está confirmado')
44
- end
45
- end
46
- # :nocov:
47
-
48
31
  private
49
32
 
50
33
  def atributos_permitidos
@@ -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
@@ -0,0 +1,19 @@
1
+ module PgEngine
2
+ class BaseAdminController < ApplicationController
3
+ include PgEngine::RequireSignIn
4
+
5
+ before_action do
6
+ raise Pundit::NotAuthorizedError unless Current.user&.developer?
7
+
8
+ Current.namespace = :admin
9
+
10
+ add_breadcrumb 'Admin'
11
+ end
12
+
13
+ around_action :set_without_tenant
14
+
15
+ def set_without_tenant(&)
16
+ ActsAsTenant.without_tenant(&)
17
+ end
18
+ end
19
+ end
@@ -29,12 +29,10 @@ module PgEngine
29
29
  account = if session['current_user_account'].present?
30
30
  UserAccount.where(id: session['current_user_account']).first&.account
31
31
  elsif Current.user.user_accounts.count == 1
32
- Current.user.user_accounts.first
32
+ Current.user.user_accounts.first.account
33
33
  end
34
34
  set_current_tenant(account)
35
- # FIXME: un concern que redirija al switcher si no hay current tenant
36
35
  end
37
- Current.account = ActsAsTenant.current_tenant
38
36
  end
39
37
  end
40
38
  # rubocop:enable Rails/ApplicationController
@@ -0,0 +1,17 @@
1
+ module PgEngine
2
+ class BasePublicController < ApplicationController
3
+ # :nocov:
4
+ def login_as
5
+ return head :bad_request unless dev_user_or_env?
6
+
7
+ usuario = User.find(params[:id])
8
+ if usuario.confirmed_at.present?
9
+ sign_in(:user, usuario)
10
+ redirect_to after_sign_in_path_for(usuario)
11
+ else
12
+ go_back('No está confirmado')
13
+ end
14
+ end
15
+ # :nocov:
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module PgEngine
2
+ class BaseUsersController < ApplicationController
3
+ include PgEngine::RequireSignIn
4
+ include PgEngine::RequireTenantSet
5
+
6
+ before_action do
7
+ # FIXME: requisito que esto esté seteado
8
+ Current.namespace = :users
9
+
10
+ add_breadcrumb 'Inicio', :users_root_path unless using_modal2? || frame_embedded?
11
+ end
12
+
13
+ def home
14
+ render html: '<h1>Inicio</h1>'.html_safe, layout: 'pg_layout/centered'
15
+ end
16
+ end
17
+ end
@@ -1,6 +1,7 @@
1
1
  module Users
2
2
  class AccountSwitcherController < PgEngine.config.users_controller
3
3
  rescue_from ActsAsTenant::Errors::NoTenantSet, with: :internal_error
4
+ skip_before_action :require_tenant_set
4
5
 
5
6
  before_action do
6
7
  @no_main_frame = true
@@ -9,4 +9,6 @@ class Current < ActiveSupport::CurrentAttributes
9
9
  #
10
10
  # Time.zone = user.time_zone
11
11
  # end
12
+
13
+ deprecate :account, deprecator: PgEngine.deprecator
12
14
  end
@@ -46,7 +46,10 @@ class Email < ApplicationRecord
46
46
 
47
47
  has_one_attached :encoded_eml
48
48
 
49
- belongs_to :associated, polymorphic: true, optional: true
49
+ acts_as_tenant :account, optional: true
50
+
51
+ tenantable_belongs_to :associated, polymorphic: true, optional: true,
52
+ assign_tenant_from_associated: true
50
53
 
51
54
  belongs_to :creado_por, optional: true, class_name: 'User'
52
55
  belongs_to :actualizado_por, optional: true, class_name: 'User'
@@ -23,7 +23,8 @@
23
23
  class EmailLog < ApplicationRecord
24
24
  audited
25
25
 
26
- belongs_to :email, optional: true
26
+ acts_as_tenant :account, optional: true
27
+ tenantable_belongs_to :email, optional: true, assign_tenant_from_associated: true
27
28
 
28
29
  after_create_commit do
29
30
  email.update_status! if email.present?
@@ -76,16 +76,16 @@ class User < ApplicationRecord
76
76
  end
77
77
 
78
78
  def create_account
79
- # rubocop:disable Rails/Presence
80
79
  account =
81
80
  if ActsAsTenant.current_tenant.present?
82
- # FIXME!: raise PgEngine::Error unless invited
81
+ # :nocov:
82
+ raise PgEngine::Error, 'user not invited' unless Rails.env.test?
83
+ # :nocov:
84
+
83
85
  ActsAsTenant.current_tenant
84
86
  else
85
87
  Account.create(nombre: email, plan: 0)
86
88
  end
87
- # rubocop:enable Rails/Presence
88
-
89
89
  ua = user_accounts.create(account:)
90
90
 
91
91
  raise(Error, 'no se pudo crear la cuenta') unless ua.persisted?
@@ -0,0 +1,15 @@
1
+ Audited::Audit.class_eval do
2
+ before_validation do
3
+ if account_id.nil?
4
+ if auditable.respond_to?(:account_id)
5
+ self.account_id = auditable.account_id
6
+ elsif auditable_type == 'Account'
7
+ self.account_id = auditable.id
8
+ elsif ActsAsTenant.current_tenant.present?
9
+ self.account = ActsAsTenant.current_tenant
10
+ end
11
+ end
12
+ end
13
+
14
+ belongs_to :account, optional: true
15
+ end
@@ -5,7 +5,7 @@
5
5
  .ms-1
6
6
  = @user.edit_link
7
7
  .ms-1
8
- = link_to admin_login_as_path(id: @user.id), class: 'btn btn-light btn-sm' do
8
+ = link_to login_as_path(id: @user.id), class: 'btn btn-light btn-sm' do
9
9
  span.bi.bi-arrow-right
10
10
  | Login as
11
11
 
@@ -13,6 +13,9 @@ Rails.application.routes.draw do
13
13
  pg_resource(:mensaje_contactos, only: [:new, :create], path: 'contacto')
14
14
  post 'webhook/mailgun', to: 'webhooks#mailgun'
15
15
  end
16
+
17
+ get 'login_as', to: 'public#login_as'
18
+
16
19
  devise_for :users, controllers: {
17
20
  confirmations: 'users/confirmations',
18
21
  registrations: 'users/registrations'
@@ -26,6 +29,9 @@ Rails.application.routes.draw do
26
29
  post ':user_account_id', action: 'switch', as: 'account_switch'
27
30
  end
28
31
  end
32
+
33
+ get '/u', to: 'users#home', as: :users_root
34
+
29
35
  namespace :admin, path: 'a' do
30
36
  pg_resource(:emails)
31
37
  pg_resource(:eventos)
@@ -37,7 +43,6 @@ Rails.application.routes.draw do
37
43
  pg_resource(:users)
38
44
  pg_resource(:accounts)
39
45
  pg_resource(:user_accounts)
40
- get 'login_as', to: 'users#login_as'
41
46
  end
42
47
  if defined? ActiveAdmin
43
48
  ActiveAdmin.routes(self)
@@ -9,8 +9,6 @@ module PgEngine
9
9
  def initialize
10
10
  if defined? UsersController
11
11
  @users_controller = UsersController
12
- elsif defined? FrontendController
13
- @users_controller = FrontendController
14
12
  end
15
13
 
16
14
  @global_domains = ['app.localhost.com', 'test.host', 'localhost']
@@ -33,9 +33,11 @@ RSpec.describe Admin::EmailLogsController do
33
33
  # EmailLog. As you add validations to EmailLog, be sure to
34
34
  # adjust the attributes here as well.
35
35
  let(:valid_attributes) do
36
- attributes_for(:email_log)
36
+ attributes_for(:email_log).merge(email_id: email.id)
37
37
  end
38
38
 
39
+ let(:email) { create :email }
40
+
39
41
  let(:logged_user) { create :user, :developer }
40
42
 
41
43
  before do
@@ -0,0 +1,16 @@
1
+ require 'rails_helper'
2
+
3
+ describe 'Audited::Audit' do
4
+ subject do
5
+ create :categoria_de_cosa
6
+ end
7
+
8
+ it 'creates the audits' do
9
+ expect { subject }.to change(Audited::Audit, :count).by(1)
10
+ end
11
+
12
+ it 'assigns the tenant to audits' do
13
+ subject
14
+ expect(Audited::Audit.last.account).to eq ActsAsTenant.current_tenant
15
+ end
16
+ end
@@ -15,7 +15,6 @@ describe 'Breadcrumbs' do
15
15
  let(:path) { "/a/cosas/#{cosa.id}" }
16
16
  let(:cosa) { create :cosa }
17
17
  let(:logged_user) { create :user, :developer }
18
- let(:account) { logged_user.current_account }
19
18
 
20
19
  before do
21
20
  login_as logged_user
@@ -13,7 +13,6 @@ describe 'Date selector' do
13
13
  end
14
14
 
15
15
  let(:logged_user) { create :user, :developer }
16
- let(:account) { logged_user.current_account }
17
16
  let(:categoria_de_cosa) { create :categoria_de_cosa, fecha: }
18
17
  let(:fecha) { Date.new(2024, 8, 12) }
19
18
 
@@ -5,7 +5,7 @@ require 'rails_helper'
5
5
  describe 'Sign in' do
6
6
  shared_examples 'sign_in' do
7
7
  subject do
8
- visit '/users/sign_in'
8
+ visit '/u/categoria_de_cosas'
9
9
  fill_in 'user_email', with: user.email
10
10
  fill_in 'user_password', with: password
11
11
  find('input[type=submit]').click
@@ -13,7 +13,6 @@ describe 'Modal windows' do
13
13
  end
14
14
 
15
15
  let(:logged_user) { create :user, :developer }
16
- let(:account) { logged_user.current_account }
17
16
  let!(:categoria_de_cosa) { create :categoria_de_cosa }
18
17
 
19
18
  before do
@@ -42,6 +42,7 @@ describe 'Tenants' do
42
42
  visitar
43
43
 
44
44
  click_on other_account.to_s
45
+ visit '/u/categoria_de_cosas'
45
46
  expect(page).to have_text 'No hay categorías de cosas que mostrar'
46
47
  end
47
48
 
@@ -24,7 +24,11 @@ export default class extends Controller {
24
24
 
25
25
  disconnect () {
26
26
  if (this.popover) {
27
- this.popover.dispose()
27
+ // setTimeout because of:
28
+ // https://github.com/twbs/bootstrap/issues/37474
29
+ setTimeout(() => {
30
+ this.popover.dispose()
31
+ }, 300)
28
32
  }
29
33
  }
30
34
  }
@@ -30,7 +30,11 @@ export default class extends Controller {
30
30
 
31
31
  disconnect () {
32
32
  if (this.tooltip) {
33
- this.tooltip.dispose()
33
+ // setTimeout because of:
34
+ // https://github.com/twbs/bootstrap/issues/37474
35
+ setTimeout(() => {
36
+ this.tooltip.dispose()
37
+ }, 300)
34
38
  }
35
39
  }
36
40
  }
@@ -33,7 +33,7 @@
33
33
  <br>
34
34
  <ul style="max-width: 500px">
35
35
  <% User.order(:id).each do |user| %>
36
- <li><%= link_to user, admin_login_as_path(id: user.id) %></li>
36
+ <li><%= link_to user, login_as_path(id: user.id) %></li>
37
37
  <% end %>
38
38
  </ul>
39
39
  </div>
@@ -8,9 +8,8 @@
8
8
  <%= link_to users_account_switcher_path do %>
9
9
  <% if Rails.env.development? %>
10
10
  <span class="d-block px-3 text-secondary">Tenant: <%= ActsAsTenant.current_tenant || 'Global' %></span>
11
- <span class="d-block px-3 text-secondary">Cuenta: <%= Current.account || 'Global' %></span>
12
- <% elsif Current.account.present? %>
13
- <span class="d-block px-3 text-secondary"><%= Current.account %></span>
11
+ <% else %>
12
+ <span class="d-block px-3 text-secondary"><%= ActsAsTenant.current_tenant %></span>
14
13
  <% end %>
15
14
  <% end %>
16
15
  <hr>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRails
4
- VERSION = '7.5.0'
4
+ VERSION = '7.5.2'
5
5
  end
@@ -17,7 +17,7 @@ describe 'Generators', type: :generator do
17
17
  before { prepare_destination }
18
18
 
19
19
  it do
20
- run_generator(['Frontend/Modelo', 'bla:integer'])
20
+ run_generator(['users/modelo', 'bla:integer'])
21
21
 
22
22
  my_assert_file 'app/decorators/modelo_decorator.rb' do |content|
23
23
  expect(content).to match(/delegate_all/)
@@ -31,9 +31,9 @@ describe 'Generators', type: :generator do
31
31
  before { prepare_destination }
32
32
 
33
33
  it do
34
- run_generator(['Frontend/Modelo', 'bla:integer'])
34
+ run_generator(['users/modelo', 'bla:integer'])
35
35
 
36
- my_assert_file 'spec/controllers/frontend/modelos_controller_spec.rb' do |content|
36
+ my_assert_file 'spec/controllers/users/modelos_controller_spec.rb' do |content|
37
37
  expect(content).to match(/routing/)
38
38
  expect(content).to match(/sign_in/)
39
39
  end
@@ -46,7 +46,7 @@ describe 'Generators', type: :generator do
46
46
  before { prepare_destination }
47
47
 
48
48
  it do
49
- run_generator(['Frontend/Modelo', 'bla:integer', 'cosa:references', '--activeadmin'])
49
+ run_generator(['users/modelo', 'bla:integer', 'cosa:references', '--activeadmin'])
50
50
 
51
51
  my_assert_file 'app/admin/modelos.rb' do |content|
52
52
  expect(content).to match(/permit_params.*cosa_id/)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.5.0
4
+ version: 7.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martín Rosso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-10 00:00:00.000000000 Z
11
+ date: 2024-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -677,8 +677,12 @@ files:
677
677
  - pg_engine/app/controllers/admin/eventos_controller.rb
678
678
  - pg_engine/app/controllers/admin/user_accounts_controller.rb
679
679
  - pg_engine/app/controllers/admin/users_controller.rb
680
+ - pg_engine/app/controllers/concerns/pg_engine/require_tenant_set.rb
680
681
  - pg_engine/app/controllers/concerns/pg_engine/resource.rb
682
+ - pg_engine/app/controllers/pg_engine/base_admin_controller.rb
681
683
  - pg_engine/app/controllers/pg_engine/base_controller.rb
684
+ - pg_engine/app/controllers/pg_engine/base_public_controller.rb
685
+ - pg_engine/app/controllers/pg_engine/base_users_controller.rb
682
686
  - pg_engine/app/controllers/pg_engine/devise_controller.rb
683
687
  - pg_engine/app/controllers/pg_engine/health_controller.rb
684
688
  - pg_engine/app/controllers/pg_engine/require_sign_in.rb
@@ -729,6 +733,7 @@ files:
729
733
  - pg_engine/app/notifiers/email_user_notifier.rb
730
734
  - pg_engine/app/notifiers/simple_user_notifier.rb
731
735
  - pg_engine/app/overrides/activestorage_direct_uploads.rb
736
+ - pg_engine/app/overrides/audited_audit.rb
732
737
  - pg_engine/app/policies/account_policy.rb
733
738
  - pg_engine/app/policies/email_log_policy.rb
734
739
  - pg_engine/app/policies/email_policy.rb
@@ -867,6 +872,7 @@ files:
867
872
  - pg_engine/spec/models/pg_engine/base_record_spec.rb
868
873
  - pg_engine/spec/models/user_account_spec.rb
869
874
  - pg_engine/spec/models/user_spec.rb
875
+ - pg_engine/spec/overrides/audited_audit_spec.rb
870
876
  - pg_engine/spec/pg_engine/pdf_preview_generator_spec.rb
871
877
  - pg_engine/spec/requests/admin/eventos_spec.rb
872
878
  - pg_engine/spec/requests/base_controller_requests_spec.rb