pg_rails 7.0.6 → 7.0.8.pre.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -0
  3. data/pg_associable/app/assets/{css → stylesheets}/pg_associable.scss +1 -1
  4. data/pg_associable/app/helpers/pg_associable/form_builder_methods.rb +2 -19
  5. data/pg_associable/app/helpers/pg_associable/helpers.rb +2 -1
  6. data/pg_associable/app/inputs/pg_associable_input.rb +53 -0
  7. data/pg_associable/app/javascript/asociable_controller.tsx +171 -0
  8. data/pg_associable/app/{assets/js → javascript}/modal_controller.js +6 -3
  9. data/pg_associable/app/views/pg_associable/_resultados.html.slim +3 -1
  10. data/pg_associable/app/views/pg_associable/_resultados_inline.html.slim +5 -2
  11. data/pg_associable/index.js +2 -4
  12. data/pg_associable/lib/pg_associable/engine.rb +0 -8
  13. data/pg_associable/spec/pg_associable/helpers_spec.rb +4 -3
  14. data/pg_engine/app/admin/accounts.rb +25 -0
  15. data/pg_engine/{lib/templates/activeadmin → app/admin}/audits.rb +3 -3
  16. data/pg_engine/app/admin/dashboard.rb +34 -0
  17. data/pg_engine/app/admin/user_accounts.rb +26 -0
  18. data/pg_engine/{lib/templates/activeadmin → app/admin}/users.rb +1 -2
  19. data/pg_engine/app/assets/javascripts/active_admin.js +1 -0
  20. data/pg_engine/app/assets/stylesheets/active_admin.scss +17 -0
  21. data/pg_engine/app/controllers/admin/accounts_controller.rb +33 -0
  22. data/pg_engine/app/controllers/admin/user_accounts_controller.rb +33 -0
  23. data/pg_engine/app/controllers/admin/users_controller.rb +47 -0
  24. data/pg_engine/app/controllers/pg_engine/resource_helper.rb +1 -0
  25. data/pg_engine/app/decorators/account_decorator.rb +16 -0
  26. data/pg_engine/app/decorators/user_account_decorator.rb +19 -0
  27. data/pg_engine/app/decorators/user_decorator.rb +20 -0
  28. data/pg_engine/app/helpers/pg_engine/flash_helper.rb +1 -1
  29. data/pg_engine/app/models/account.rb +39 -0
  30. data/pg_engine/app/models/user.rb +61 -0
  31. data/pg_engine/app/models/user_account.rb +46 -0
  32. data/pg_engine/app/policies/account_policy.rb +31 -0
  33. data/pg_engine/app/policies/pg_engine/application_policy.rb +1 -1
  34. data/pg_engine/app/policies/user_account_policy.rb +31 -0
  35. data/pg_engine/app/policies/user_policy.rb +31 -0
  36. data/pg_engine/app/views/admin/accounts/_account.html.slim +1 -0
  37. data/pg_engine/app/views/admin/accounts/_form.html.slim +12 -0
  38. data/pg_engine/app/views/admin/accounts/edit.html.slim +5 -0
  39. data/pg_engine/app/views/admin/accounts/new.html.slim +5 -0
  40. data/pg_engine/app/views/admin/accounts/show.html.slim +27 -0
  41. data/pg_engine/app/views/admin/user_accounts/_form.html.slim +12 -0
  42. data/pg_engine/app/views/admin/user_accounts/_user_account.html.slim +1 -0
  43. data/pg_engine/app/views/admin/user_accounts/edit.html.slim +5 -0
  44. data/pg_engine/app/views/admin/user_accounts/new.html.slim +5 -0
  45. data/pg_engine/app/views/admin/user_accounts/show.html.slim +24 -0
  46. data/pg_engine/app/views/admin/users/_form.html.slim +12 -0
  47. data/pg_engine/app/views/admin/users/_user.html.slim +1 -0
  48. data/pg_engine/app/views/admin/users/edit.html.slim +5 -0
  49. data/pg_engine/app/views/admin/users/new.html.slim +5 -0
  50. data/pg_engine/app/views/admin/users/show.html.slim +27 -0
  51. data/pg_engine/config/initializers/active_admin.rb +352 -0
  52. data/pg_engine/config/initializers/devise.rb +313 -0
  53. data/pg_engine/config/locales/devise.en.yml +65 -0
  54. data/pg_engine/config/routes.rb +11 -0
  55. data/pg_engine/db/migrate/20240205194218_devise_create_users.rb +47 -0
  56. data/pg_engine/db/migrate/20240208234111_unaccent.rb +5 -0
  57. data/pg_engine/db/migrate/20240208234901_install_audited.rb +32 -0
  58. data/pg_engine/db/migrate/20240210025702_create_active_admin_comments.rb +16 -0
  59. data/pg_engine/db/migrate/20240211152951_create_accounts.rb +24 -0
  60. data/pg_engine/db/migrate/20240211153049_create_user_accounts.rb +20 -0
  61. data/pg_engine/db/seeds.rb +8 -0
  62. data/pg_engine/lib/pg_engine/engine.rb +16 -2
  63. data/pg_engine/lib/tasks/auto_anotar_modelos.rake +1 -1
  64. data/pg_engine/spec/controllers/admin/accounts_controller_spec.rb +206 -0
  65. data/pg_engine/spec/controllers/admin/user_accounts_controller_spec.rb +189 -0
  66. data/pg_engine/spec/controllers/admin/users_controller_spec.rb +180 -0
  67. data/pg_engine/spec/factories/accounts.rb +11 -0
  68. data/pg_engine/spec/factories/user_accounts.rb +21 -0
  69. data/pg_engine/spec/factories/users.rb +59 -0
  70. data/pg_engine/spec/models/account_spec.rb +13 -0
  71. data/pg_engine/spec/models/user_account_spec.rb +13 -0
  72. data/pg_engine/spec/models/user_spec.rb +13 -0
  73. data/pg_layout/app/views/layouts/pg_layout/layout.html.slim +1 -0
  74. data/pg_layout/app/views/pg_layout/_flash.html.slim +1 -1
  75. data/pg_layout/lib/pg_layout/engine.rb +0 -1
  76. data/pg_rails/lib/version.rb +1 -1
  77. data/pg_rails/scss/pg_rails.scss +1 -1
  78. data/pg_scaffold/lib/generators/pg_pundit/templates/policy.rb +1 -1
  79. data/pg_scaffold/lib/generators/pg_rspec/scaffold/templates/controller_spec.rb +4 -4
  80. data/pg_scaffold/lib/generators/pg_slim/templates/_form.html.slim +1 -1
  81. data/pg_scaffold/spec/generators_spec.rb +1 -1
  82. metadata +62 -14
  83. data/pg_associable/app/assets/js/asociable_controller.js +0 -58
  84. data/pg_associable/app/assets/js/asociable_inline_controller.js +0 -142
  85. data/pg_associable/app/inputs/pg_associable/pg_associable_inline_input.rb +0 -39
  86. data/pg_associable/app/inputs/pg_associable/pg_associable_input.rb +0 -41
  87. data/pg_associable/lib/pg_associable/simple_form_initializer.rb +0 -34
  88. data/pg_associable/lib/tasks/pg_associable_tasks.rake +0 -4
@@ -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
@@ -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
@@ -1,7 +1,7 @@
1
1
  module PgEngine
2
2
  module FlashHelper
3
3
  def render_turbo_stream_flash_messages
4
- turbo_stream.prepend 'flash', partial: 'layouts/flash'
4
+ turbo_stream.prepend 'flash', partial: 'pg_layout/flash'
5
5
  end
6
6
 
7
7
  def render_turbo_stream_title
@@ -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
@@ -88,7 +88,7 @@ module PgEngine
88
88
  end
89
89
 
90
90
  def acceso_total?
91
- user&.admin?
91
+ user&.developer?
92
92
  end
93
93
 
94
94
  def objeto_borrado?
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ class UserAccountPolicy < 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
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # generado con pg_rails
4
+
5
+ class UserPolicy < 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
@@ -0,0 +1 @@
1
+ h1 el partiaaal
@@ -0,0 +1,12 @@
1
+ / # locals: (object: nil, asociable: false)
2
+
3
+ div style="max-width: 300px"
4
+ = pg_form_for(@account || object) do |f|
5
+ = f.mensajes_de_error
6
+
7
+ = hidden_field_tag :asociable, true if asociable
8
+ = f.input :plan
9
+ = f.input :nombre
10
+ = f.input :hashid
11
+ .mt-2
12
+ = f.button :submit
@@ -0,0 +1,5 @@
1
+ - content_for :title do
2
+ | Modificar #{@clase_modelo.nombre_singular.downcase}
3
+
4
+ .p-3
5
+ = render 'form'
@@ -0,0 +1,5 @@
1
+ - content_for :title do
2
+ | Crear #{@clase_modelo.nombre_singular.downcase}
3
+
4
+ .p-3
5
+ = render 'form'
@@ -0,0 +1,27 @@
1
+ - content_for :title do
2
+ = @account.to_s
3
+ - content_for :actions do
4
+ = @account.destroy_link
5
+ .ms-1
6
+ = @account.edit_link
7
+
8
+ table.table.table-borderless.table-sm.w-auto.mb-0.m-3
9
+ - atributos_para_mostrar.each do |att|
10
+ tr
11
+ th = @clase_modelo.human_attribute_name(att)
12
+ td = @account.send(att)
13
+ tr
14
+ th = t('attributes.creado_por')
15
+ td = @account.creado_por
16
+ tr
17
+ th = t('attributes.created_at')
18
+ td = @account.created_at
19
+ tr
20
+ th = t('attributes.actualizado_por')
21
+ td = @account.actualizado_por
22
+ tr
23
+ th = t('attributes.updated_at')
24
+ td = @account.updated_at
25
+ tr
26
+ th = t('attributes.discarded_at')
27
+ td = @account.discarded_at
@@ -0,0 +1,12 @@
1
+ / # locals: (object: nil, asociable: false)
2
+
3
+ div style="max-width: 300px"
4
+ = pg_form_for(@user_account || object) do |f|
5
+ = f.mensajes_de_error
6
+
7
+ = hidden_field_tag :asociable, true if asociable
8
+ = f.pg_associable :user
9
+ = f.pg_associable :account
10
+ = f.input :profiles
11
+ .mt-2
12
+ = f.button :submit
@@ -0,0 +1,5 @@
1
+ - content_for :title do
2
+ | Modificar #{@clase_modelo.nombre_singular.downcase}
3
+
4
+ .p-3
5
+ = render 'form'
@@ -0,0 +1,5 @@
1
+ - content_for :title do
2
+ | Crear #{@clase_modelo.nombre_singular.downcase}
3
+
4
+ .p-3
5
+ = render 'form'
@@ -0,0 +1,24 @@
1
+ - content_for :title do
2
+ = @user_account.to_s
3
+ - content_for :actions do
4
+ = @user_account.destroy_link
5
+ .ms-1
6
+ = @user_account.edit_link
7
+
8
+ table.table.table-borderless.table-sm.w-auto.mb-0.m-3
9
+ - atributos_para_mostrar.each do |att|
10
+ tr
11
+ th = @clase_modelo.human_attribute_name(att)
12
+ td = @user_account.send(att)
13
+ tr
14
+ th = t('attributes.creado_por')
15
+ td = @user_account.creado_por
16
+ tr
17
+ th = t('attributes.created_at')
18
+ td = @user_account.created_at
19
+ tr
20
+ th = t('attributes.actualizado_por')
21
+ td = @user_account.actualizado_por
22
+ tr
23
+ th = t('attributes.updated_at')
24
+ td = @user_account.updated_at
@@ -0,0 +1,12 @@
1
+ / # locals: (object: nil, asociable: false)
2
+
3
+ div style="max-width: 300px"
4
+ = pg_form_for(@user || object) do |f|
5
+ = f.mensajes_de_error
6
+
7
+ = hidden_field_tag :asociable, true if asociable
8
+ = f.input :email
9
+ = f.input :password, required: false, hint: 'Si se deja en blanco no se cambia'
10
+ = f.input :developer
11
+ .mt-2
12
+ = f.button :submit
@@ -0,0 +1 @@
1
+ h1 el partiaaal
@@ -0,0 +1,5 @@
1
+ - content_for :title do
2
+ | Modificar #{@clase_modelo.nombre_singular.downcase}
3
+
4
+ .p-3
5
+ = render 'form'
@@ -0,0 +1,5 @@
1
+ - content_for :title do
2
+ | Crear #{@clase_modelo.nombre_singular.downcase}
3
+
4
+ .p-3
5
+ = render 'form'
@@ -0,0 +1,27 @@
1
+ - content_for :title do
2
+ = @user.to_s
3
+ - content_for :actions do
4
+ = @user.destroy_link
5
+ .ms-1
6
+ = @user.edit_link
7
+
8
+ table.table.table-borderless.table-sm.w-auto.mb-0.m-3
9
+ - atributos_para_mostrar.each do |att|
10
+ tr
11
+ th = @clase_modelo.human_attribute_name(att)
12
+ td = @user.send(att)
13
+ / tr
14
+ th = t('attributes.creado_por')
15
+ td = @user.creado_por
16
+ tr
17
+ th = t('attributes.created_at')
18
+ td = @user.created_at
19
+ / tr
20
+ th = t('attributes.actualizado_por')
21
+ td = @user.actualizado_por
22
+ tr
23
+ th = t('attributes.updated_at')
24
+ td = @user.updated_at
25
+ tr
26
+ th = t('attributes.discarded_at')
27
+ td = @user.discarded_at