pg_rails 7.0.8.pre.alpha.24 → 7.0.8.pre.alpha.26

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: a1e89c3437921de83649c5499b972831fe8bc9f4dd9d14ff01555825d0513f74
4
- data.tar.gz: 137eb256a8ee10a7692d9d41df0c29b9f955ab0cbfe18776e16087ba9baf0278
3
+ metadata.gz: 67cb2b4ac12dba97e33e5d859a101b7d38502c9be7366122c52e3c67102e26f5
4
+ data.tar.gz: 18426e296a8ac94c30540ac0ce01e6152e0b0cd4aa7ca0750d4f671d24bc3aa6
5
5
  SHA512:
6
- metadata.gz: d6b28222612e06a6007bde69fb0c85603a0f02281e18756e8371eb20aaf972d746886abb8077525f7bdf0a287879fe03f5ff1d0ffd77f035e4badef4ccb517f3
7
- data.tar.gz: 8dce15fca468b6cd28c1254ccb05c5267e832f926c46c4b7b2ad49e4b03a2eb25e5202a7f9d6e2a1796abf885fb981dfe5c00410be0b6e57d0b7c5604eb169bf
6
+ metadata.gz: 202ce67c321c3614f84ebae1be41329300ea76be4629381288e11658e58d374d7afcb990f9742dc30071f229dd47d04f610902228238af3f97da31dc62cd77a0
7
+ data.tar.gz: 8c97bc615beb0888ecc9f98636bba1ea7a181aa6c5723c80d29e4b8a40a4a6219cd2c0ef652be3e4c7548c0685e8daeb8f453425f6829410181b69b5debd2062
@@ -32,7 +32,7 @@ module Admin
32
32
 
33
33
  # :nocov:
34
34
  def login_as
35
- if current_user&.developer? || Rails.env.development?
35
+ if dev_user_or_env?
36
36
  usuario = User.find(params[:id])
37
37
  sign_in(:user, usuario)
38
38
  end
@@ -20,6 +20,7 @@ module PgEngine
20
20
  def index
21
21
  @collection = filtros_y_policy atributos_para_buscar
22
22
  @collection = sort_collection(@collection)
23
+ @records_filtered = policy_scope(clase_modelo).any? if @collection.empty?
23
24
  pg_respond_index
24
25
  end
25
26
 
@@ -11,10 +11,32 @@ module PgEngine
11
11
  include RouteHelper
12
12
  include PgAssociable::Helpers
13
13
 
14
+ class Redirect < PgEngine::Error
15
+ attr_accessor :url
16
+
17
+ def initialize(url)
18
+ @url = url
19
+ super
20
+ end
21
+ end
22
+
14
23
  protect_from_forgery with: :exception
15
24
 
16
25
  rescue_from PrintHelper::FechaInvalidaError, with: :fecha_invalida
17
26
  rescue_from Pundit::NotAuthorizedError, with: :not_authorized
27
+ rescue_from Redirect do |e|
28
+ redirect_to e.url
29
+ end
30
+
31
+ helper_method :dev_user_or_env?
32
+ def dev_user_or_env?
33
+ Rails.env.development? || dev_user?
34
+ end
35
+
36
+ helper_method :dev_user?
37
+ def dev_user?
38
+ current_user&.developer?
39
+ end
18
40
 
19
41
  helper_method :mobile_device?
20
42
 
@@ -49,6 +71,7 @@ module PgEngine
49
71
  # end
50
72
  # end
51
73
 
74
+ # TODO!: ver qué onda esto, tiene sentido acá?
52
75
  def fecha_invalida
53
76
  respond_to do |format|
54
77
  format.json do
@@ -2,16 +2,12 @@ module PgEngine
2
2
  class DeviseController < ApplicationController
3
3
  before_action :configure_permitted_parameters
4
4
 
5
- layout :layout_by_resource
5
+ layout :layout_by_user
6
6
 
7
7
  protected
8
8
 
9
- def layout_by_resource
10
- edit_registration? ? 'pg_layout/devise' : 'pg_layout/containerized'
11
- end
12
-
13
- def edit_registration?
14
- !(controller_name == 'registrations' && action_name.in?(%w[edit update]))
9
+ def layout_by_user
10
+ user_signed_in? ? 'pg_layout/containerized' : 'pg_layout/devise'
15
11
  end
16
12
 
17
13
  def configure_permitted_parameters
@@ -1,6 +1,11 @@
1
1
  module Users
2
2
  class RegistrationsController < Devise::RegistrationsController
3
3
  # POST /resource
4
+
5
+ before_action do
6
+ authorize User
7
+ end
8
+
4
9
  def create
5
10
  build_resource(sign_up_params)
6
11
 
@@ -0,0 +1,7 @@
1
+ module PgEngine
2
+ module I18nHelper
3
+ def controller_key
4
+ controller.class.to_s.underscore.sub(/_controller\z/, '')
5
+ end
6
+ end
7
+ end
@@ -1,9 +1,5 @@
1
1
  module PgEngine
2
2
  module PgRailsHelper
3
- def dev?
4
- Rails.env.development? || current_user&.developer?
5
- end
6
-
7
3
  def current_account
8
4
  current_user&.current_account
9
5
  end
@@ -4,7 +4,7 @@ module PgEngine
4
4
  module PrintHelper
5
5
  include ActionView::Helpers::NumberHelper
6
6
 
7
- class FechaInvalidaError < StandardError
7
+ class FechaInvalidaError < PgEngine::Error
8
8
  end
9
9
 
10
10
  def mostrar_con_link(objeto, options = {})
@@ -76,7 +76,7 @@ class User < ApplicationRecord
76
76
  "#{nombre} #{apellido}"
77
77
  end
78
78
 
79
- class Error < StandardError; end
79
+ class Error < PgEngine::Error; end
80
80
 
81
81
  def current_account
82
82
  raise Error, 'El usuario debe tener cuenta' if accounts.empty?
@@ -13,19 +13,7 @@ class UserPolicy < ApplicationPolicy
13
13
  # end
14
14
  end
15
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
16
+ def acceso_total?
17
+ true
18
+ end
31
19
  end
@@ -48,5 +48,14 @@ div
48
48
 
49
49
  .ps-3.justify-content-center
50
50
  = paginate(@collection)
51
+ - elsif @records_filtered
52
+ - i18n_key = "#{controller_key}.#{action_name}.index.empty_but_filtered"
53
+ p.m-3
54
+ = t(i18n_key, default: :'.empty_but_filtered', model: @clase_modelo.nombre_plural.downcase)
55
+ | :
56
+ span.ms-2
57
+ = link_to namespaced_path(@clase_modelo, clean: true) do
58
+ | Limpiar búsqueda
51
59
  - else
52
- p.m-3 No hay #{@clase_modelo.nombre_plural.downcase} que mostrar
60
+ - i18n_key = "#{controller_key}.#{action_name}.index.empty"
61
+ p.m-3 = t(i18n_key, default: :'.empty', model: @clase_modelo.nombre_plural.downcase)
@@ -1,4 +1,4 @@
1
- class MailDeliveryTemporalError < StandardError; end
1
+ class MailDeliveryTemporalError < PgEngine::Error; end
2
2
 
3
3
  ActionMailer::MailDeliveryJob.rescue_from EOFError,
4
4
  IOError,
@@ -1,4 +1,9 @@
1
1
  es:
2
+ pg_engine:
3
+ base:
4
+ index:
5
+ empty: 'No hay %{model} aún'
6
+ empty_but_filtered: 'No hay %{model} para los filtros aplicados'
2
7
  attributes:
3
8
  created_at: Fecha de creación
4
9
  updated_at: Fecha de actualización
@@ -47,6 +52,9 @@ es:
47
52
  blank: ''
48
53
  empty: ''
49
54
  devise:
55
+ sign_in: ¿Ya tenés una cuenta? Iniciar sesión
56
+ sign_out: Cerrar sesión
57
+ sign_up: Crear una cuenta
50
58
  registrations:
51
59
  new:
52
60
  sign_up: Crear una cuenta
@@ -56,7 +64,7 @@ es:
56
64
  forgot_your_password: ¿Olvidaste tu contraseña?
57
65
  shared:
58
66
  links:
67
+ sign_in: ¿Ya tenés una cuenta? Iniciar sesión
59
68
  sign_up: Crear una cuenta
60
69
  forgot_your_password: ¿Olvidaste tu contraseña?
61
- sign_out: Cerrar sesión
62
- didn_t_receive_confirmation_instructions: ¿No recibiste las instrucciones para confirmar tu cuenta?
70
+ didn_t_receive_confirmation_instructions: ¿No recibiste las instrucciones para confirmar tu cuenta?
@@ -47,6 +47,7 @@ module PgEngine
47
47
 
48
48
  private
49
49
 
50
+ # TODO: loguear time
50
51
  def notify(mensaje, type)
51
52
  Rails.logger.send(type, titulo(mensaje, type))
52
53
  Rails.logger.send(type, detalles(type))
@@ -0,0 +1,52 @@
1
+ require 'rails_helper'
2
+
3
+ class DummyBaseController < PgEngine::BaseController
4
+ def action_with_redirect
5
+ raise PgEngine::BaseController::Redirect, '/some_path'
6
+ end
7
+
8
+ def check_dev_user
9
+ @dev_user_or_env = dev_user_or_env?
10
+ @dev_user = dev_user?
11
+ head :ok
12
+ end
13
+ end
14
+
15
+ # rubocop:disable RSpec/MultipleExpectations
16
+ # rubocop:disable RSpec/FilePath
17
+ # rubocop:disable RSpec/SpecFilePathFormat
18
+ describe DummyBaseController do
19
+ describe 'PgEngine::BaseController::Redirect' do
20
+ before { get :action_with_redirect }
21
+
22
+ it do
23
+ expect(response).to redirect_to '/some_path'
24
+ end
25
+ end
26
+
27
+ describe '#dev_user_or_env?' do
28
+ let(:user) { create :user, :developer }
29
+
30
+ before do
31
+ sign_in user if user.present?
32
+ get :check_dev_user
33
+ end
34
+
35
+ it do
36
+ expect(assigns(:dev_user_or_env)).to be_truthy
37
+ expect(assigns(:dev_user)).to be_truthy
38
+ end
39
+
40
+ context 'when not signed in' do
41
+ let(:user) { nil }
42
+
43
+ it do
44
+ expect(assigns(:dev_user_or_env)).to be_falsey
45
+ expect(assigns(:dev_user)).to be_falsey
46
+ end
47
+ end
48
+ end
49
+ end
50
+ # rubocop:enable RSpec/MultipleExpectations
51
+ # rubocop:enable RSpec/FilePath
52
+ # rubocop:enable RSpec/SpecFilePathFormat
@@ -1,21 +1,26 @@
1
1
  class Navbar
2
2
  include Rails.application.routes.url_helpers
3
3
 
4
+ attr_reader :extensiones
5
+
4
6
  def initialize(user)
5
7
  @user = user
8
+ @yaml_data = YAML.load_file("#{Rails.application.root}/config/pg_rails.yml")
9
+ @yaml_data = ActiveSupport::HashWithIndifferentAccess.new(@yaml_data)
10
+ @extensiones = []
6
11
  end
7
12
 
8
- def topbar
9
- bar('topbar')
13
+ def add_html(html)
14
+ @extensiones << html
10
15
  end
11
16
 
12
- def sidebar
13
- bar('sidebar')
17
+ def add_item(key, obj)
18
+ @yaml_data[key] ||= []
19
+ @yaml_data[key] << ActiveSupport::HashWithIndifferentAccess.new(obj)
14
20
  end
15
21
 
16
22
  def bar(key)
17
- yaml_data = YAML.load_file("#{Rails.application.root}/config/pg_rails.yml")
18
- bar_data = ActiveSupport::HashWithIndifferentAccess.new(yaml_data)[key]
23
+ bar_data = @yaml_data[key]
19
24
  return [] if bar_data.blank?
20
25
 
21
26
  # rubocop:disable Security/Eval
@@ -20,13 +20,15 @@
20
20
 
21
21
  <%= render "devise/shared/links" %>
22
22
 
23
- <% if Rails.env.development? %>
23
+ <% if dev_user_or_env? %>
24
+ <div class="text-end" style="margin-top: 500px">
24
25
  <br>
25
26
  <br>
26
27
  <br>
27
- <ul>
28
- <% User.all.each do |user| %>
28
+ <ul style="max-width: 500px">
29
+ <% User.order(:id).each do |user| %>
29
30
  <li><%= link_to user, admin_login_as_path(id: user.id) %></li>
30
31
  <% end %>
31
32
  </ul>
33
+ </div>
32
34
  <% end %>
@@ -7,7 +7,7 @@ html
7
7
  meta name="turbo-cache-control" content="no-cache"
8
8
  / meta name="turbo-refresh-method" content="morph"
9
9
  / meta name="turbo-refresh-scroll" content="preserve"
10
- / meta name="turbo-prefetch" content="true"
10
+ meta name="turbo-prefetch" content="false"
11
11
  meta name="view-transition" content="same-origin"
12
12
  meta name="cable-history-timestamp" content="#{Time.now.to_i}"
13
13
  = csrf_meta_tags
@@ -27,7 +27,7 @@ html
27
27
  = render partial: 'pg_layout/flash'
28
28
  = render partial: 'pg_layout/navbar'
29
29
  div
30
- - if user_signed_in? && @breadcrumb != false
30
+ - if user_signed_in? && breadcrumbs.any?
31
31
  .d-flex.align-items-center.justify-content-between.px-3.py-1.d-print-none[
32
32
  style="min-height: 2.5em;"]
33
33
  nav aria-label="breadcrumb"
@@ -11,17 +11,26 @@
11
11
  <!-- <span class="navbar-toggler-icon"></span> -->
12
12
  </button>
13
13
  <div class="collapse navbar-collapse" id="navbarSupportedContent">
14
- <ul class="navbar-nav xme-auto mb-2 mb-lg-0">
14
+ <ul class="navbar-nav mb-2 mb-lg-0">
15
+ <% @navbar.bar('topbar.before').each do |entry| %>
16
+ <li class="nav-item">
17
+ <a class="nav-link" href="<%= entry[:path] %>">
18
+ <%= entry[:title] %>
19
+ </a>
20
+ </li>
21
+ <% end %>
15
22
  <% if user_signed_in? %>
16
23
  <li class="nav-item dropdown">
17
24
  <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
18
25
  <%= current_user %>
19
26
  </a>
20
27
  <ul class="dropdown-menu">
21
- <li>
22
- <%= link_to "Mi perfil", edit_user_registration_path, class: 'dropdown-item' %>
23
- </li>
24
- <% @navbar.topbar.each do |entry| %>
28
+ <% if policy(current_user).edit? %>
29
+ <li>
30
+ <%= link_to "Mi perfil", edit_user_registration_path, class: 'dropdown-item' %>
31
+ </li>
32
+ <% end %>
33
+ <% @navbar.bar('topbar.dropdown_user').each do |entry| %>
25
34
  <% next if @navbar.hide_entry?(entry) %>
26
35
  <li>
27
36
  <a class="dropdown-item" href="<%= entry[:path] %>">
@@ -31,11 +40,12 @@
31
40
  <% end %>
32
41
 
33
42
  <li>
34
- <%= link_to t("devise.shared.links.sign_out"), destroy_user_session_path, data: { 'turbo-method': 'delete' }, class: 'dropdown-item' %>
43
+ <%= link_to t("devise.sign_out"), destroy_user_session_path, data: { 'turbo-method': 'delete' }, class: 'dropdown-item' %>
35
44
  </li>
36
45
  </ul>
37
46
  </li>
38
- <% @navbar.sidebar.each do |entry| %>
47
+ <%# Los item de sidebar en mobile %>
48
+ <% @navbar.bar('sidebar').each do |entry| %>
39
49
  <% next if @navbar.hide_entry?(entry) %>
40
50
  <% random_id = rand(99999).to_s %>
41
51
  <li class="nav-item d-md-none">
@@ -47,15 +57,16 @@
47
57
 
48
58
  <% else %>
49
59
  <li class="nav-item">
50
- <%= link_to t("devise.shared.links.sign_in"), new_user_session_path, class: 'nav-link' %>
60
+ <%= link_to t("devise.sign_up"), new_user_registration_path, class: 'btn btn-success' %>
51
61
  </li>
52
62
  <li class="nav-item">
53
- <%= link_to t("devise.shared.links.sign_up"), new_user_registration_path, class: 'nav-link' %>
63
+ <%= link_to t("devise.sign_in"), new_user_session_path, class: 'nav-link' %>
54
64
  </li>
55
65
  <% end %>
56
66
  </ul>
57
- <%= @navbar_ext %>
58
-
67
+ <% @navbar.extensiones.each do |extension| %>
68
+ <%= extension %>
69
+ <% end %>
59
70
  </div>
60
71
  </div>
61
72
  </nav>
@@ -13,7 +13,7 @@
13
13
  </div> %>
14
14
  <div class="sidebar--large-items">
15
15
  <ul class="list-unstyled ps-0">
16
- <% @navbar.sidebar.each do |entry| %>
16
+ <% @navbar.bar('sidebar').each do |entry| %>
17
17
  <% next if @navbar.hide_entry?(entry) %>
18
18
  <% random_id = rand(99999).to_s %>
19
19
  <li class="mb-1">
@@ -0,0 +1,32 @@
1
+ require 'rails_helper'
2
+
3
+ describe Navbar do
4
+ let(:user) { create :user }
5
+ let(:instancia) { described_class.new(user) }
6
+
7
+ describe '#add_html' do
8
+ subject { instancia.add_html(some_html) }
9
+
10
+ let(:some_html) { '<p>Hola</p>' }
11
+
12
+ it do
13
+ expect { subject }.to(change(instancia, :extensiones))
14
+ end
15
+ end
16
+
17
+ describe '#add_item' do
18
+ subject { instancia.add_item('key', some_item) }
19
+
20
+ let(:some_item) do
21
+ {
22
+ name: 'Título',
23
+ path: 'root_path',
24
+ policy: 'true'
25
+ }
26
+ end
27
+
28
+ it do
29
+ expect { subject }.to(change { instancia.bar('key') })
30
+ end
31
+ end
32
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgRails
4
- VERSION = '7.0.8-alpha.24'
4
+ VERSION = '7.0.8-alpha.26'
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
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.24
4
+ version: 7.0.8.pre.alpha.26
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-04-03 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-04-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 7.1.3.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 7.1.3.2
13
27
  description: Rails goodies.
14
28
  email:
15
29
  - mrosso10@gmail.com
@@ -54,6 +68,7 @@ files:
54
68
  - pg_engine/app/decorators/user_decorator.rb
55
69
  - pg_engine/app/helpers/pg_engine/flash_helper.rb
56
70
  - pg_engine/app/helpers/pg_engine/form_helper.rb
71
+ - pg_engine/app/helpers/pg_engine/i18n_helper.rb
57
72
  - pg_engine/app/helpers/pg_engine/index_helper.rb
58
73
  - pg_engine/app/helpers/pg_engine/pg_rails_helper.rb
59
74
  - pg_engine/app/helpers/pg_engine/postgres_helper.rb
@@ -126,6 +141,7 @@ files:
126
141
  - pg_engine/spec/controllers/admin/users_controller_spec.rb
127
142
  - pg_engine/spec/controllers/concerns/pg_engine/resource_helper_spec.rb
128
143
  - pg_engine/spec/controllers/devise/sessions_controller_spec.rb
144
+ - pg_engine/spec/controllers/pg_engine/base_controller_spec.rb
129
145
  - pg_engine/spec/controllers/users/confirmations_controller_spec.rb
130
146
  - pg_engine/spec/controllers/users/registrations_controller_spec.rb
131
147
  - pg_engine/spec/factories/accounts.rb
@@ -188,6 +204,7 @@ files:
188
204
  - pg_layout/app/views/pg_layout/_sidebar.html.erb
189
205
  - pg_layout/lib/pg_layout.rb
190
206
  - pg_layout/lib/pg_layout/engine.rb
207
+ - pg_layout/spec/lib/navbar_spec.rb
191
208
  - pg_rails/js/index.js
192
209
  - pg_rails/lib/pg_rails.rb
193
210
  - pg_rails/lib/pg_rails/capybara_support.rb