pg_rails 7.6.20 → 7.6.21.pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/pg_associable/app/javascript/modal_controller.js +8 -4
- data/pg_associable/spec/pg_associable/helpers_spec.rb +8 -13
- data/pg_engine/app/components/inline_edit/inline_edit_component.html.slim +1 -1
- data/pg_engine/app/components/inline_edit/inline_show_component.html.slim +2 -2
- data/pg_engine/app/components/notifications_bell_component.rb +1 -1
- data/pg_engine/app/controllers/admin/accounts_controller.rb +2 -2
- data/pg_engine/app/controllers/admin/user_accounts_controller.rb +3 -3
- data/pg_engine/app/controllers/admin/users_controller.rb +4 -1
- data/pg_engine/app/controllers/concerns/pg_engine/resource.rb +12 -7
- data/pg_engine/app/controllers/concerns/pg_engine/tenant_helper.rb +33 -0
- data/pg_engine/app/controllers/pg_engine/base_admin_controller.rb +0 -1
- data/pg_engine/app/controllers/pg_engine/base_controller.rb +18 -21
- data/pg_engine/app/controllers/pg_engine/base_public_controller.rb +1 -1
- data/pg_engine/app/controllers/pg_engine/base_users_controller.rb +5 -3
- data/pg_engine/app/controllers/pg_engine/devise_controller.rb +4 -1
- data/pg_engine/app/controllers/pg_engine/tenant_controller.rb +22 -0
- data/pg_engine/app/controllers/{users → tenant}/dashboard_controller.rb +2 -2
- data/pg_engine/app/controllers/tenant/inline_edit_controller.rb +22 -0
- data/pg_engine/app/controllers/tenant/user_accounts_controller.rb +56 -0
- data/pg_engine/app/controllers/users/accounts_controller.rb +46 -15
- data/pg_engine/app/controllers/users/invitations_controller.rb +78 -0
- data/pg_engine/app/controllers/users/notifications_controller.rb +1 -0
- data/pg_engine/app/controllers/users/registrations_controller.rb +3 -2
- data/pg_engine/app/decorators/account_decorator.rb +18 -0
- data/pg_engine/app/decorators/pg_engine/base_record_decorator.rb +9 -1
- data/pg_engine/app/decorators/user_account_decorator.rb +76 -11
- data/pg_engine/app/helpers/pg_engine/accounts_helper.rb +9 -0
- data/pg_engine/app/helpers/pg_engine/frame_helper.rb +12 -0
- data/pg_engine/app/lib/pg_engine/default_url_options.rb +21 -0
- data/pg_engine/app/lib/pg_engine/filtros_builder.rb +2 -0
- data/pg_engine/app/models/account.rb +28 -1
- data/pg_engine/app/models/concerns/pg_engine/child_record.rb +55 -0
- data/pg_engine/app/models/current.rb +29 -3
- data/pg_engine/app/models/pg_engine/base_record.rb +5 -0
- data/pg_engine/app/models/user.rb +56 -14
- data/pg_engine/app/models/user_account.rb +74 -9
- data/pg_engine/app/policies/account_policy.rb +35 -16
- data/pg_engine/app/policies/email_log_policy.rb +0 -4
- data/pg_engine/app/policies/email_policy.rb +0 -4
- data/pg_engine/app/policies/pg_engine/base_policy.rb +31 -10
- data/pg_engine/app/policies/user_account_policy.rb +59 -25
- data/pg_engine/app/policies/user_policy.rb +14 -1
- data/pg_engine/app/views/admin/user_accounts/_form.html.slim +1 -1
- data/pg_engine/app/views/admin/user_accounts/show.html.slim +15 -0
- data/pg_engine/app/views/admin/users/show.html.slim +0 -3
- data/pg_engine/app/views/pg_engine/base/index.html.slim +2 -2
- data/pg_engine/app/views/tenant/dashboard/dashboard.html.slim +2 -0
- data/pg_engine/app/views/tenant/user_accounts/_fields.html.slim +13 -0
- data/pg_engine/app/views/tenant/user_accounts/_form.html.slim +9 -0
- data/pg_engine/app/views/tenant/user_accounts/show.html.slim +20 -0
- data/pg_engine/app/views/users/accounts/_form.html.slim +7 -0
- data/pg_engine/app/views/users/accounts/show.html.slim +23 -15
- data/pg_engine/config/initializers/acts_as_tenant.rb +7 -2
- data/pg_engine/config/initializers/devise.rb +10 -0
- data/pg_engine/config/initializers/ransack.rb +2 -0
- data/pg_engine/config/locales/es.yml +60 -0
- data/pg_engine/config/routes.rb +21 -11
- data/pg_engine/config/simple_form/simple_form_bootstrap.rb +2 -2
- data/pg_engine/db/migrate/20241023203849_devise_invitable.rb +14 -0
- data/pg_engine/db/migrate/20241027225618_add_membership_status_to_user_accounts.rb +6 -0
- data/pg_engine/db/seeds.rb +6 -6
- data/pg_engine/lib/pg_engine/configuracion.rb +36 -1
- data/pg_engine/lib/pg_engine/navigator.rb +2 -25
- data/pg_engine/lib/pg_engine.rb +1 -0
- data/pg_engine/spec/controllers/admin/accounts_controller_spec.rb +3 -2
- data/pg_engine/spec/controllers/admin/user_accounts_controller_spec.rb +11 -9
- data/pg_engine/spec/factories/accounts.rb +8 -0
- data/pg_engine/spec/factories/user_accounts.rb +1 -1
- data/pg_engine/spec/factories/users.rb +6 -0
- data/pg_engine/spec/models/concerns/pg_engine/child_record_spec.rb +27 -0
- data/pg_engine/spec/models/user_account_spec.rb +5 -1
- data/pg_engine/spec/models/user_spec.rb +3 -25
- data/pg_engine/spec/policies/account_policy_spec.rb +19 -0
- data/pg_engine/spec/requests/devise/invitations_spec.rb +196 -0
- data/pg_engine/spec/requests/resource_spec.rb +14 -15
- data/pg_engine/spec/requests/users/accounts_spec.rb +117 -8
- data/pg_engine/spec/requests/users/base_controller_spec.rb +31 -0
- data/pg_engine/spec/requests/users/dashboard_spec.rb +4 -9
- data/pg_engine/spec/requests/users/date_jumper_spec.rb +2 -1
- data/pg_engine/spec/requests/users/inline_edit_spec.rb +6 -5
- data/pg_engine/spec/requests/users/registrations_spec.rb +2 -2
- data/pg_engine/spec/requests/users/user_accounts_spec.rb +54 -0
- data/pg_engine/spec/system/login_spec.rb +2 -2
- data/pg_engine/spec/system/noticed_spec.rb +0 -2
- data/pg_engine/spec/system/signup_spec.rb +4 -3
- data/pg_engine/spec/system/tenants_spec.rb +10 -9
- data/pg_layout/app/javascript/application.js +1 -1
- data/pg_layout/app/javascript/config/turbo_rails/index.js +1 -1
- data/pg_layout/app/lib/navbar.rb +15 -1
- data/pg_layout/app/views/devise/invitations/edit.html.erb +34 -0
- data/pg_layout/app/views/devise/invitations/new.html.erb +15 -0
- data/pg_layout/app/views/devise/mailer/invitation_instructions.html.erb +11 -0
- data/pg_layout/app/views/devise/mailer/invitation_instructions.text.erb +11 -0
- data/pg_layout/app/views/devise/registrations/edit.html.erb +1 -0
- data/pg_layout/app/views/layouts/pg_layout/base.html.slim +7 -5
- data/pg_layout/app/views/pg_layout/_navbar.html.erb +7 -6
- data/pg_layout/app/views/pg_layout/_sidebar.html.erb +2 -20
- data/pg_layout/app/views/pg_layout/_signed_in_links.html.slim +52 -0
- data/pg_layout/lib/pg_layout.rb +0 -5
- data/pg_rails/lib/pg_rails/pundit_matchers.rb +21 -0
- data/pg_rails/lib/pg_rails/tpath_support.rb +73 -0
- data/pg_rails/lib/pg_rails.rb +6 -0
- data/pg_rails/lib/version.rb +1 -1
- data/pg_rails/scss/pg_rails.scss +1 -1
- data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +1 -1
- data/pg_scaffold/lib/generators/pg_slim/templates/index.html.slim +1 -1
- metadata +43 -9
- data/pg_engine/app/controllers/concerns/pg_engine/require_tenant_set.rb +0 -15
- data/pg_engine/app/controllers/users/account_switcher_controller.rb +0 -30
- data/pg_engine/app/controllers/users/inline_edit_controller.rb +0 -21
- data/pg_engine/app/views/users/account_switcher/list.html.slim +0 -24
- data/pg_engine/app/views/users/dashboard/dashboard.html.slim +0 -1
- 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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6698336321ce3bb886aa1de70219bab209e2f8b2f1b3f867282a29f1f1ebf5a5
|
|
4
|
+
data.tar.gz: fae76eef1209ba3e463740c8818ebd406a0b387eab151d964519fe0f5a389cec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
//
|
|
93
|
+
// TODO!!: rename to main?
|
|
94
94
|
const topFrame = document.querySelector('#top')
|
|
95
|
-
if (topFrame
|
|
96
|
-
topFrame.
|
|
95
|
+
if (topFrame) {
|
|
96
|
+
if (topFrame.attributes.src) {
|
|
97
|
+
topFrame.reload()
|
|
98
|
+
} else {
|
|
99
|
+
topFrame.setAttribute('src', window.location)
|
|
100
|
+
}
|
|
97
101
|
} else {
|
|
98
|
-
|
|
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
|
-
|
|
7
|
-
|
|
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, :
|
|
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, :
|
|
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
|
|
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 == :
|
|
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
|
|
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}" },
|
|
@@ -21,15 +21,15 @@ module Admin
|
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def atributos_para_buscar
|
|
24
|
-
%i[user account
|
|
24
|
+
%i[user account profiles_arr_cont]
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def atributos_para_listar
|
|
28
|
-
%i[user account
|
|
28
|
+
%i[user user_email_f account profiles_f]
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
def atributos_para_mostrar
|
|
32
|
-
%i[user account
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
|
|
533
|
-
|
|
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
|
|
@@ -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
|
-
|
|
25
|
-
if ActsAsTenant.current_tenant.present?
|
|
26
|
-
|
|
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
|
-
|
|
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
|
|
@@ -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
|
-
#
|
|
6
|
+
# TODO!: requisito que esto esté seteado
|
|
8
7
|
Current.namespace = :users
|
|
9
8
|
|
|
10
|
-
|
|
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
|
|
@@ -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
|
-
|
|
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
|
-
|
|
16
|
-
# %i[plan nombre domain subdomain]
|
|
17
|
-
# end
|
|
48
|
+
private
|
|
18
49
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
50
|
+
def atributos_permitidos
|
|
51
|
+
%i[nombre logo plan]
|
|
52
|
+
end
|
|
22
53
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
54
|
+
def atributos_para_buscar
|
|
55
|
+
[]
|
|
56
|
+
end
|
|
26
57
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|