pg_rails 7.0.5 → 7.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/pg_associable/lib/pg_associable/engine.rb +0 -4
- data/pg_associable/lib/pg_associable/simple_form_initializer.rb +2 -2
- data/pg_associable/spec/pg_associable/helpers_spec.rb +4 -3
- data/pg_engine/app/admin/accounts.rb +25 -0
- data/pg_engine/{lib/templates/activeadmin → app/admin}/audits.rb +3 -3
- data/pg_engine/app/admin/dashboard.rb +34 -0
- data/pg_engine/app/admin/user_accounts.rb +26 -0
- data/pg_engine/{lib/templates/activeadmin → app/admin}/users.rb +1 -2
- data/pg_engine/app/assets/javascripts/active_admin.js +1 -0
- data/pg_engine/app/assets/stylesheets/active_admin.scss +17 -0
- data/pg_engine/app/controllers/admin/accounts_controller.rb +33 -0
- data/pg_engine/app/controllers/admin/user_accounts_controller.rb +33 -0
- data/pg_engine/app/controllers/admin/users_controller.rb +47 -0
- data/pg_engine/app/controllers/pg_engine/resource_helper.rb +10 -5
- data/pg_engine/app/decorators/account_decorator.rb +16 -0
- data/pg_engine/app/decorators/pg_engine/base_decorator.rb +14 -12
- data/pg_engine/app/decorators/user_account_decorator.rb +19 -0
- data/pg_engine/app/decorators/user_decorator.rb +20 -0
- data/pg_engine/app/helpers/pg_engine/flash_helper.rb +1 -1
- data/pg_engine/app/models/account.rb +39 -0
- data/pg_engine/app/models/user.rb +61 -0
- data/pg_engine/app/models/user_account.rb +46 -0
- data/pg_engine/app/policies/account_policy.rb +31 -0
- data/pg_engine/app/policies/pg_engine/application_policy.rb +1 -1
- data/pg_engine/app/policies/user_account_policy.rb +31 -0
- data/pg_engine/app/policies/user_policy.rb +31 -0
- data/pg_engine/app/views/admin/accounts/_account.html.slim +1 -0
- data/pg_engine/app/views/admin/accounts/_form.html.slim +12 -0
- data/pg_engine/app/views/admin/accounts/edit.html.slim +5 -0
- data/pg_engine/app/views/admin/accounts/new.html.slim +5 -0
- data/pg_engine/app/views/admin/accounts/show.html.slim +27 -0
- data/pg_engine/app/views/admin/user_accounts/_form.html.slim +12 -0
- data/pg_engine/app/views/admin/user_accounts/_user_account.html.slim +1 -0
- data/pg_engine/app/views/admin/user_accounts/edit.html.slim +5 -0
- data/pg_engine/app/views/admin/user_accounts/new.html.slim +5 -0
- data/pg_engine/app/views/admin/user_accounts/show.html.slim +24 -0
- data/pg_engine/app/views/admin/users/_form.html.slim +12 -0
- data/pg_engine/app/views/admin/users/_user.html.slim +1 -0
- data/pg_engine/app/views/admin/users/edit.html.slim +5 -0
- data/pg_engine/app/views/admin/users/new.html.slim +5 -0
- data/pg_engine/app/views/admin/users/show.html.slim +27 -0
- data/pg_engine/config/initializers/active_admin.rb +355 -0
- data/pg_engine/config/initializers/devise.rb +313 -0
- data/pg_engine/config/locales/devise.en.yml +65 -0
- data/pg_engine/config/routes.rb +11 -0
- data/pg_engine/db/migrate/20240205194218_devise_create_users.rb +47 -0
- data/pg_engine/db/migrate/20240208234111_unaccent.rb +5 -0
- data/pg_engine/db/migrate/20240208234901_install_audited.rb +32 -0
- data/pg_engine/db/migrate/20240210025702_create_active_admin_comments.rb +16 -0
- data/pg_engine/db/migrate/20240211152951_create_accounts.rb +24 -0
- data/pg_engine/db/migrate/20240211153049_create_user_accounts.rb +20 -0
- data/pg_engine/db/seeds.rb +5 -0
- data/pg_engine/lib/pg_engine/core_ext.rb +14 -14
- data/pg_engine/lib/pg_engine/engine.rb +16 -2
- data/pg_engine/lib/pg_engine/route_helpers.rb +2 -2
- data/pg_engine/lib/tasks/auto_anotar_modelos.rake +2 -2
- data/pg_engine/spec/controllers/admin/accounts_controller_spec.rb +206 -0
- data/pg_engine/spec/controllers/admin/user_accounts_controller_spec.rb +189 -0
- data/pg_engine/spec/controllers/admin/users_controller_spec.rb +180 -0
- data/pg_engine/spec/factories/accounts.rb +11 -0
- data/pg_engine/spec/factories/user_accounts.rb +21 -0
- data/pg_engine/spec/factories/users.rb +59 -0
- data/pg_engine/spec/models/account_spec.rb +13 -0
- data/pg_engine/spec/models/user_account_spec.rb +13 -0
- data/pg_engine/spec/models/user_spec.rb +13 -0
- data/pg_layout/lib/pg_layout/engine.rb +0 -1
- data/pg_rails/lib/version.rb +1 -1
- data/pg_scaffold/lib/generators/pg_pundit/templates/policy.rb +1 -1
- data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +4 -4
- data/pg_scaffold/lib/generators/pg_slim/templates/show.html.slim +4 -4
- data/pg_scaffold/lib/pg_scaffold/monkey_patches/mejoras_de_atributos.rb +2 -2
- data/pg_scaffold/spec/generators_spec.rb +1 -1
- metadata +56 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c615490752a2afcaa4959f18c3b58bc214849a0912c308aea4b75a48122aa859
|
4
|
+
data.tar.gz: d4e8cc1fc2418a2691ef25607776de7ab1b6936367379cb4571c12925836933c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c7cad41dc0953598c49c7a48ca188e24a62d8dea1d1aed95f530e5eb92faa18bbf1033aac19c8adf963f759e7d0de52e905b4001354afb282373a257f8042be
|
7
|
+
data.tar.gz: 8ecd2f4a9617b57b3938f307502883681d70dab249a6f0fbb0789855b411465dac411ffe7dc3056ee0b49a40f84db8a77ce71739bd7dbc9ad81691b42c4de591
|
data/README.md
CHANGED
@@ -73,3 +73,16 @@ Acceder a la app en <http://localhost:3000/>.
|
|
73
73
|
4. `bundle exec rails g pg_scaffold Admin/CategoriaDeCosa nombre:string{required} "tipo:integer{enum,required}" fecha:date tiempo:datetime --model-name=CategoriaDeCosa --discard --activeadmin`
|
74
74
|
5. `bundle exec rails g pg_scaffold Admin/Cosa nombre:string{required} "tipo:integer{enum,required}" categoria_de_cosa:references{required} --model-name=Cosa --discard --activeadmin`
|
75
75
|
6. Setup asociacion creable en cosas/_form
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
be rake app:pg_engine_engine:install:migrations
|
80
|
+
|
81
|
+
be rails pg_engine_engine:install:migrations
|
82
|
+
|
83
|
+
|
84
|
+
"build": "esbuild pg_rails/js/index.js --bundle --sourcemap --format=esm --outdir=pg_rails/builds --public-path=/assets",
|
85
|
+
"build:css:compile": "sass ./pg_rails/scss/pg_rails.scss:./pg_rails/builds/application.css --no-source-map --load-path=node_modules",
|
86
|
+
"build:css:prefix": "postcss ./pg_rails/builds/application.css --use=autoprefixer --output=./pg_rails/builds/application.css",
|
87
|
+
"build:css": "yarn build:css:compile && yarn build:css:prefix",
|
88
|
+
|
@@ -1,9 +1,5 @@
|
|
1
|
-
require "#{__dir__}/../../app/helpers/pg_associable/helpers"
|
2
|
-
require "#{__dir__}/../../app/helpers/pg_associable/form_builder_methods"
|
3
|
-
|
4
1
|
module PgAssociable
|
5
2
|
class Engine < ::Rails::Engine
|
6
|
-
isolate_namespace PgAssociable
|
7
3
|
# initializer 'configurar_simple_form', after: 'factory_bot.set_fixture_replacement' do
|
8
4
|
initializer 'configurar_pg_scaffold' do
|
9
5
|
require 'pg_associable/simple_form_initializer'
|
@@ -3,7 +3,7 @@ SimpleForm.setup do |config|
|
|
3
3
|
error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
|
4
4
|
b.use :html5
|
5
5
|
b.optional :readonly
|
6
|
-
b.use :label, class: 'form-
|
6
|
+
b.use :label, class: 'form-label'
|
7
7
|
b.use :hidden_input
|
8
8
|
b.wrapper tag: 'div', class: 'position-relative' do |ba|
|
9
9
|
ba.use :input, class: 'form-control', disabled: true, placeholder: 'Clic para seleccionar...',
|
@@ -20,7 +20,7 @@ SimpleForm.setup do |config|
|
|
20
20
|
error_class: 'form-group-invalid', valid_class: 'form-group-valid' do |b|
|
21
21
|
b.use :html5
|
22
22
|
b.optional :readonly
|
23
|
-
b.use :label, class: 'form-
|
23
|
+
b.use :label, class: 'form-label'
|
24
24
|
b.use :hidden_input
|
25
25
|
b.wrapper tag: 'div', class: 'search-box position-relative' do |ba|
|
26
26
|
ba.use :search_form, error_class: 'is-invalid'
|
@@ -2,10 +2,11 @@ require 'rails_helper'
|
|
2
2
|
|
3
3
|
describe PgAssociable::Helpers do
|
4
4
|
describe '#pg_respond_buscar' do
|
5
|
-
let(:user) { create :user }
|
5
|
+
let(:user) { create :user, :developer }
|
6
6
|
let(:ctrl) do
|
7
|
-
clazz = Class.new(
|
8
|
-
clazz.new
|
7
|
+
# clazz = Class.new(Admin::CosasController)
|
8
|
+
# clazz.new
|
9
|
+
Admin::CosasController.new
|
9
10
|
end
|
10
11
|
let!(:cosa) { create :cosa }
|
11
12
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
ActiveAdmin.register Account do
|
2
|
+
permit_params :plan, :nombre, :hashid
|
3
|
+
|
4
|
+
index do
|
5
|
+
selectable_column
|
6
|
+
id_column
|
7
|
+
column :plan
|
8
|
+
column :nombre
|
9
|
+
column :hashid
|
10
|
+
actions
|
11
|
+
end
|
12
|
+
|
13
|
+
filter :plan
|
14
|
+
filter :nombre
|
15
|
+
filter :hashid
|
16
|
+
|
17
|
+
form do |f|
|
18
|
+
f.inputs do
|
19
|
+
f.input :plan
|
20
|
+
f.input :nombre
|
21
|
+
f.input :hashid
|
22
|
+
end
|
23
|
+
f.actions
|
24
|
+
end
|
25
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
ActiveAdmin.register Audited::Audit do
|
2
|
-
permit_params [
|
3
|
-
|
4
|
-
|
2
|
+
permit_params %i[auditable_id auditable_type associated_id associated_type user_id
|
3
|
+
user_type username action audited_changes version comment
|
4
|
+
remote_address request_uuid created_at]
|
5
5
|
|
6
6
|
# :id
|
7
7
|
# :discarded_at, :fecha, :nombre, :tiempo, :tipo, :created_at, :updated_at, :actualizado_por_id, :creado_por_id
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
ActiveAdmin.register_page 'Dashboard' do
|
4
|
+
menu priority: 1, label: proc { I18n.t('active_admin.dashboard') }
|
5
|
+
|
6
|
+
content title: proc { I18n.t('active_admin.dashboard') } do
|
7
|
+
div class: 'blank_slate_container', id: 'dashboard_default_message' do
|
8
|
+
span class: 'blank_slate' do
|
9
|
+
span I18n.t('active_admin.dashboard_welcome.welcome')
|
10
|
+
small I18n.t('active_admin.dashboard_welcome.call_to_action')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Here is an example of a simple dashboard with columns and panels.
|
15
|
+
#
|
16
|
+
# columns do
|
17
|
+
# column do
|
18
|
+
# panel "Recent Posts" do
|
19
|
+
# ul do
|
20
|
+
# Post.recent(5).map do |post|
|
21
|
+
# li link_to(post.title, admin_post_path(post))
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
# end
|
25
|
+
# end
|
26
|
+
|
27
|
+
# column do
|
28
|
+
# panel "Info" do
|
29
|
+
# para "Welcome to ActiveAdmin."
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
ActiveAdmin.register UserAccount do
|
2
|
+
decorate_with UserAccountDecorator
|
3
|
+
permit_params :user_id, :account_id, profiles: []
|
4
|
+
|
5
|
+
index do
|
6
|
+
selectable_column
|
7
|
+
id_column
|
8
|
+
column :user
|
9
|
+
column :account
|
10
|
+
column :profiles
|
11
|
+
actions
|
12
|
+
end
|
13
|
+
|
14
|
+
filter :user
|
15
|
+
filter :account
|
16
|
+
filter :profiles
|
17
|
+
|
18
|
+
form do |f|
|
19
|
+
f.inputs do
|
20
|
+
f.input :user
|
21
|
+
f.input :account
|
22
|
+
f.input :profiles, as: :select
|
23
|
+
end
|
24
|
+
f.actions
|
25
|
+
end
|
26
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
ActiveAdmin.register User do
|
2
2
|
decorate_with UserDecorator
|
3
|
-
permit_params :email, :password, :password_confirmation, :confirmed_at
|
3
|
+
permit_params :email, :password, :password_confirmation, :confirmed_at
|
4
4
|
|
5
5
|
index do
|
6
6
|
selectable_column
|
@@ -19,7 +19,6 @@ ActiveAdmin.register User do
|
|
19
19
|
else
|
20
20
|
f.input :email
|
21
21
|
f.input :password unless f.object.persisted?
|
22
|
-
f.input :profiles, as: :select
|
23
22
|
end
|
24
23
|
end
|
25
24
|
f.actions
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require active_admin/base
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// Sass variable overrides must be declared before loading up Active Admin's styles.
|
2
|
+
//
|
3
|
+
// To view the variables that Active Admin provides, take a look at
|
4
|
+
// `app/assets/stylesheets/active_admin/mixins/_variables.scss` in the
|
5
|
+
// Active Admin source.
|
6
|
+
//
|
7
|
+
// For example, to change the sidebar width:
|
8
|
+
// $sidebar-width: 242px;
|
9
|
+
|
10
|
+
// Active Admin's got SASS!
|
11
|
+
@import "active_admin/mixins";
|
12
|
+
@import "active_admin/base";
|
13
|
+
|
14
|
+
// Overriding any non-variable Sass must be done after the fact.
|
15
|
+
// For example, to change the default status-tag color:
|
16
|
+
//
|
17
|
+
// .status_tag { background: #6090DB; }
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# generado con pg_rails
|
4
|
+
|
5
|
+
module Admin
|
6
|
+
class AccountsController < AdminController
|
7
|
+
before_action { @clase_modelo = Account }
|
8
|
+
|
9
|
+
before_action(only: :index) { authorize Account }
|
10
|
+
|
11
|
+
before_action :set_instancia_modelo, only: %i[new create show edit update destroy]
|
12
|
+
|
13
|
+
add_breadcrumb Account.nombre_plural, :admin_accounts_path
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def atributos_permitidos
|
18
|
+
%i[plan nombre hashid]
|
19
|
+
end
|
20
|
+
|
21
|
+
def atributos_para_buscar
|
22
|
+
%i[plan nombre hashid]
|
23
|
+
end
|
24
|
+
|
25
|
+
def atributos_para_listar
|
26
|
+
%i[plan nombre hashid]
|
27
|
+
end
|
28
|
+
|
29
|
+
def atributos_para_mostrar
|
30
|
+
%i[plan nombre hashid]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# generado con pg_rails
|
4
|
+
|
5
|
+
module Admin
|
6
|
+
class UserAccountsController < AdminController
|
7
|
+
before_action { @clase_modelo = UserAccount }
|
8
|
+
|
9
|
+
before_action(only: :index) { authorize UserAccount }
|
10
|
+
|
11
|
+
before_action :set_instancia_modelo, only: %i[new create show edit update destroy]
|
12
|
+
|
13
|
+
add_breadcrumb UserAccount.nombre_plural, :admin_user_accounts_path
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def atributos_permitidos
|
18
|
+
%i[user_id account_id profiles]
|
19
|
+
end
|
20
|
+
|
21
|
+
def atributos_para_buscar
|
22
|
+
%i[user account profiles]
|
23
|
+
end
|
24
|
+
|
25
|
+
def atributos_para_listar
|
26
|
+
%i[user account profiles]
|
27
|
+
end
|
28
|
+
|
29
|
+
def atributos_para_mostrar
|
30
|
+
%i[user account profiles]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# generado con pg_rails
|
4
|
+
|
5
|
+
module Admin
|
6
|
+
class UsersController < AdminController
|
7
|
+
before_action { @clase_modelo = User }
|
8
|
+
|
9
|
+
before_action(only: :index) { authorize User }
|
10
|
+
|
11
|
+
before_action only: %i[update] do
|
12
|
+
params[:user].delete(:password) if params[:user][:password].blank?
|
13
|
+
end
|
14
|
+
|
15
|
+
before_action :set_instancia_modelo, only: %i[new create show edit update destroy]
|
16
|
+
|
17
|
+
add_breadcrumb User.nombre_plural, :admin_users_path
|
18
|
+
|
19
|
+
def create
|
20
|
+
@user.skip_confirmation!
|
21
|
+
pg_respond_create
|
22
|
+
end
|
23
|
+
|
24
|
+
def update
|
25
|
+
@user.skip_reconfirmation!
|
26
|
+
pg_respond_update
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def atributos_permitidos
|
32
|
+
%i[email password developer]
|
33
|
+
end
|
34
|
+
|
35
|
+
def atributos_para_buscar
|
36
|
+
%i[email developer]
|
37
|
+
end
|
38
|
+
|
39
|
+
def atributos_para_listar
|
40
|
+
%i[email developer]
|
41
|
+
end
|
42
|
+
|
43
|
+
def atributos_para_mostrar
|
44
|
+
%i[email developer]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -30,7 +30,7 @@ module PgEngine
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def new
|
33
|
-
add_breadcrumb
|
33
|
+
add_breadcrumb 'Crear'
|
34
34
|
end
|
35
35
|
|
36
36
|
def edit
|
@@ -71,21 +71,23 @@ module PgEngine
|
|
71
71
|
session[:page_size].present? ? session[:page_size].to_i : 10
|
72
72
|
end
|
73
73
|
|
74
|
-
def pg_respond_update
|
75
|
-
object
|
74
|
+
def pg_respond_update
|
75
|
+
object = instancia_modelo
|
76
76
|
respond_to do |format|
|
77
77
|
if (@saved = object.save)
|
78
78
|
format.html { redirect_to object.decorate.target_object }
|
79
79
|
format.json { render json: object.decorate }
|
80
80
|
else
|
81
|
+
# TODO: esto solucionaría el problema?
|
82
|
+
# self.instancia_modelo = instancia_modelo.decorate
|
81
83
|
format.html { render :edit, status: :unprocessable_entity }
|
82
84
|
format.json { render json: object.errors, status: :unprocessable_entity }
|
83
85
|
end
|
84
86
|
end
|
85
87
|
end
|
86
88
|
|
87
|
-
def pg_respond_create
|
88
|
-
object
|
89
|
+
def pg_respond_create
|
90
|
+
object = instancia_modelo
|
89
91
|
respond_to do |format|
|
90
92
|
if (@saved = object.save)
|
91
93
|
if params[:asociable]
|
@@ -107,6 +109,8 @@ module PgEngine
|
|
107
109
|
end
|
108
110
|
format.json { render json: object.decorate }
|
109
111
|
else
|
112
|
+
# TODO: esto solucionaría el problema?
|
113
|
+
# self.instancia_modelo = instancia_modelo.decorate
|
110
114
|
if params[:asociable]
|
111
115
|
format.turbo_stream do
|
112
116
|
render turbo_stream:
|
@@ -221,6 +225,7 @@ module PgEngine
|
|
221
225
|
authorize instancia_modelo
|
222
226
|
|
223
227
|
# TODO: problema en create y update cuando falla la validacion
|
228
|
+
# Reproducir el error antes de arreglarlo
|
224
229
|
self.instancia_modelo = instancia_modelo.decorate if action_name.in? %w[show edit new]
|
225
230
|
end
|
226
231
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# generado con pg_rails
|
4
|
+
|
5
|
+
class AccountDecorator < PgEngine::BaseDecorator
|
6
|
+
delegate_all
|
7
|
+
|
8
|
+
# Define presentation-specific methods here. Helpers are accessed through
|
9
|
+
# `helpers` (aka `h`). You can override attributes, for example:
|
10
|
+
#
|
11
|
+
# def created_at
|
12
|
+
# helpers.content_tag :span, class: 'time' do
|
13
|
+
# object.created_at.strftime("%a %m/%d/%y")
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
end
|
@@ -16,18 +16,20 @@ module PgEngine
|
|
16
16
|
object.as_json.tap { |o| o[:to_s] = to_s }
|
17
17
|
end
|
18
18
|
|
19
|
-
#
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
19
|
+
# rubocop:disable Style/MissingRespondToMissing
|
20
|
+
def method_missing(method_name, *args, &)
|
21
|
+
valor = object.attributes[method_name.to_s]
|
22
|
+
return super if valor.blank?
|
23
|
+
|
24
|
+
if valor.instance_of?(Date)
|
25
|
+
dmy(valor)
|
26
|
+
elsif valor.instance_of?(ActiveSupport::TimeWithZone)
|
27
|
+
dmy_time(valor)
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
# rubocop:enable Style/MissingRespondToMissing
|
31
33
|
|
32
34
|
def destroy_link(message = '¿Estás seguro?')
|
33
35
|
return unless Pundit.policy!(helpers.send(PgEngine.configuracion.current_user_method), object).destroy?
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# generado con pg_rails
|
4
|
+
|
5
|
+
class UserAccountDecorator < PgEngine::BaseDecorator
|
6
|
+
delegate_all
|
7
|
+
|
8
|
+
def profiles
|
9
|
+
object.profiles.join(', ')
|
10
|
+
end
|
11
|
+
# Define presentation-specific methods here. Helpers are accessed through
|
12
|
+
# `helpers` (aka `h`). You can override attributes, for example:
|
13
|
+
#
|
14
|
+
# def created_at
|
15
|
+
# helpers.content_tag :span, class: 'time' do
|
16
|
+
# object.created_at.strftime("%a %m/%d/%y")
|
17
|
+
# end
|
18
|
+
# end
|
19
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# generado con pg_rails
|
4
|
+
|
5
|
+
class UserDecorator < PgEngine::BaseDecorator
|
6
|
+
delegate_all
|
7
|
+
|
8
|
+
def default_module
|
9
|
+
:admin
|
10
|
+
end
|
11
|
+
|
12
|
+
# Define presentation-specific methods here. Helpers are accessed through
|
13
|
+
# `helpers` (aka `h`). You can override attributes, for example:
|
14
|
+
#
|
15
|
+
# def created_at
|
16
|
+
# helpers.content_tag :span, class: 'time' do
|
17
|
+
# object.created_at.strftime("%a %m/%d/%y")
|
18
|
+
# end
|
19
|
+
# end
|
20
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# == Schema Information
|
4
|
+
#
|
5
|
+
# Table name: accounts
|
6
|
+
#
|
7
|
+
# id :bigint not null, primary key
|
8
|
+
# discarded_at :datetime
|
9
|
+
# hashid :string
|
10
|
+
# nombre :string not null
|
11
|
+
# plan :integer not null
|
12
|
+
# created_at :datetime not null
|
13
|
+
# updated_at :datetime not null
|
14
|
+
# actualizado_por_id :bigint
|
15
|
+
# creado_por_id :bigint
|
16
|
+
#
|
17
|
+
# Indexes
|
18
|
+
#
|
19
|
+
# index_accounts_on_actualizado_por_id (actualizado_por_id)
|
20
|
+
# index_accounts_on_creado_por_id (creado_por_id)
|
21
|
+
#
|
22
|
+
# Foreign Keys
|
23
|
+
#
|
24
|
+
# fk_rails_... (actualizado_por_id => users.id)
|
25
|
+
# fk_rails_... (creado_por_id => users.id)
|
26
|
+
#
|
27
|
+
# generado con pg_rails
|
28
|
+
|
29
|
+
class Account < ApplicationRecord
|
30
|
+
audited
|
31
|
+
include Discard::Model
|
32
|
+
|
33
|
+
belongs_to :creado_por, optional: true, class_name: 'User'
|
34
|
+
belongs_to :actualizado_por, optional: true, class_name: 'User'
|
35
|
+
|
36
|
+
enumerize :plan, in: { completar: 0, los: 1, valores: 2 }
|
37
|
+
|
38
|
+
validates :plan, :nombre, presence: true
|
39
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# == Schema Information
|
2
|
+
#
|
3
|
+
# Table name: users
|
4
|
+
#
|
5
|
+
# id :bigint not null, primary key
|
6
|
+
# confirmation_sent_at :datetime
|
7
|
+
# confirmation_token :string
|
8
|
+
# confirmed_at :datetime
|
9
|
+
# current_sign_in_at :datetime
|
10
|
+
# current_sign_in_ip :string
|
11
|
+
# developer :boolean default(FALSE), not null
|
12
|
+
# discarded_at :datetime
|
13
|
+
# email :string default(""), not null
|
14
|
+
# encrypted_password :string default(""), not null
|
15
|
+
# failed_attempts :integer default(0), not null
|
16
|
+
# last_sign_in_at :datetime
|
17
|
+
# last_sign_in_ip :string
|
18
|
+
# locked_at :datetime
|
19
|
+
# remember_created_at :datetime
|
20
|
+
# reset_password_sent_at :datetime
|
21
|
+
# reset_password_token :string
|
22
|
+
# sign_in_count :integer default(0), not null
|
23
|
+
# unconfirmed_email :string
|
24
|
+
# unlock_token :string
|
25
|
+
# created_at :datetime not null
|
26
|
+
# updated_at :datetime not null
|
27
|
+
#
|
28
|
+
# Indexes
|
29
|
+
#
|
30
|
+
# index_users_on_confirmation_token (confirmation_token) UNIQUE
|
31
|
+
# index_users_on_email (email) UNIQUE
|
32
|
+
# index_users_on_reset_password_token (reset_password_token) UNIQUE
|
33
|
+
# index_users_on_unlock_token (unlock_token) UNIQUE
|
34
|
+
#
|
35
|
+
class User < ApplicationRecord
|
36
|
+
# ApplicationRecord should be defined on Application
|
37
|
+
|
38
|
+
# Include default devise modules. Others available are:
|
39
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
40
|
+
devise :database_authenticatable, :registerable,
|
41
|
+
:recoverable, :rememberable, :validatable,
|
42
|
+
:confirmable, :lockable, :timeoutable, :trackable
|
43
|
+
|
44
|
+
audited
|
45
|
+
include Discard::Model
|
46
|
+
|
47
|
+
has_many :user_accounts
|
48
|
+
has_many :accounts, through: :user_accounts
|
49
|
+
|
50
|
+
validates :email, presence: true
|
51
|
+
|
52
|
+
scope :query, ->(param) { where('email ILIKE ?', "%#{param}%") }
|
53
|
+
|
54
|
+
def to_s
|
55
|
+
email
|
56
|
+
end
|
57
|
+
|
58
|
+
def current_account
|
59
|
+
accounts.first
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# == Schema Information
|
4
|
+
#
|
5
|
+
# Table name: user_accounts
|
6
|
+
#
|
7
|
+
# id :bigint not null, primary key
|
8
|
+
# profiles :integer default([]), not null, is an Array
|
9
|
+
# created_at :datetime not null
|
10
|
+
# updated_at :datetime not null
|
11
|
+
# account_id :bigint not null
|
12
|
+
# actualizado_por_id :bigint
|
13
|
+
# creado_por_id :bigint
|
14
|
+
# user_id :bigint not null
|
15
|
+
#
|
16
|
+
# Indexes
|
17
|
+
#
|
18
|
+
# index_user_accounts_on_account_id (account_id)
|
19
|
+
# index_user_accounts_on_actualizado_por_id (actualizado_por_id)
|
20
|
+
# index_user_accounts_on_creado_por_id (creado_por_id)
|
21
|
+
# index_user_accounts_on_user_id (user_id)
|
22
|
+
#
|
23
|
+
# Foreign Keys
|
24
|
+
#
|
25
|
+
# fk_rails_... (account_id => accounts.id)
|
26
|
+
# fk_rails_... (actualizado_por_id => users.id)
|
27
|
+
# fk_rails_... (creado_por_id => users.id)
|
28
|
+
# fk_rails_... (user_id => users.id)
|
29
|
+
#
|
30
|
+
# generado con pg_rails
|
31
|
+
|
32
|
+
class UserAccount < ApplicationRecord
|
33
|
+
audited
|
34
|
+
|
35
|
+
belongs_to :user
|
36
|
+
belongs_to :account
|
37
|
+
|
38
|
+
belongs_to :creado_por, optional: true, class_name: 'User'
|
39
|
+
belongs_to :actualizado_por, optional: true, class_name: 'User'
|
40
|
+
|
41
|
+
enumerize :profiles, in: {
|
42
|
+
admin: 1,
|
43
|
+
dueño: 2,
|
44
|
+
invitado: 3
|
45
|
+
}, multiple: true
|
46
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# generado con pg_rails
|
4
|
+
|
5
|
+
class AccountPolicy < ApplicationPolicy
|
6
|
+
class Scope < ApplicationPolicy::Scope
|
7
|
+
# def resolve
|
8
|
+
# if policy.acceso_total?
|
9
|
+
# scope.all
|
10
|
+
# else
|
11
|
+
# scope.none
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
end
|
15
|
+
|
16
|
+
# def puede_editar?
|
17
|
+
# acceso_total? && !record.readonly?
|
18
|
+
# end
|
19
|
+
|
20
|
+
# def puede_crear?
|
21
|
+
# acceso_total? || user.asesor?
|
22
|
+
# end
|
23
|
+
|
24
|
+
# def puede_borrar?
|
25
|
+
# acceso_total? && !record.readonly?
|
26
|
+
# end
|
27
|
+
|
28
|
+
# def acceso_total?
|
29
|
+
# user.developer?
|
30
|
+
# end
|
31
|
+
end
|