pg_rails 7.0.8.pre.alpha.9 → 7.0.8.pre.alpha.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 55efac7692668130210916f2d27c9d5f649660dc6a7341ea615fcfe66b263909
4
- data.tar.gz: 1827e613adbfbaed350d8d84f69131c302a14ef9b7f7cef0c2fc030171b13261
3
+ metadata.gz: d3efd952ef548d103ed1c4aea21b903f039792ed601fc66e93fb5b84dce4d39d
4
+ data.tar.gz: 148ae25de52ab06846c1b7b313f6f87db0d6d6ba502a9186104559e0e37ec114
5
5
  SHA512:
6
- metadata.gz: ca7acd8b6732ba7e5fb832b443a32d74d12490d013d1c0a72ed7bfbd499ce959f458815c22a980f9b94f81cdbddfa4e024e4b8de5533ab0f637ec7ed6c1de735
7
- data.tar.gz: 4335852cf4c82da4e90504ed5872472f5612378fb92b674bb3da4185c26fb040e81b55522bcf67dfe71db81c36fec146c112f4ff14bbc02832eb01dc481a03ee
6
+ metadata.gz: 68b63352e0ac30ff6f3c7a22e3a2fb73f8918ee91dfefe51b2c8371915c9d7adde99eb114c1ba935387182fa10966d0c5776c672e477486cff17a82993ff68fb
7
+ data.tar.gz: 1fda6ee9f5416f813e811268f307b87638b69de4a3db4659a7259c6101dc6b8281d9b351e92998e517a0d492cc39eea71780add28b2c240c4971aa26f87a2000
@@ -26,22 +26,34 @@ module Admin
26
26
  pg_respond_update
27
27
  end
28
28
 
29
+ skip_before_action :authenticate_user!, only: [:login_as]
30
+
31
+ # :nocov:
32
+ def login_as
33
+ if current_user&.developer? || Rails.env.development?
34
+ usuario = User.find(params[:id])
35
+ sign_in(:user, usuario)
36
+ end
37
+ redirect_to '/'
38
+ end
39
+ # :nocov:
40
+
29
41
  private
30
42
 
31
43
  def atributos_permitidos
32
- %i[email password developer]
44
+ %i[email nombre apellido password developer]
33
45
  end
34
46
 
35
47
  def atributos_para_buscar
36
- %i[email developer]
48
+ %i[email nombre apellido developer]
37
49
  end
38
50
 
39
51
  def atributos_para_listar
40
- %i[email developer]
52
+ %i[email nombre apellido developer]
41
53
  end
42
54
 
43
55
  def atributos_para_mostrar
44
- %i[email developer]
56
+ %i[email nombre apellido developer]
45
57
  end
46
58
  end
47
59
  end
@@ -74,8 +74,8 @@ module PgEngine
74
74
  end
75
75
  end
76
76
 
77
- def go_back(message)
78
- flash[:alert] = message
77
+ def go_back(message = nil, type: :alert)
78
+ flash[type] = message if message.present?
79
79
  redirect_back fallback_location: root_path
80
80
  end
81
81
  end
@@ -1,9 +1,22 @@
1
1
  module PgEngine
2
2
  class DeviseController < ApplicationController
3
- layout 'pg_layout/devise'
3
+ before_action :configure_permitted_parameters
4
4
 
5
- before_action do
6
- render(layout: 'pg_layout/layout') if controller_name == 'registrations' && action_name == 'edit'
5
+ layout :layout_by_resource
6
+
7
+ def layout_by_resource
8
+ if controller_name == 'registrations' && action_name.in?(%w[edit update])
9
+ 'pg_layout/layout'
10
+ else
11
+ 'pg_layout/devise'
12
+ end
13
+ end
14
+
15
+ protected
16
+
17
+ def configure_permitted_parameters
18
+ devise_parameter_sanitizer.permit(:sign_up, keys: %i[nombre apellido])
19
+ devise_parameter_sanitizer.permit(:account_update, keys: %i[nombre apellido])
7
20
  end
8
21
  end
9
22
  end
@@ -34,9 +34,12 @@ module PgEngine
34
34
  end
35
35
 
36
36
  def self.human_attribute_name(attribute, options = {})
37
- # Si es un enumerized
38
37
  if attribute.to_s.ends_with?('_text')
38
+ # Si es un enumerized
39
39
  super(attribute[0..-6], options)
40
+ elsif attribute.to_s.ends_with?('_f')
41
+ # Si es un decorated method
42
+ super(attribute[0..-3], options)
40
43
  else
41
44
  super(attribute, options)
42
45
  end
@@ -36,10 +36,9 @@ class User < ApplicationRecord
36
36
  # ApplicationRecord should be defined on Application
37
37
 
38
38
  # Include default devise modules. Others available are:
39
- # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
40
39
  devise :database_authenticatable, :registerable,
41
40
  :recoverable, :rememberable, :validatable,
42
- :confirmable, :lockable, :timeoutable, :trackable
41
+ :lockable, :timeoutable, :trackable, :confirmable
43
42
 
44
43
  audited
45
44
  include Discard::Model
@@ -47,12 +46,16 @@ class User < ApplicationRecord
47
46
  has_many :user_accounts
48
47
  has_many :accounts, through: :user_accounts
49
48
 
50
- validates :email, presence: true
49
+ validates :email, :nombre, :apellido, presence: true
51
50
 
52
51
  scope :query, ->(param) { where('email ILIKE ?', "%#{param}%") }
53
52
 
54
53
  def to_s
55
- email
54
+ nombre_completo
55
+ end
56
+
57
+ def nombre_completo
58
+ "#{nombre} #{apellido}"
56
59
  end
57
60
 
58
61
  def current_account
@@ -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'
@@ -6,6 +6,7 @@ Rails.application.routes.draw do
6
6
  pg_resource(:users)
7
7
  pg_resource(:accounts)
8
8
  pg_resource(:user_accounts)
9
+ get 'login_as', to: 'users#login_as'
9
10
  end
10
11
  ActiveAdmin.routes(self)
11
12
  end
@@ -0,0 +1,6 @@
1
+ class NombreUser < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :users, :nombre, :string, null: false
4
+ add_column :users, :apellido, :string, null: false
5
+ end
6
+ end
@@ -3,6 +3,6 @@ DatabaseCleaner.clean_with(:truncation, except: %w(ar_internal_metadata users ac
3
3
  MAIL = 'mrosso10@gmail.com'
4
4
 
5
5
  unless User.where(email: MAIL).exists?
6
- FactoryBot.create :user, email: MAIL, password: 'admin123',
6
+ FactoryBot.create :user, email: MAIL, nombre: 'Martín', apellido: 'Rosso', password: 'admin123',
7
7
  confirmed_at: Time.now, developer: true
8
8
  end
@@ -21,7 +21,8 @@ if Rails.env.development?
21
21
  'show_complete_foreign_keys' => 'false',
22
22
  'show_indexes' => 'false',
23
23
  'simple_indexes' => 'true',
24
- 'model_dir' => 'app/models',
24
+ 'model_dir' => ['app/models', 'app/overrides'],
25
+ # 'model_dir' => 'app/models',
25
26
  'root_dir' => '',
26
27
  'include_version' => 'false',
27
28
  'require' => '',
@@ -0,0 +1,33 @@
1
+ require 'rails_helper'
2
+
3
+ describe Devise::RegistrationsController do
4
+ before do
5
+ # rubocop:disable RSpec/InstanceVariable
6
+ @request.env['devise.mapping'] = Devise.mappings[:user]
7
+ # rubocop:enable RSpec/InstanceVariable
8
+ end
9
+
10
+ describe '#new' do
11
+ subject { get :new }
12
+
13
+ it do
14
+ subject
15
+ expect(response).to have_http_status(:ok)
16
+ end
17
+ end
18
+
19
+ describe '#edit' do
20
+ subject { get :edit }
21
+
22
+ let(:logger_user) { create :user, :admin }
23
+
24
+ before do
25
+ sign_in logger_user
26
+ end
27
+
28
+ it do
29
+ subject
30
+ expect(response).to have_http_status(:ok)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ require 'rails_helper'
2
+
3
+ describe Devise::SessionsController do
4
+ before do
5
+ # rubocop:disable RSpec/InstanceVariable
6
+ @request.env['devise.mapping'] = Devise.mappings[:user]
7
+ # rubocop:enable RSpec/InstanceVariable
8
+ end
9
+
10
+ describe '#new' do
11
+ subject { get :new }
12
+
13
+ it do
14
+ subject
15
+ expect(response).to have_http_status(:ok)
16
+ end
17
+ end
18
+ end
@@ -37,6 +37,8 @@
37
37
 
38
38
  FactoryBot.define do
39
39
  factory :orphan_user, class: 'User' do
40
+ nombre { Faker::Name.name }
41
+ apellido { Faker::Name.name }
40
42
  email { Faker::Internet.email }
41
43
  password { "password#{rand(99_999)}" }
42
44
  confirmed_at { Faker::Date.backward }
@@ -2,12 +2,14 @@ require 'rails_helper'
2
2
 
3
3
  describe PgEngine::BaseRecord do
4
4
  describe '#human_attribute_name' do
5
- subject do
6
- described_class.human_attribute_name('bla_text')
5
+ it do
6
+ obj = described_class.human_attribute_name('bla_text')
7
+ expect(obj).to eq described_class.human_attribute_name('bla')
7
8
  end
8
9
 
9
10
  it do
10
- expect(subject).to eq described_class.human_attribute_name('bla')
11
+ obj = described_class.human_attribute_name('bla_f')
12
+ expect(obj).to eq described_class.human_attribute_name('bla')
11
13
  end
12
14
  end
13
15
  end
@@ -5,15 +5,25 @@ class Navbar
5
5
  @user = user
6
6
  end
7
7
 
8
+ def topbar
9
+ bar('topbar')
10
+ end
11
+
8
12
  def sidebar
13
+ bar('sidebar')
14
+ end
15
+
16
+ def bar(key)
9
17
  yaml_data = YAML.load_file("#{Rails.application.root}/config/pg_rails.yml")
10
- sidebar = ActiveSupport::HashWithIndifferentAccess.new(yaml_data)['sidebar']
18
+ bar_data = ActiveSupport::HashWithIndifferentAccess.new(yaml_data)[key]
19
+ return [] if bar_data.blank?
20
+
11
21
  # rubocop:disable Security/Eval
12
- sidebar.map do |item|
22
+ bar_data.map do |item|
13
23
  {
14
24
  title: item['name'],
15
25
  path: eval(item['path']),
16
- show: true
26
+ show: item['policy'] ? eval(item['policy']) : true
17
27
  }
18
28
  end
19
29
  # rubocop:enable Security/Eval
@@ -5,6 +5,8 @@
5
5
 
6
6
  <div class="form-inputs">
7
7
  <%= f.input :email, required: true, autofocus: true %>
8
+ <%= f.input :nombre, required: true %>
9
+ <%= f.input :apellido, required: true %>
8
10
 
9
11
  <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
10
12
  <p><%= t(".currently_waiting_confirmation_for_email", email: resource.unconfirmed_email) %></p>
@@ -8,6 +8,8 @@
8
8
  required: true,
9
9
  autofocus: true ,
10
10
  input_html: { autocomplete: "email" }%>
11
+ <%= f.input :nombre, required: true %>
12
+ <%= f.input :apellido, required: true %>
11
13
  <%= f.input :password,
12
14
  required: true,
13
15
  hint: (t('devise.shared.minimum_password_length', count: @minimum_password_length) if @minimum_password_length),
@@ -18,3 +18,14 @@
18
18
  <% end %>
19
19
 
20
20
  <%= render "devise/shared/links" %>
21
+
22
+ <% if Rails.env.development? %>
23
+ <br>
24
+ <br>
25
+ <br>
26
+ <ul>
27
+ <% User.all.each do |user| %>
28
+ <li><%= link_to user, admin_login_as_path(id: user.id) %></li>
29
+ <% end %>
30
+ </ul>
31
+ <% end %>
@@ -3,8 +3,9 @@
3
3
  - flash_to_show = flash.select { |flash_message| flash_message[0].to_sym.in? ApplicationController._flash_types }
4
4
  / slim-lint:enable LineLength
5
5
 
6
+ / TODO: data-turbo-temporary, setear al activar toast?
6
7
  - flash_to_show.each do |flash_type, message|
7
8
  .toast(class="bg-#{flash_type_to_class(flash_type)}-subtle" role="alert" data-bs-autohide="true"
8
- data-turbo-temporary="true" aria-live="assertive" aria-atomic="true")
9
+ data-xturbo-temporary="true" aria-live="assertive" aria-atomic="true")
9
10
  .toast-body
10
11
  = message
@@ -9,16 +9,25 @@
9
9
  <!-- <span class="navbar-toggler-icon"></span> -->
10
10
  </button>
11
11
  <div class="collapse navbar-collapse" id="navbarSupportedContent">
12
- <ul class="navbar-nav me-auto mb-2 mb-lg-0">
12
+ <ul class="navbar-nav xme-auto mb-2 mb-lg-0">
13
13
  <% if user_signed_in? %>
14
14
  <li class="nav-item dropdown">
15
15
  <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
16
- <%= current_user.email %>
16
+ <%= current_user %>
17
17
  </a>
18
18
  <ul class="dropdown-menu">
19
19
  <li>
20
20
  <%= link_to "Mi perfil", edit_user_registration_path, class: 'dropdown-item' %>
21
21
  </li>
22
+ <% @navbar.topbar.each do |entry| %>
23
+ <% next if @navbar.hide_entry?(entry) %>
24
+ <li>
25
+ <a class="dropdown-item" href="<%= entry[:path] %>">
26
+ <%= entry[:title] %>
27
+ </a>
28
+ </li>
29
+ <% end %>
30
+
22
31
  <li>
23
32
  <%= link_to "Cerrar sesión", destroy_user_session_path, data: { 'turbo-method': 'delete' }, class: 'dropdown-item' %>
24
33
  </li>
@@ -40,6 +49,8 @@
40
49
  </li>
41
50
  <% end %>
42
51
  </ul>
52
+ <%= content_for :navbar_ext %>
53
+
43
54
  </div>
44
55
  </div>
45
56
  </nav>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRails
4
- VERSION = '7.0.8-alpha.9'
4
+ VERSION = '7.0.8-alpha.10'
5
5
  end
@@ -23,9 +23,9 @@ class PgSlimGenerator < Slim::Generators::ScaffoldGenerator
23
23
 
24
24
  def available_views
25
25
  if options[:index_file]
26
- %w[index edit show new _form]
26
+ %w[index show _form]
27
27
  else
28
- %w[edit show new _form]
28
+ %w[show _form]
29
29
  end
30
30
  end
31
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.8.pre.alpha.9
4
+ version: 7.0.8.pre.alpha.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martín Rosso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-01 00:00:00.000000000 Z
11
+ date: 2024-03-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Rails goodies.
14
14
  email:
@@ -84,7 +84,9 @@ files:
84
84
  - pg_engine/app/views/admin/users/new.html.slim
85
85
  - pg_engine/app/views/admin/users/show.html.slim
86
86
  - pg_engine/app/views/pg_engine/base/download.xlsx.axlsx
87
+ - pg_engine/app/views/pg_engine/base/edit.html.slim
87
88
  - pg_engine/app/views/pg_engine/base/index.html.slim
89
+ - pg_engine/app/views/pg_engine/base/new.html.slim
88
90
  - pg_engine/config/initializers/active_admin.rb
89
91
  - pg_engine/config/initializers/devise.rb
90
92
  - pg_engine/config/locales/devise.en.yml
@@ -99,6 +101,7 @@ files:
99
101
  - pg_engine/db/migrate/20240211152951_create_accounts.rb
100
102
  - pg_engine/db/migrate/20240211153049_create_user_accounts.rb
101
103
  - pg_engine/db/migrate/20240222115722_create_active_storage_tables.active_storage.rb
104
+ - pg_engine/db/migrate/20240305200900_nombre_user.rb
102
105
  - pg_engine/db/seeds.rb
103
106
  - pg_engine/lib/pg_engine.rb
104
107
  - pg_engine/lib/pg_engine/configuracion.rb
@@ -112,6 +115,8 @@ files:
112
115
  - pg_engine/spec/controllers/admin/user_accounts_controller_spec.rb
113
116
  - pg_engine/spec/controllers/admin/users_controller_spec.rb
114
117
  - pg_engine/spec/controllers/concerns/pg_engine/error_helper_spec.rb
118
+ - pg_engine/spec/controllers/devise/registrations_controller_spec.rb
119
+ - pg_engine/spec/controllers/devise/sessions_controller_spec.rb
115
120
  - pg_engine/spec/factories/accounts.rb
116
121
  - pg_engine/spec/factories/user_accounts.rb
117
122
  - pg_engine/spec/factories/users.rb