diff options
| author | Xinhui | 2016-10-10 11:25:10 +0200 |
|---|---|---|
| committer | Xinhui | 2016-10-10 11:25:10 +0200 |
| commit | 1cd01cc22e45710adf2efa080662d919daaaeed3 (patch) | |
| tree | dfa168b12c5306141f47bed40ecfc501694a4ecf /app | |
| parent | fc25c675b21524d722f3e0e2ae34db43392f1651 (diff) | |
| download | chouette-core-1cd01cc22e45710adf2efa080662d919daaaeed3.tar.bz2 | |
GroupOfLine policy
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/group_of_lines_controller.rb | 16 | ||||
| -rw-r--r-- | app/controllers/networks_controller.rb | 15 | ||||
| -rw-r--r-- | app/policies/network_policy.rb | 15 | ||||
| -rw-r--r-- | app/views/group_of_lines/show.html.slim | 23 | ||||
| -rw-r--r-- | app/views/lines/show.html.slim | 4 |
5 files changed, 58 insertions, 15 deletions
diff --git a/app/controllers/group_of_lines_controller.rb b/app/controllers/group_of_lines_controller.rb index f8b5301d3..112ff2dd0 100644 --- a/app/controllers/group_of_lines_controller.rb +++ b/app/controllers/group_of_lines_controller.rb @@ -1,6 +1,6 @@ class GroupOfLinesController < BreadcrumbController include ApplicationHelper - + before_action :check_policy, :only => [:edit, :update, :destroy] defaults :resource_class => Chouette::GroupOfLine respond_to :html respond_to :xml @@ -29,6 +29,16 @@ class GroupOfLinesController < BreadcrumbController end end + def new + authorize resource_class + super + end + + def create + authorize resource_class + super + end + def name_filter respond_to do |format| format.json { render :json => filtered_group_of_lines_maps} @@ -65,6 +75,10 @@ class GroupOfLinesController < BreadcrumbController private + def check_policy + authorize resource + end + def group_of_line_params params.require(:group_of_line).permit( :objectid, :object_version, :creation_time, :creator_id, :name, :comment, :lines, :registration_number, :line_tokens) end diff --git a/app/controllers/networks_controller.rb b/app/controllers/networks_controller.rb index beced7e55..85ec36769 100644 --- a/app/controllers/networks_controller.rb +++ b/app/controllers/networks_controller.rb @@ -1,6 +1,6 @@ class NetworksController < BreadcrumbController include ApplicationHelper - + before_action :check_policy, :only => [:edit, :update, :destroy] defaults :resource_class => Chouette::Network respond_to :html respond_to :xml @@ -17,6 +17,14 @@ class NetworksController < BreadcrumbController end end + def new + authorize resource_class + end + + def create + authorize resource_class + end + def index index! do |format| format.html { @@ -45,8 +53,11 @@ class NetworksController < BreadcrumbController alias_method :line_referential, :parent + def check_policy + authorize resource + end + def network_params params.require(:network).permit(:objectid, :object_version, :creation_time, :creator_id, :version_date, :description, :name, :registration_number, :source_name, :source_type_name, :source_identifier, :comment ) end - end diff --git a/app/policies/network_policy.rb b/app/policies/network_policy.rb new file mode 100644 index 000000000..427eace93 --- /dev/null +++ b/app/policies/network_policy.rb @@ -0,0 +1,15 @@ +class NetworkPolicy < ApplicationPolicy + class Scope < Scope + def resolve + scope + end + end + + def create? + false + end + def update? ; create? end + def new? ; create? end + def edit? ; create? end + def destroy? ; create? end +end diff --git a/app/views/group_of_lines/show.html.slim b/app/views/group_of_lines/show.html.slim index c93f5277e..b934cb1ef 100644 --- a/app/views/group_of_lines/show.html.slim +++ b/app/views/group_of_lines/show.html.slim @@ -2,7 +2,7 @@ .group_of_line_show = @map.to_html - + .summary p label = "#{@group_of_line.human_attribute_name('registration_number')} : " @@ -13,19 +13,22 @@ = @group_of_line.comment p.after_map - + h3.group_of_line_lines = t('.lines') .lines_detail - == render partial: "lines_detail" + == render partial: "lines_detail" - content_for :sidebar do ul.actions - li - = link_to t('group_of_lines.actions.new'), new_line_referential_group_of_line_path(@line_referential), class: 'add' - li - = link_to t('group_of_lines.actions.edit'), edit_line_referential_group_of_line_path(@line_referential, @group_of_line), class: 'edit' - li - = link_to t('group_of_lines.actions.destroy'), line_referential_group_of_line_path(@line_referential, @group_of_line), :method => :delete, :data => {:confirm => t('group_of_lines.actions.destroy_confirm')} , class: 'remove' + - if policy(Chouette::GroupOfLine).create? + li + = link_to t('group_of_lines.actions.new'), new_line_referential_group_of_line_path(@line_referential), class: 'add' + - if policy(@group_of_line).edit? + li + = link_to t('group_of_lines.actions.edit'), edit_line_referential_group_of_line_path(@line_referential, @group_of_line), class: 'edit' + - if policy(@group_of_line).destroy? + li + = link_to t('group_of_lines.actions.destroy'), line_referential_group_of_line_path(@line_referential, @group_of_line), :method => :delete, :data => {:confirm => t('group_of_lines.actions.destroy_confirm')} , class: 'remove' br - = creation_tag(@group_of_line)
\ No newline at end of file + = creation_tag(@group_of_line) diff --git a/app/views/lines/show.html.slim b/app/views/lines/show.html.slim index af9a72b15..cca0e395c 100644 --- a/app/views/lines/show.html.slim +++ b/app/views/lines/show.html.slim @@ -134,10 +134,10 @@ h3.routes = t('.itineraries') - if policy(Chouette::Line).create? li = link_to t('lines.actions.new'), new_line_referential_line_path(@line_referential), class: 'add' - - if policy(Chouette::Line).update? + - if policy(@line).update? li = link_to t('lines.actions.edit'), edit_line_referential_line_path(@line_referential, @line), class: 'edit' - - if policy(Chouette::Line).destroy? + - if policy(@line).destroy? li = link_to t('lines.actions.destroy'), line_referential_line_path(@line_referential, @line), method: :delete, :data => {:confirm => t('lines.actions.destroy_confirm')}, class: 'remove' |
