pg_rails 7.6.20 → 7.6.21.pre.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/pg_associable/app/javascript/modal_controller.js +8 -4
  3. data/pg_associable/spec/pg_associable/helpers_spec.rb +8 -13
  4. data/pg_engine/app/components/inline_edit/inline_edit_component.html.slim +1 -1
  5. data/pg_engine/app/components/inline_edit/inline_show_component.html.slim +2 -2
  6. data/pg_engine/app/components/notifications_bell_component.rb +1 -1
  7. data/pg_engine/app/controllers/admin/accounts_controller.rb +2 -2
  8. data/pg_engine/app/controllers/admin/user_accounts_controller.rb +3 -3
  9. data/pg_engine/app/controllers/admin/users_controller.rb +4 -1
  10. data/pg_engine/app/controllers/concerns/pg_engine/resource.rb +12 -7
  11. data/pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb +33 -0
  12. data/pg_engine/app/controllers/pg_engine/base_admin_controller.rb +0 -1
  13. data/pg_engine/app/controllers/pg_engine/base_controller.rb +18 -21
  14. data/pg_engine/app/controllers/pg_engine/base_public_controller.rb +1 -1
  15. data/pg_engine/app/controllers/pg_engine/base_users_controller.rb +5 -3
  16. data/pg_engine/app/controllers/pg_engine/devise_controller.rb +4 -1
  17. data/pg_engine/app/controllers/pg_engine/tenant_controller.rb +22 -0
  18. data/pg_engine/app/controllers/{users → tenant}/dashboard_controller.rb +2 -2
  19. data/pg_engine/app/controllers/tenant/inline_edit_controller.rb +22 -0
  20. data/pg_engine/app/controllers/tenant/user_accounts_controller.rb +56 -0
  21. data/pg_engine/app/controllers/users/accounts_controller.rb +46 -15
  22. data/pg_engine/app/controllers/users/invitations_controller.rb +78 -0
  23. data/pg_engine/app/controllers/users/notifications_controller.rb +1 -0
  24. data/pg_engine/app/controllers/users/registrations_controller.rb +3 -2
  25. data/pg_engine/app/decorators/account_decorator.rb +18 -0
  26. data/pg_engine/app/decorators/pg_engine/base_record_decorator.rb +9 -1
  27. data/pg_engine/app/decorators/user_account_decorator.rb +76 -11
  28. data/pg_engine/app/helpers/pg_engine/accounts_helper.rb +9 -0
  29. data/pg_engine/app/helpers/pg_engine/frame_helper.rb +12 -0
  30. data/pg_engine/app/lib/pg_engine/default_url_options.rb +21 -0
  31. data/pg_engine/app/lib/pg_engine/filtros_builder.rb +2 -0
  32. data/pg_engine/app/models/account.rb +28 -1
  33. data/pg_engine/app/models/concerns/pg_engine/child_record.rb +55 -0
  34. data/pg_engine/app/models/current.rb +29 -3
  35. data/pg_engine/app/models/pg_engine/base_record.rb +5 -0
  36. data/pg_engine/app/models/user.rb +56 -14
  37. data/pg_engine/app/models/user_account.rb +74 -9
  38. data/pg_engine/app/policies/account_policy.rb +35 -16
  39. data/pg_engine/app/policies/email_log_policy.rb +0 -4
  40. data/pg_engine/app/policies/email_policy.rb +0 -4
  41. data/pg_engine/app/policies/pg_engine/base_policy.rb +31 -10
  42. data/pg_engine/app/policies/user_account_policy.rb +59 -25
  43. data/pg_engine/app/policies/user_policy.rb +14 -1
  44. data/pg_engine/app/views/admin/user_accounts/_form.html.slim +1 -1
  45. data/pg_engine/app/views/admin/user_accounts/show.html.slim +15 -0
  46. data/pg_engine/app/views/admin/users/show.html.slim +0 -3
  47. data/pg_engine/app/views/pg_engine/base/index.html.slim +2 -2
  48. data/pg_engine/app/views/tenant/dashboard/dashboard.html.slim +2 -0
  49. data/pg_engine/app/views/tenant/user_accounts/_fields.html.slim +13 -0
  50. data/pg_engine/app/views/tenant/user_accounts/_form.html.slim +9 -0
  51. data/pg_engine/app/views/tenant/user_accounts/show.html.slim +20 -0
  52. data/pg_engine/app/views/users/accounts/_form.html.slim +7 -0
  53. data/pg_engine/app/views/users/accounts/show.html.slim +23 -15
  54. data/pg_engine/config/initializers/acts_as_tenant.rb +7 -2
  55. data/pg_engine/config/initializers/devise.rb +10 -0
  56. data/pg_engine/config/initializers/ransack.rb +2 -0
  57. data/pg_engine/config/locales/es.yml +60 -0
  58. data/pg_engine/config/routes.rb +21 -11
  59. data/pg_engine/config/simple_form/simple_form_bootstrap.rb +2 -2
  60. data/pg_engine/db/migrate/20241023203849_devise_invitable.rb +14 -0
  61. data/pg_engine/db/migrate/20241027225618_add_membership_status_to_user_accounts.rb +6 -0
  62. data/pg_engine/db/seeds.rb +6 -6
  63. data/pg_engine/lib/pg_engine/configuracion.rb +36 -1
  64. data/pg_engine/lib/pg_engine/navigator.rb +2 -25
  65. data/pg_engine/lib/pg_engine.rb +1 -0
  66. data/pg_engine/spec/controllers/admin/accounts_controller_spec.rb +3 -2
  67. data/pg_engine/spec/controllers/admin/user_accounts_controller_spec.rb +11 -9
  68. data/pg_engine/spec/factories/accounts.rb +8 -0
  69. data/pg_engine/spec/factories/user_accounts.rb +1 -1
  70. data/pg_engine/spec/factories/users.rb +6 -0
  71. data/pg_engine/spec/models/concerns/pg_engine/child_record_spec.rb +27 -0
  72. data/pg_engine/spec/models/user_account_spec.rb +5 -1
  73. data/pg_engine/spec/models/user_spec.rb +3 -25
  74. data/pg_engine/spec/policies/account_policy_spec.rb +19 -0
  75. data/pg_engine/spec/requests/devise/invitations_spec.rb +196 -0
  76. data/pg_engine/spec/requests/resource_spec.rb +14 -15
  77. data/pg_engine/spec/requests/users/accounts_spec.rb +117 -8
  78. data/pg_engine/spec/requests/users/base_controller_spec.rb +31 -0
  79. data/pg_engine/spec/requests/users/dashboard_spec.rb +4 -9
  80. data/pg_engine/spec/requests/users/date_jumper_spec.rb +2 -1
  81. data/pg_engine/spec/requests/users/inline_edit_spec.rb +6 -5
  82. data/pg_engine/spec/requests/users/registrations_spec.rb +2 -2
  83. data/pg_engine/spec/requests/users/user_accounts_spec.rb +54 -0
  84. data/pg_engine/spec/system/login_spec.rb +2 -2
  85. data/pg_engine/spec/system/noticed_spec.rb +0 -2
  86. data/pg_engine/spec/system/signup_spec.rb +4 -3
  87. data/pg_engine/spec/system/tenants_spec.rb +10 -9
  88. data/pg_layout/app/javascript/application.js +1 -1
  89. data/pg_layout/app/javascript/config/turbo_rails/index.js +1 -1
  90. data/pg_layout/app/lib/navbar.rb +15 -1
  91. data/pg_layout/app/views/devise/invitations/edit.html.erb +34 -0
  92. data/pg_layout/app/views/devise/invitations/new.html.erb +15 -0
  93. data/pg_layout/app/views/devise/mailer/invitation_instructions.html.erb +11 -0
  94. data/pg_layout/app/views/devise/mailer/invitation_instructions.text.erb +11 -0
  95. data/pg_layout/app/views/devise/registrations/edit.html.erb +1 -0
  96. data/pg_layout/app/views/layouts/pg_layout/base.html.slim +7 -5
  97. data/pg_layout/app/views/pg_layout/_navbar.html.erb +7 -6
  98. data/pg_layout/app/views/pg_layout/_sidebar.html.erb +2 -20
  99. data/pg_layout/app/views/pg_layout/_signed_in_links.html.slim +52 -0
  100. data/pg_layout/lib/pg_layout.rb +0 -5
  101. data/pg_rails/lib/pg_rails/pundit_matchers.rb +21 -0
  102. data/pg_rails/lib/pg_rails/tpath_support.rb +73 -0
  103. data/pg_rails/lib/pg_rails.rb +6 -0
  104. data/pg_rails/lib/version.rb +1 -1
  105. data/pg_rails/scss/pg_rails.scss +1 -1
  106. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +1 -1
  107. data/pg_scaffold/lib/generators/pg_slim/templates/index.html.slim +1 -1
  108. metadata +43 -9
  109. data/pg_engine/app/controllers/concerns/pg_engine/require_tenant_set.rb +0 -15
  110. data/pg_engine/app/controllers/users/account_switcher_controller.rb +0 -30
  111. data/pg_engine/app/controllers/users/inline_edit_controller.rb +0 -21
  112. data/pg_engine/app/views/users/account_switcher/list.html.slim +0 -24
  113. data/pg_engine/app/views/users/dashboard/dashboard.html.slim +0 -1
  114. data/pg_engine/spec/requests/users/switcher_spec.rb +0 -84
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a76ffabfe4b54636335deff5bc216c0de26d6f0a6a7e42a5b54c6d3e1c065a7
4
- data.tar.gz: 72bd49ecd3d237d6aa083d54ec04f2d473a1c427e1c971b0ae77e65da94a4044
3
+ metadata.gz: 6698336321ce3bb886aa1de70219bab209e2f8b2f1b3f867282a29f1f1ebf5a5
4
+ data.tar.gz: fae76eef1209ba3e463740c8818ebd406a0b387eab151d964519fe0f5a389cec
5
5
  SHA512:
6
- metadata.gz: 3199b9c236fc31a94710715e1c64f6a40d90c0c3b391a3e7c73dc79723bdab3ecf4a55adba024002efbf5a95d3990aa0569c6ef08f4acfc55bc88a9f2bfc862f
7
- data.tar.gz: f4037520fd19acdf4e0c2b1564519431d35c5c6dd65dca12ee7b78bb97b83dd2b787077295e951cc28f4767dd3f71bede2b5fa52716b919c94256df9a0616245
6
+ metadata.gz: 55b7bc4417466c09110d4e48c4ee7355fdfc7bcf8e153592f9e0418fe518803953b73a6c3584274992aa3624cf6073b0ddab327e9971d7bb17923fbd176322ed
7
+ data.tar.gz: c51ce96d9af18a24111adc2130ae196290df313198561b4d6b23f59447b6d5d7762c5907bb1bcac59c7aabfbfc439b75324e06901d48de98181462b95c7e4582
@@ -90,12 +90,16 @@ export default class extends Controller {
90
90
  }
91
91
 
92
92
  reloadTop () {
93
- // FIXME: rename to main?
93
+ // TODO!!: rename to main?
94
94
  const topFrame = document.querySelector('#top')
95
- if (topFrame.attributes.src) {
96
- topFrame.reload()
95
+ if (topFrame) {
96
+ if (topFrame.attributes.src) {
97
+ topFrame.reload()
98
+ } else {
99
+ topFrame.setAttribute('src', window.location)
100
+ }
97
101
  } else {
98
- topFrame.setAttribute('src', window.location)
102
+ window.location.reload()
99
103
  }
100
104
  }
101
105
 
@@ -3,16 +3,8 @@ require 'rails_helper'
3
3
  describe PgAssociable::Helpers do
4
4
  include ActiveSupport::CurrentAttributes::TestHelper
5
5
 
6
- describe 'current attributes gets reset' do
7
- it 'sets a current attribute' do
8
- Current.user = 1
9
- expect(Current.namespace).to be_nil
10
- end
11
-
12
- it 'the attribute gets reset' do
13
- Current.namespace = 2
14
- expect(Current.user).to be_nil
15
- end
6
+ before do
7
+ Current.namespace = :admin
16
8
  end
17
9
 
18
10
  # DEPRECATED
@@ -21,10 +13,13 @@ describe PgAssociable::Helpers do
21
13
  Admin::CategoriaDeCosasController.new
22
14
  end
23
15
  let!(:categoria_de_cosa) { create :categoria_de_cosa }
16
+ let(:tid) do
17
+ Current.user.user_account_for(Current.account).to_param
18
+ end
24
19
 
25
20
  before do
26
- Current.user = create :user, :developer
27
- allow(ctrl).to receive_messages(params: { id: 123, query: categoria_de_cosa.nombre })
21
+ Current.user = create :user, :owner
22
+ allow(ctrl).to receive_messages(params: { id: 123, query: categoria_de_cosa.nombre, tid: })
28
23
  allow(ctrl).to receive(:render)
29
24
  end
30
25
 
@@ -42,7 +37,7 @@ describe PgAssociable::Helpers do
42
37
  let!(:cosa) { create :cosa }
43
38
 
44
39
  before do
45
- Current.user = create :user, :developer
40
+ Current.user = create :user, :owner
46
41
  allow(ctrl).to receive_messages(params: { id: 123, query: cosa.id })
47
42
  allow(ctrl).to receive(:render)
48
43
  end
@@ -13,7 +13,7 @@
13
13
  = button_tag class: 'btn btn-sm btn-primary',
14
14
  data: { controller: 'tooltip', 'bs-title': 'Guardar' } do
15
15
  i.bi.bi-check-lg
16
- = link_to users_inline_show_path(model: @model.to_gid, attribute: @attribute),
16
+ = link_to tenant_inline_show_path(model: @model.to_gid, attribute: @attribute),
17
17
  class: 'btn btn-sm btn-secondary',
18
18
  data: { controller: 'tooltip', 'bs-title': 'Cancelar' } do
19
19
  i.bi.bi-x-lg
@@ -1,10 +1,10 @@
1
- - if Current.namespace == :users && \
1
+ - if Current.namespace == :tenant && \
2
2
  @model.class.inline_editable?(@unsuffixed_attribute) && helpers.policy(@model).edit?
3
3
  = helpers.turbo_frame_tag(@frame_id, class: 'inline-edit')
4
4
  - if @record_updated
5
5
  pg-event[data-event-name="pg:record-updated" data-inline="true" data-turbo-temporary=""
6
6
  data-response='#{@model.decorate.to_json}']
7
- = link_to users_inline_edit_path(model: @model.to_gid, attribute: @attribute),
7
+ = link_to tenant_inline_edit_path(model: @model.to_gid, attribute: @attribute),
8
8
  data: { \
9
9
  controller: :tooltip,
10
10
  'bs-title': "Modificar #{@model.class.human_attribute_name(@attribute).downcase}" },
@@ -6,7 +6,7 @@ class NotificationsBellComponent < BaseComponent
6
6
  end
7
7
 
8
8
  erb_template <<~ERB
9
- <div>
9
+ <div class="d-flex">
10
10
  <% if @tooltip.present? %>
11
11
  <div class="d-inline-block text-white pg--notifications-bell--tooltip">
12
12
  <%= @tooltip %>
@@ -19,11 +19,11 @@ module Admin
19
19
  end
20
20
 
21
21
  def atributos_para_listar
22
- atributos_permitidos
22
+ %i[plan nombre domain subdomain owner]
23
23
  end
24
24
 
25
25
  def atributos_para_mostrar
26
- atributos_permitidos
26
+ %i[plan nombre domain subdomain owner]
27
27
  end
28
28
  end
29
29
  end
@@ -21,15 +21,15 @@ module Admin
21
21
  end
22
22
 
23
23
  def atributos_para_buscar
24
- %i[user account profiles]
24
+ %i[user account profiles_arr_cont]
25
25
  end
26
26
 
27
27
  def atributos_para_listar
28
- %i[user account profiles]
28
+ %i[user user_email_f account profiles_f]
29
29
  end
30
30
 
31
31
  def atributos_para_mostrar
32
- %i[user account profiles]
32
+ %i[user account]
33
33
  end
34
34
  end
35
35
  end
@@ -39,7 +39,10 @@ module Admin
39
39
  end
40
40
 
41
41
  def atributos_para_mostrar
42
- %i[email nombre apellido confirmed_at developer]
42
+ %i[email nombre apellido confirmed_at developer
43
+ current_sign_in_at current_sign_in_ip last_sign_in_at last_sign_in_ip
44
+ invitation_created_at invitation_sent_at invitation_accepted_at
45
+ invitation_limit invited_by]
43
46
  end
44
47
  end
45
48
  end
@@ -171,7 +171,7 @@ module PgEngine
171
171
  pg_respond_show
172
172
  end
173
173
 
174
- # FIXME: refactor
174
+ # TODO!: refactor
175
175
  def respond_with_modal(component)
176
176
  content = component.render_in(view_context)
177
177
 
@@ -199,7 +199,8 @@ module PgEngine
199
199
  component = ModalContentComponent.new(src: path)
200
200
  respond_with_modal(component)
201
201
  else
202
- if modal_targeted? && referred_by?(instancia_modelo)
202
+ if (modal_targeted? && referred_by?(instancia_modelo)) ||
203
+ !policy(instancia_modelo.object).show?
203
204
  add_breadcrumb instancia_modelo.to_s_short
204
205
  else
205
206
  add_breadcrumb instancia_modelo.to_s_short,
@@ -282,7 +283,7 @@ module PgEngine
282
283
  .gsub('%action_name%', action_name)
283
284
  .gsub('%request_format%', request.format.symbol.to_s)
284
285
  .gsub('%turbo_frame%', request.headers['Turbo-Frame'] || 'top')
285
- # FIXME: rename to main?
286
+ # TODO!!: rename to main?
286
287
  end
287
288
 
288
289
  def show_filters?
@@ -384,6 +385,7 @@ module PgEngine
384
385
  format.xlsx do
385
386
  render xlsx: 'download',
386
387
  filename: "#{clase_modelo.nombre_plural.gsub(' ', '-').downcase}" \
388
+ "#{action_name == 'archived' ? '-archivados' : ''}" \
387
389
  "-#{Time.zone.now.strftime('%Y-%m-%d-%H.%M.%S')}.xlsx"
388
390
  end
389
391
  end
@@ -414,7 +416,7 @@ module PgEngine
414
416
  # rubocop:disable Metrics/PerceivedComplexity
415
417
  def pg_respond_destroy(model, land_on = nil)
416
418
  if destroy_model(model)
417
- # FIXME: rename to main
419
+ # TODO!!: rename to main
418
420
  if turbo_frame? && current_turbo_frame != 'top'
419
421
  body = <<~HTML.html_safe
420
422
  <pg-event data-event-name="pg:record-destroyed" data-turbo-temporary>
@@ -529,9 +531,12 @@ module PgEngine
529
531
  end
530
532
 
531
533
  def filtros_y_policy(campos, dflt_sort = nil, archived: false)
532
- @filtros = PgEngine::FiltrosBuilder.new(
533
- self, clase_modelo, campos
534
- )
534
+ if campos.any?
535
+ @filtros = PgEngine::FiltrosBuilder.new(
536
+ self, clase_modelo, campos
537
+ )
538
+ end
539
+
535
540
  scope = default_scope_for_current_model(archived:)
536
541
 
537
542
  shared_context = Ransack::Adapters::ActiveRecord::Context.new(scope)
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PgEngine
4
+ module TenantHelper
5
+ # rubocop:disable Metrics/AbcSize
6
+ def set_tenant_from_params_or_fail!
7
+ if ActsAsTenant.current_tenant.present?
8
+ return unless Rails.env.test?
9
+
10
+ # Si es un controller test
11
+ # TODO: migrar a request
12
+ ua = Current.user.user_accounts.ua_active.where(account: ActsAsTenant.current_tenant).first
13
+ Current.active_user_account = ua
14
+
15
+ # Si no fue seteado por el domain
16
+
17
+ return
18
+ end
19
+
20
+ uaid = UserAccount.decode_id(params[:tid]) if params[:tid].present?
21
+
22
+ ua = ActsAsTenant.without_tenant do
23
+ Current.user.user_accounts.ua_active.where(id: uaid).first if uaid.present?
24
+ end
25
+
26
+ raise ActsAsTenant::Errors::NoTenantSet if ua.blank?
27
+
28
+ set_current_tenant(ua.account)
29
+ Current.active_user_account = ua
30
+ end
31
+ # rubocop:enable Metrics/AbcSize
32
+ end
33
+ end
@@ -11,7 +11,6 @@ module PgEngine
11
11
  end
12
12
 
13
13
  around_action :set_without_tenant
14
-
15
14
  def set_without_tenant(&)
16
15
  ActsAsTenant.without_tenant(&)
17
16
  end
@@ -10,20 +10,20 @@ module PgEngine
10
10
  set_current_tenant_by_subdomain_or_domain(:account, :subdomain, :domain)
11
11
  set_current_tenant_through_filter
12
12
 
13
+ include DefaultUrlOptions
14
+
13
15
  before_action do
14
16
  Current.user = current_user
15
17
  Current.controller = self
16
18
 
17
- # if ActsAsTenant.current_tenant.blank? && !global_domain?
18
- # raise ActsAsTenant::Errors::NoTenantSet
19
- # end
20
- # FIXME: if current_tenant.present? check it's not discarded
21
- # FIXME: if session['current_user_account'] present? check
22
- # user belongs to it, and if not, cleanup
23
19
  if Current.user.present?
24
- user_accounts = Current.user.user_accounts.kept
25
- if ActsAsTenant.current_tenant.present?
26
- unless user_accounts.exists?(account: ActsAsTenant.current_tenant)
20
+ active_user_accounts = Current.user.user_accounts.ua_active.to_a
21
+ if ActsAsTenant.current_tenant.present? && !Rails.env.test?
22
+ # TODO: los controller tests pasan por acá porque no se ejecuta
23
+ # el tenant middleware. afortunadamente eso hace que no haga falta
24
+ # el tid. igualmente cambiarlos a requests specs
25
+ # TODO: testear
26
+ unless active_user_accounts.any? { |uac| uac.account == ActsAsTenant.current_tenant }
27
27
  pg_warn <<~WARN
28
28
  #{Current.user.to_gid} not belongs to \
29
29
  #{ActsAsTenant.current_tenant.to_gid}. Signed out
@@ -34,14 +34,6 @@ module PgEngine
34
34
  end
35
35
 
36
36
  @current_tenant_set_by_domain_or_subdomain = true
37
- else
38
- account = if user_accounts.count == 1
39
- user_accounts.first.account
40
- elsif session['current_user_account'].present?
41
- user_accounts.where(id: session['current_user_account']).first&.account
42
- end
43
-
44
- set_current_tenant(account)
45
37
  end
46
38
  end
47
39
  end
@@ -88,9 +80,17 @@ module PgEngine
88
80
  end
89
81
 
90
82
  def no_tenant_set(error)
83
+ pg_debug(error)
91
84
  return internal_error(error) if Current.user.blank?
92
85
 
93
- redirect_to users_account_switcher_path
86
+ active_user_accounts = ActsAsTenant.without_tenant do
87
+ Current.user.user_accounts.ua_active.to_a
88
+ end
89
+ if active_user_accounts.length == 1 && params[:tid].blank?
90
+ redirect_to url_for(tid: active_user_accounts.first.to_param)
91
+ else
92
+ redirect_to users_accounts_path
93
+ end
94
94
  end
95
95
 
96
96
  def bad_user_input(error)
@@ -150,9 +150,6 @@ module PgEngine
150
150
  @navbar_opened_class = navbar_expanded ? 'opened' : ''
151
151
  @navbar_chevron_class = navbar_expanded ? 'bi-chevron-left' : 'bi-chevron-right'
152
152
  @navbar = Navbar.new
153
- PgEngine.configuracion.navigators.each do |navigator|
154
- navigator.configure(@navbar)
155
- end
156
153
 
157
154
  if defined?(Rollbar) && Rollbar.configuration.enabled && Rails.application.credentials.rollbar.present?
158
155
  @rollbar_token = Rails.application.credentials.rollbar.access_token_client
@@ -6,7 +6,7 @@ module PgEngine
6
6
 
7
7
  # :nocov:
8
8
  def login_as
9
- # FIXME: make a POST route
9
+ # TODO!: make a POST route
10
10
  return head :bad_request unless dev_user_or_env?
11
11
 
12
12
  Current.namespace = nil
@@ -1,13 +1,15 @@
1
1
  module PgEngine
2
2
  class BaseUsersController < ApplicationController
3
3
  include PgEngine::RequireSignIn
4
- include PgEngine::RequireTenantSet
5
4
 
6
5
  before_action do
7
- # FIXME: requisito que esto esté seteado
6
+ # TODO!: requisito que esto esté seteado
8
7
  Current.namespace = :users
9
8
 
10
- add_breadcrumb 'Inicio', :users_root_path unless using_modal2? || frame_embedded?
9
+ @other_active_accounts = ActsAsTenant.without_tenant do
10
+ Current.user.user_accounts.ua_active.to_a
11
+ end
12
+ @sidebar = false
11
13
  end
12
14
  end
13
15
  end
@@ -13,6 +13,7 @@ module PgEngine
13
13
  before_action :configure_permitted_parameters
14
14
  before_action do
15
15
  @no_main_frame = true
16
+ @sidebar = false
16
17
  end
17
18
 
18
19
  layout :layout_by_user
@@ -25,7 +26,9 @@ module PgEngine
25
26
 
26
27
  def configure_permitted_parameters
27
28
  devise_parameter_sanitizer.permit(:sign_up, keys: %i[nombre apellido accept_terms])
28
- devise_parameter_sanitizer.permit(:account_update, keys: %i[nombre apellido])
29
+ devise_parameter_sanitizer.permit(:account_update, keys: %i[nombre apellido avatar])
30
+ devise_parameter_sanitizer.permit(:invite, keys: [{ user_accounts_attributes: [{ profiles: [] }] }])
31
+ devise_parameter_sanitizer.permit(:accept_invitation, keys: %i[nombre apellido accept_terms])
29
32
  end
30
33
  end
31
34
  end
@@ -0,0 +1,22 @@
1
+ module PgEngine
2
+ class TenantController < ApplicationController
3
+ include PgEngine::RequireSignIn
4
+ include PgEngine::TenantHelper
5
+
6
+ before_action do
7
+ Current.namespace = :tenant
8
+
9
+ set_tenant_from_params_or_fail!
10
+
11
+ cid = Current.account.id
12
+ @other_active_accounts = ActsAsTenant.without_tenant do
13
+ Current.user.user_accounts.ua_active.where.not(account_id: cid).to_a
14
+ end
15
+
16
+ unless using_modal2? || frame_embedded? ||
17
+ (self.class.respond_to?(:skip_default_breadcrumb) && self.class.skip_default_breadcrumb)
18
+ add_breadcrumb 'Inicio', :tenant_root_path
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
- module Users
2
- class DashboardController < PgEngine.config.users_controller
1
+ module Tenant
2
+ class DashboardController < PgEngine::TenantController
3
3
  layout 'pg_layout/containerized'
4
4
 
5
5
  def dashboard
@@ -0,0 +1,22 @@
1
+ module Tenant
2
+ class InlineEditController < PgEngine::TenantController
3
+ before_action do
4
+ if current_turbo_frame.blank?
5
+ render_my_component(BadRequestComponent.new, :bad_request)
6
+ else
7
+ @model = GlobalID::Locator.locate params[:model]
8
+ authorize(@model)
9
+ end
10
+ end
11
+
12
+ def edit
13
+ attribute = params[:attribute]
14
+ render InlineEditComponent.new(@model, attribute), layout: false
15
+ end
16
+
17
+ def show
18
+ attribute = params[:attribute]
19
+ render InlineShowComponent.new(@model, attribute), layout: false
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ module Tenant
6
+ class UserAccountsController < PgEngine::TenantController
7
+ include PgEngine::Resource
8
+
9
+ self.clase_modelo = UserAccount
10
+ self.skip_default_breadcrumb = true
11
+
12
+ before_action do
13
+ @sidebar = false
14
+ unless modal_targeted? || frame_embedded?
15
+ add_breadcrumb Account.model_name.human(count: 2), ->(h) { h.users_accounts_path(tid: nil) }
16
+ add_breadcrumb ActsAsTenant.current_tenant, users_account_path(Current.account, tid: nil)
17
+ end
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)
33
+ end
34
+ end
35
+
36
+ def default_sort
37
+ 'id asc'
38
+ end
39
+
40
+ private
41
+
42
+ def atributos_permitidos
43
+ [
44
+ :membership_status, { profiles: [] }
45
+ ]
46
+ end
47
+
48
+ def atributos_para_buscar
49
+ []
50
+ end
51
+
52
+ def atributos_para_listar
53
+ %i[user user_email_f profiles_f estado_f]
54
+ end
55
+ end
56
+ end
@@ -2,30 +2,61 @@
2
2
 
3
3
  # generado con pg_rails
4
4
 
5
+ # TODO!: on index: (para cuando active los subdomains)
6
+ # - if @current_tenant_set_by_domain_or_subdomain
7
+ # p Estás en el dominio de #{ActsAsTenant.current_tenant} (#{request.host})
8
+ # p
9
+ # | Para cambiar de cuenta vas a tener que iniciar sesión en el dominio
10
+ # |< de Bien o de la cuenta específica a la que quieras cambiar
11
+
5
12
  module Users
6
13
  class AccountsController < UsersController
7
14
  include PgEngine::Resource
8
-
9
15
  self.clase_modelo = Account
10
- add_breadcrumb 'Cuentas'
11
16
  self.skip_default_breadcrumb = true
12
17
 
13
- # private
18
+ add_breadcrumb Account.model_name.human(count: 2), ->(h) { h.users_accounts_path(tid: nil) }
19
+
20
+ # La user_account puede estar disabled
21
+ def show
22
+ add_breadcrumb @account, users_account_path(@account, tid: nil)
23
+
24
+ @user_account = Current.user.user_account_for(@account).decorate
25
+ end
26
+
27
+ def update_invitation
28
+ set_instancia_modelo
29
+ @user_account = Current.user.user_account_for(@account)
30
+
31
+ invitation_status = if params[:reject] == '1'
32
+ :ist_rejected
33
+ elsif params[:sign_off] == '1'
34
+ :ist_signed_off
35
+ elsif params[:accept] == '1'
36
+ :ist_accepted
37
+ else
38
+ # :nocov:
39
+ raise PgEngine::BadUserInput, 'Solicitud incorrecta'
40
+ # :nocov:
41
+ end
42
+
43
+ @user_account.update(invitation_status:)
44
+
45
+ redirect_to users_accounts_path
46
+ end
14
47
 
15
- # def atributos_permitidos
16
- # %i[plan nombre domain subdomain]
17
- # end
48
+ private
18
49
 
19
- # def atributos_para_buscar
20
- # atributos_permitidos
21
- # end
50
+ def atributos_permitidos
51
+ %i[nombre logo plan]
52
+ end
22
53
 
23
- # def atributos_para_listar
24
- # atributos_permitidos
25
- # end
54
+ def atributos_para_buscar
55
+ []
56
+ end
26
57
 
27
- # def atributos_para_mostrar
28
- # atributos_permitidos
29
- # end
58
+ def atributos_para_listar
59
+ %i[nombre plan owner]
60
+ end
30
61
  end
31
62
  end
@@ -0,0 +1,78 @@
1
+ module Users
2
+ class InvitationsController < Devise::InvitationsController
3
+ include PgEngine::TenantHelper
4
+ before_action only: %i[new create] do
5
+ set_tenant_from_params_or_fail!
6
+
7
+ add_breadcrumb Account.model_name.human(count: 2), ->(h) { h.users_accounts_path(tid: nil) }
8
+ add_breadcrumb ActsAsTenant.current_tenant, users_account_path(ActsAsTenant.current_tenant)
9
+ add_breadcrumb 'Usuarios'
10
+ add_breadcrumb 'Agregar usuario'
11
+ @sidebar = false
12
+ @no_main_frame = true
13
+ end
14
+
15
+ def new
16
+ self.resource = resource_class.new
17
+ resource.user_accounts.build
18
+ render :new
19
+ end
20
+
21
+ def create
22
+ if params['user'].present? && params['user']['email'].present?
23
+ email = params['user']['email']
24
+ self.resource = ActsAsTenant.without_tenant do
25
+ User.find_by(email:)
26
+ end
27
+ end
28
+
29
+ if resource.present?
30
+ if resource.kept?
31
+ add_to_account(resource)
32
+ else
33
+ render_error(resource)
34
+ end
35
+ else
36
+ super
37
+ end
38
+ end
39
+
40
+ def after_invite_path_for(_inviter, _invitee)
41
+ # tenant_user_accounts_path
42
+ users_account_path(ActsAsTenant.current_tenant)
43
+ end
44
+
45
+ protected
46
+
47
+ def render_error(_resource)
48
+ new_user = User.new(invite_params)
49
+ self.resource = new_user
50
+ resource.errors.add(:email, 'pertenece a un usuario que no está disponible')
51
+ render :new, status: :unprocessable_entity
52
+ end
53
+
54
+ def add_to_account(resource)
55
+ new_user = User.new(invite_params)
56
+
57
+ user_account = new_user.user_accounts.first
58
+ user_account.invitation_status = :ist_invited
59
+ resource.user_accounts << user_account
60
+ if resource.valid?
61
+ respond_with resource, location: after_invite_path_for(current_inviter, resource)
62
+ else
63
+ if user_account_exists?(resource)
64
+ new_user.errors.add(:email, 'pertenece a un usuario de la cuenta')
65
+ else
66
+ new_user.errors.add(:base, resource.errors.full_messages.join(', '))
67
+ end
68
+ self.resource = new_user
69
+ render :new, status: :unprocessable_entity
70
+ end
71
+ end
72
+
73
+ def user_account_exists?(resource)
74
+ first = resource.errors.first
75
+ first.present? && first.attribute == :'user_accounts.user_id' && first.type == :taken
76
+ end
77
+ end
78
+ end
@@ -1,5 +1,6 @@
1
1
  module Users
2
2
  class NotificationsController < PgEngine.config.users_controller
3
+ # TODO: authorize
3
4
  def mark_as_unseen
4
5
  notification = Noticed::Notification.find(params[:id])
5
6
  notification.mark_as_unseen!