Skip to content

Commit

Permalink
Merge pull request #1539 from betagouv/stats_policy_tests
Browse files Browse the repository at this point in the history
Add stats policy and authorize team link
  • Loading branch information
LucienMLD authored Feb 4, 2021
2 parents 1d9a9fa + e6a3e06 commit 6800af3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class PagesController < SharedController
# Abstract Controller for the public pages
# implicitly uses the 'pages' layout
include GeocoderIp
include Pundit

## Configuration for honeypot-captcha
#
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/stats/base_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
module Stats
class BaseController < PagesController
include Pundit

private

def stats_params
Expand Down
2 changes: 1 addition & 1 deletion app/views/pages/_footer.haml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
%li= link_to t('about.mentions_d_information.title'), mentions_d_information_path
%li= link_to t('about.mentions_legales.title'), mentions_legales_path
%li= link_to t('usage_stats'), public_index_path
- if current_user&.is_admin?
- if policy(Stats::All).team?
%li= link_to t('usage_team_stats'), team_index_path
%li= link_to t('.service_presentation'), '/book.pdf', 'aria-label': t('.service_presentation_title'), target: '_blank', rel: 'noopener'
20 changes: 20 additions & 0 deletions spec/policies/stats/all_policy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'rails_helper'

RSpec.describe Stats::AllPolicy, type: :policy do
let(:no_user) { nil }
let(:user) { create :user }
let(:admin) { create :user, is_admin: true }

subject { described_class }

permissions :team? do
context "grants access to admin" do
it { is_expected.to permit(admin, Stats::All) }
end

context "denies access to no admin user" do
it { is_expected.not_to permit(user, Stats::All) }
it { is_expected.not_to permit(no_user, Stats::All) }
end
end
end

0 comments on commit 6800af3

Please sign in to comment.