diff options
| author | Xinhui | 2016-11-22 17:21:38 +0100 |
|---|---|---|
| committer | Xinhui | 2016-11-22 17:21:56 +0100 |
| commit | f12aad6a79ba71d59f30c1ae977babfa8d0d248f (patch) | |
| tree | 0d4df3a507f5feb87cf6bda090e87af4c6db0a94 | |
| parent | 1a081d15a16f3bae8b2be35adf69ff4773265765 (diff) | |
| download | chouette-core-f12aad6a79ba71d59f30c1ae977babfa8d0d248f.tar.bz2 | |
ReferentialPolicy
Refs #1998
| -rw-r--r-- | app/controllers/referentials_controller.rb | 6 | ||||
| -rw-r--r-- | app/policies/referential_policy.rb | 13 | ||||
| -rw-r--r-- | app/views/referentials/show.html.slim | 5 | ||||
| -rw-r--r-- | app/views/workbenches/show.html.slim | 2 | ||||
| -rw-r--r-- | spec/policies/referential_policy_spec.rb | 4 |
5 files changed, 25 insertions, 5 deletions
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index b7e6d8031..e0d107b30 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -1,6 +1,6 @@ class ReferentialsController < BreadcrumbController - defaults :resource_class => Referential + before_action :check_policy, :only => [:edit, :update] respond_to :html respond_to :json, :only => :show @@ -87,6 +87,10 @@ class ReferentialsController < BreadcrumbController end private + def check_policy + authorize resource + end + def referential_params params.require(:referential).permit( :id, diff --git a/app/policies/referential_policy.rb b/app/policies/referential_policy.rb new file mode 100644 index 000000000..ddf5188a0 --- /dev/null +++ b/app/policies/referential_policy.rb @@ -0,0 +1,13 @@ +class ReferentialPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end + + def update? + !record.archived? + end + + def edit? ; update? end +end diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim index 94c463d74..2e19c2fc7 100644 --- a/app/views/referentials/show.html.slim +++ b/app/views/referentials/show.html.slim @@ -43,7 +43,7 @@ h2 - content_for :sidebar do ul.actions - - unless @referential.archived? # FIXME + - if policy(@referential).update? li = link_to t('referentials.actions.edit'), edit_referential_path(@referential), class: 'edit' li = link_to t('referentials.actions.destroy'), referential_path(@referential), method: :delete, data: {:confirm => t('referentials.actions.destroy_confirm')}, class: "remove" @@ -51,7 +51,6 @@ h2 li = link_to t('referentials.actions.clone'), new_referential_path(from: @referential.id), class: 'add' br - - unless @referential.archived? # FIXME + - if policy(@referential).update? h4 = t('.clean_up') - == render 'clean' diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim index a979d85f8..a6cef4904 100644 --- a/app/views/workbenches/show.html.slim +++ b/app/views/workbenches/show.html.slim @@ -50,7 +50,7 @@ ul.dropdown-menu li = link_to "Voir", referential_path(referential) - - unless referential.archived? # FIXME + - if policy(referential).update? li = link_to "Editer", edit_referential_path(referential) li = link_to "Cloner", new_referential_path(from: referential) diff --git a/spec/policies/referential_policy_spec.rb b/spec/policies/referential_policy_spec.rb new file mode 100644 index 000000000..084ecc9f0 --- /dev/null +++ b/spec/policies/referential_policy_spec.rb @@ -0,0 +1,4 @@ +require 'rails_helper' + +RSpec.describe ReferentialPolicy do +end |
