itsf_backend 1.1.7 → 1.1.8

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
  SHA1:
3
- metadata.gz: 0be05c7a7fd7f6d0fb8391a79bd47350b7d9ea00
4
- data.tar.gz: 2ecc683d46c48fae5c150dd93a42d6a0c5d7a9b8
3
+ metadata.gz: 7b421756702587ef74370ab1010ab5535623d270
4
+ data.tar.gz: 94d3ee99c2857d4abf02c76d9a1d116100aaf498
5
5
  SHA512:
6
- metadata.gz: fb484cf8858f22721a11804340796539a09189bfb7d8acaf5595c14e7aa108b56087d9ccd08192215517c6abc0f4d9cc9305efe78156c7fc8bbfc63d58bb88d8
7
- data.tar.gz: dd9deebdf4828fcb22be500b5caeaa027027d8cf35b3088076cf4194f31da6c8a6505a4c369a59f84ef3de6f85cc022d2f785af446bf8ca8417f57bb2bd03b81
6
+ metadata.gz: 8a0af1ca63b6d8ca0885b5f72a1f3010764042468a3e0a6063a7fe15f245a4597e2e917781e60ce0cb956beeffe31e8ae03808a7db408fcd5b4dd2cd22ee3f8d
7
+ data.tar.gz: 537f2e9615e687a3f5160263d49cd9f03ad3b765a988d989e98e5d0422e2da259a1e4140f412f6c376df99202cc61eb83eaac980c609becb6319779c7899b8d5
@@ -0,0 +1,21 @@
1
+ module Controller
2
+ module PunditAuthorizationFailureHandlingConcern
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ rescue_from Pundit::NotAuthorizedError, with: :not_authorized
7
+ end
8
+
9
+ private
10
+
11
+ def not_authorized(exception)
12
+ resource_name = exception.record.respond_to?(:model_name) ? exception.record.model_name.human : exception.record
13
+ collection_name = exception.record.respond_to?(:model_name) ? exception.record.model_name.human(count: :other) : exception.record
14
+ flash[:error] = I18n.t("pundit.not_authorized.#{action_name}", collection_name: collection_name,resource_name: resource_name)
15
+ respond_to do |format|
16
+ format.html { redirect_to main_app.root_path }
17
+ format.json { render json: { error: 'not authorized' }, status: 403 }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -7,6 +7,7 @@ module Controller
7
7
  responders :flash
8
8
  end
9
9
 
10
+
10
11
  def index
11
12
  if Itsf::Backend.features?(:ransack)
12
13
  @q = collection_scope_with_search_scopes(collection_scope).ransack(params[:q])
@@ -19,7 +20,7 @@ module Controller
19
20
  end
20
21
 
21
22
  def new
22
- @resource = resource_class.new
23
+ @resource = initialize_resource
23
24
  authorize_action
24
25
  respond_with @resource
25
26
  end
@@ -57,6 +58,7 @@ module Controller
57
58
  respond_with @resource, location: after_destroy_location
58
59
  end
59
60
 
61
+
60
62
  private
61
63
 
62
64
  def after_create_location
@@ -93,6 +95,10 @@ module Controller
93
95
  resource_class
94
96
  end
95
97
 
98
+ def initialize_resource
99
+ resource_class.new
100
+ end
101
+
96
102
  def load_resource
97
103
  resource_class.find(params[:id])
98
104
  end
@@ -8,6 +8,7 @@ module Itsf::Backend
8
8
  if Itsf::Backend.features?(:pundit)
9
9
  include Pundit
10
10
  prepend Controller::PunditNamespacedAuthorizeConcern
11
+ include Controller::PunditAuthorizationFailureHandlingConcern
11
12
  helper_method :engine_policy
12
13
 
13
14
  after_action :verify_authorized
@@ -6,6 +6,7 @@ module Itsf::Backend
6
6
  if Itsf::Backend.features?(:pundit)
7
7
  include Pundit
8
8
  prepend Controller::PunditNamespacedAuthorizeConcern
9
+ include Controller::PunditAuthorizationFailureHandlingConcern
9
10
  helper_method :engine_policy
10
11
  end
11
12
 
@@ -7,6 +7,7 @@ module Itsf::Backend
7
7
  include Controller::RestActionsConcernWithPundit
8
8
  include Pundit
9
9
  prepend Controller::PunditNamespacedAuthorizeConcern
10
+ include Controller::PunditAuthorizationFailureHandlingConcern
10
11
  helper_method :engine_policy
11
12
  else
12
13
  include Controller::RestActionsConcern
@@ -6,6 +6,7 @@ module Itsf::Backend
6
6
  if Itsf::Backend.features?(:pundit)
7
7
  include Pundit
8
8
  include Controller::PunditNamespacedAuthorizeConcern
9
+ include Controller::PunditAuthorizationFailureHandlingConcern
9
10
  end
10
11
 
11
12
  include Controller::ServiceInflectionsConcern
@@ -0,0 +1,3 @@
1
+ = form.button :submit, class: 'btn btn-success'
2
+ = form.button :submit_and_continue_with_edit, class: 'btn btn-success'
3
+ = form.button :submit_and_continue_with_new, class: 'btn btn-success'
@@ -2,14 +2,20 @@
2
2
  - id_base = "link-to-#{controller.class.name.underscore.gsub('_controller', '').gsub(/[\/_]/, '-')}-#{resource.to_param}"
3
3
  .btn-group
4
4
  - if !Itsf::Backend.features?(:pundit) || policy(resource).show?
5
- = link_to(resource_path(resource), id: "#{id_base}-show", class: 'btn btn-xs btn-responsive btn-default') do
6
- %span.glyphicon.glyphicon-eye-open
7
- %span.btn-text= t('.show')
5
+ - begin
6
+ = link_to(resource_path(resource), id: "#{id_base}-show", class: 'btn btn-xs btn-responsive btn-default') do
7
+ %span.glyphicon.glyphicon-eye-open
8
+ %span.btn-text= t('.show')
9
+ - rescue ActionController::UrlGenerationError
8
10
  - if !Itsf::Backend.features?(:pundit) || policy(resource).edit?
9
- = link_to(edit_resource_path(resource), id: "#{id_base}-edit", class: 'btn btn-xs btn-responsive btn-default') do
10
- %span.glyphicon.glyphicon-pencil
11
- %span.btn-text= t('.edit')
11
+ - begin
12
+ = link_to(edit_resource_path(resource), id: "#{id_base}-edit", class: 'btn btn-xs btn-responsive btn-default') do
13
+ %span.glyphicon.glyphicon-pencil
14
+ %span.btn-text= t('.edit')
15
+ - rescue ActionController::UrlGenerationError
12
16
  - if !Itsf::Backend.features?(:pundit) || policy(resource).destroy?
13
- = link_to(resource_path(resource), id: "#{id_base}-destroy", class: 'btn btn-xs btn-responsive btn-danger', method: :delete, data: { confirm: I18n.t('.confirmations.delete') }) do
14
- %span.glyphicon.glyphicon-fire
15
- %span.btn-text= t('.destroy')
17
+ - begin
18
+ = link_to(resource_path(resource), id: "#{id_base}-destroy", class: 'btn btn-xs btn-responsive btn-danger', method: :delete, data: { confirm: I18n.t('.confirmations.delete') }) do
19
+ %span.glyphicon.glyphicon-fire
20
+ %span.btn-text= t('.destroy')
21
+ - rescue ActionController::UrlGenerationError
@@ -5,9 +5,7 @@
5
5
  = simple_form_for(@resource, url: resource_path(@resource)) do |f|
6
6
  = render partial: 'form_errors', locals: { resource: f.object }
7
7
  = render 'form', form: f
8
- = f.button :submit, class: 'btn btn-success'
9
- = f.button :submit_and_continue_with_edit, class: 'btn btn-success'
10
- = f.button :submit_and_continue_with_new, class: 'btn btn-success'
8
+ = render 'form_buttons', form: f
11
9
 
12
10
  .well.well-sm
13
11
  = link_to resource_path(@resource), class: 'btn btn-primary btn-responsive' do
@@ -5,9 +5,7 @@
5
5
  = simple_form_for(@resource, url: collection_path) do |f|
6
6
  = render partial: 'form_errors', locals: { resource: f.object }
7
7
  = render 'form', form: f
8
- = f.button :submit, class: 'btn btn-success'
9
- = f.button :submit_and_continue_with_edit, class: 'btn btn-success'
10
- = f.button :submit_and_continue_with_new, class: 'btn btn-success'
8
+ = render 'form_buttons', form: f
11
9
  %div.panel-footer
12
10
 
13
11
  .well.well-sm
@@ -17,12 +17,18 @@ Itsf::Backend.configure do |config|
17
17
  #
18
18
  config.home_base_controller = 'BackendController'
19
19
 
20
- # Set the base controller for resouce controllers
20
+ # Set the base controller for resource controllers
21
21
  #
22
22
  # Default: config.resource_base_controller = 'BackendController'
23
23
  #
24
24
  config.resource_base_controller = 'BackendController'
25
25
 
26
+ # Set the base controller for service controllers
27
+ #
28
+ # Default: config.service_base_controller = 'BackendController'
29
+ #
30
+ config.service_base_controller = 'BackendController'
31
+
26
32
  # Register backend engines here. They will be added to the backend menu
27
33
  #
28
34
  # Example: config.backend_engines = %w( MyEngine::Engine ).map(&:constantize)
@@ -1,5 +1,5 @@
1
1
  module Itsf
2
2
  module Backend
3
- VERSION = '1.1.7'
3
+ VERSION = '1.1.8'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itsf_backend
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roberto Vasquez Angel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-17 00:00:00.000000000 Z
11
+ date: 2016-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -498,6 +498,7 @@ files:
498
498
  - app/controllers/concerns/controller/acts_as_list_concern.rb
499
499
  - app/controllers/concerns/controller/acts_as_published_concern.rb
500
500
  - app/controllers/concerns/controller/pagination_concern.rb
501
+ - app/controllers/concerns/controller/pundit_authorization_failure_handling_concern.rb
501
502
  - app/controllers/concerns/controller/pundit_namespaced_authorize_concern.rb
502
503
  - app/controllers/concerns/controller/ransack_concern.rb
503
504
  - app/controllers/concerns/controller/rest_actions_concern_with_pundit.rb
@@ -539,6 +540,7 @@ files:
539
540
  - app/views/itsf/backend/home/index.html.haml
540
541
  - app/views/itsf/backend/i18n/_navigation.html.haml
541
542
  - app/views/itsf/backend/resource/base/_form.html.haml
543
+ - app/views/itsf/backend/resource/base/_form_buttons.haml
542
544
  - app/views/itsf/backend/resource/base/_form_errors.html.haml
543
545
  - app/views/itsf/backend/resource/base/_head_extras.html.haml
544
546
  - app/views/itsf/backend/resource/base/_index_extras.html.haml