diff options
25 files changed, 60 insertions, 147 deletions
| diff --git a/app/assets/stylesheets/components/_panels.sass b/app/assets/stylesheets/components/_panels.sass index e9f615081..ab25d8184 100644 --- a/app/assets/stylesheets/components/_panels.sass +++ b/app/assets/stylesheets/components/_panels.sass @@ -34,6 +34,7 @@          a            text-decoration: none            color: $blue +          text-transform: capitalize            &:hover, &:focus              color: $darkblue diff --git a/app/decorators/compliance_check_set_decorator.rb b/app/decorators/compliance_check_set_decorator.rb index 096596b19..c58e14d88 100644 --- a/app/decorators/compliance_check_set_decorator.rb +++ b/app/decorators/compliance_check_set_decorator.rb @@ -3,15 +3,6 @@ class ComplianceCheckSetDecorator < Draper::Decorator    def action_links      links = [] - -    links << Link.new( -      content: h.destroy_link_content, -      href: h.workbench_compliance_check_sets_path(object.id), -      method: :delete, -      data: {confirm: h.t('imports.actions.destroy_confirm')} -    ) - -    links    end    def lines_status diff --git a/app/decorators/referential_line_decorator.rb b/app/decorators/referential_line_decorator.rb index 55acf7ed9..654f68bf5 100644 --- a/app/decorators/referential_line_decorator.rb +++ b/app/decorators/referential_line_decorator.rb @@ -24,21 +24,6 @@ class ReferentialLineDecorator < Draper::Decorator        )      ) -    if h.policy(Chouette::Line).create? && -        context[:referential].organisation == context[:current_organisation] -      links << Link.new( -        content: h.t('actions.new'), -        href: h.new_referential_line_path(context[:referential]) -      ) -    end - -    if h.policy(object).update? -      links << Link.new( -        content: h.t('actions.edit'), -        href: h.edit_referential_line_path(context[:referential], object) -      ) -    end -      if h.policy(object).destroy?        links << Link.new(          content: h.destroy_link_content('actions.destroy'), diff --git a/app/decorators/stop_area_decorator.rb b/app/decorators/stop_area_decorator.rb index 4e777292d..8b2ebf490 100644 --- a/app/decorators/stop_area_decorator.rb +++ b/app/decorators/stop_area_decorator.rb @@ -7,15 +7,6 @@ class StopAreaDecorator < Draper::Decorator      links = []      stop_area ||= object -    if h.policy(Chouette::StopArea).new? -      links << Link.new( -        content: h.t('stop_areas.actions.new'), -        href: h.new_stop_area_referential_stop_area_path( -          stop_area.stop_area_referential -        ) -      ) -    end -      if h.policy(stop_area).update?        links << Link.new(          content: h.t('stop_areas.actions.edit'), diff --git a/app/policies/calendar_policy.rb b/app/policies/calendar_policy.rb index 3ba708ec9..c2da8c924 100644 --- a/app/policies/calendar_policy.rb +++ b/app/policies/calendar_policy.rb @@ -6,7 +6,7 @@ class CalendarPolicy < ApplicationPolicy    end    def create? -    !archived? && user.has_permission?('calendars.create') +    user.has_permission?('calendars.create')    end    def destroy?; instance_permission("destroy") end    def update?; instance_permission("update") end @@ -14,6 +14,6 @@ class CalendarPolicy < ApplicationPolicy    private    def instance_permission permission -    !archived? & organisation_match? && user.has_permission?("calendars.#{permission}") +    organisation_match? && user.has_permission?("calendars.#{permission}")    end  end diff --git a/app/views/compliance_check_sets/index.html.slim b/app/views/compliance_check_sets/index.html.slim index f5d1bd777..f109845b4 100644 --- a/app/views/compliance_check_sets/index.html.slim +++ b/app/views/compliance_check_sets/index.html.slim @@ -12,7 +12,7 @@                [ \                  TableBuilderHelper::Column.new( \                    key: :ref, \ -                  attribute: 'compliance_check_set_id' \ +                  attribute: 'id' \                  ), \                  TableBuilderHelper::Column.new( \                    key: :creation_date, \ @@ -41,5 +41,3 @@        .row.mt-xs          .col-lg-12            = replacement_msg t('compliance_check_sets.search_no_results') - - diff --git a/app/views/dashboards/_dashboard.html.slim b/app/views/dashboards/_dashboard.html.slim index e5aa5093a..7d547bf4c 100644 --- a/app/views/dashboards/_dashboard.html.slim +++ b/app/views/dashboards/_dashboard.html.slim @@ -22,7 +22,7 @@      .panel.panel-default        .panel-heading          h3.panel-title.with_actions -          = link_to "Modèles de calendrier", calendars_path +          = link_to I18n.t("activerecord.models.calendar", count: @dashboard.current_organisation.calendars.size), calendars_path            div              = link_to '', calendars_path, class: ' fa fa-chevron-right pull-right'        - if @dashboard.current_organisation.calendars.present? diff --git a/app/views/stop_area_referentials/show.html.slim b/app/views/stop_area_referentials/show.html.slim index f66db89f4..911006c39 100644 --- a/app/views/stop_area_referentials/show.html.slim +++ b/app/views/stop_area_referentials/show.html.slim @@ -8,7 +8,7 @@      .col-lg-12.text-right        = link_to stop_area_referential_stop_areas_path(@stop_area_referential), class: 'btn btn-primary' do          = Referential.human_attribute_name(:stop_areas) -        em.small = " (#{@stop_area_referential.stop_areas.size})" +        em.small = " (#{@stop_area_referential.stop_areas.count})"  - page_header_content_for @stop_area_referential  .page_content diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim index c4d880081..dbf3b848d 100644 --- a/app/views/stop_areas/index.html.slim +++ b/app/views/stop_areas/index.html.slim @@ -24,7 +24,7 @@                  key: :name, \                  attribute: 'name', \                  link_to: lambda do |stop_area| \ -                  referential_stop_area_path( \ +                  stop_area_referential_stop_area_path( \                      @stop_area_referential, \                      stop_area \                    ) \ @@ -51,7 +51,7 @@                  attribute: Proc.new { |s| (s.area_type.nil? ? '-' : t("enumerize.stop_area.area_type.#{s.try(:area_type)}")) } \                ), \              ], -            links: [:show, :edit, :delete], +            links: [:show],              cls: 'table has-filter has-search'            = new_pagination @stop_areas, 'pull-right' diff --git a/config/locales/calendars.en.yml b/config/locales/calendars.en.yml index 0076e5207..d3cc57677 100644 --- a/config/locales/calendars.en.yml +++ b/config/locales/calendars.en.yml @@ -56,8 +56,9 @@ en:            end: End    activerecord:      models: -      one: calendar -      other: calendars +      calendar: +        one: calendar +        other: calendars      attributes:        calendar:          name: Name diff --git a/config/locales/calendars.fr.yml b/config/locales/calendars.fr.yml index fddb47d64..fc895bf89 100644 --- a/config/locales/calendars.fr.yml +++ b/config/locales/calendars.fr.yml @@ -56,8 +56,9 @@ fr:            end: Fin    activerecord:      models: -      one: "calendrier" -      other: "calendriers" +      calendar: +        one: "calendrier" +        other: "calendriers"      attributes:        calendar:          name: Nom diff --git a/config/locales/compliance_check_sets.fr.yml b/config/locales/compliance_check_sets.fr.yml index 8f1c066e7..8c4561ae9 100644 --- a/config/locales/compliance_check_sets.fr.yml +++ b/config/locales/compliance_check_sets.fr.yml @@ -10,7 +10,7 @@ fr:            name_compliance_control_set: Indiquez le nom d'un jeu de contrôle            error_period_filter: La date de fin doit être supérieure ou égale à la date de début0      index: -      title: "Liste des jeux de contrôles"       +      title: "Liste des rapports de contrôles"      search_no_results: Aucun rapport de contrôle ne correspond à votre recherche      executed:        title: Jeu de contrôles exécutés %{name} @@ -24,7 +24,7 @@ fr:    activerecord:      attributes:        compliance_check_set: -        ref: réf +        ref: Ref          creation_date: Date et heure de création          associated_object: Objet associé          assigned_to: Affectation diff --git a/config/locales/stop_areas.en.yml b/config/locales/stop_areas.en.yml index 324294892..54a5ebae5 100644 --- a/config/locales/stop_areas.en.yml +++ b/config/locales/stop_areas.en.yml @@ -15,7 +15,7 @@ en:      actions:        new: "Add a new stop"        edit: "Edit this stop" -      destroy: "Remove this stop" +      destroy: "Remove"        deleted_at: "Activated"        destroy_confirm: "Are you sure you want destroy this stop and all of his children ?"        select_parent: "Create or modify the relation child -> parent" diff --git a/config/locales/stop_areas.fr.yml b/config/locales/stop_areas.fr.yml index bf4dd832f..f96a2e564 100644 --- a/config/locales/stop_areas.fr.yml +++ b/config/locales/stop_areas.fr.yml @@ -15,7 +15,7 @@ fr:      actions:        new: "Ajouter un arrêt"        edit: "Editer cet arrêt" -      destroy: "Supprimer cet arrêt" +      destroy: "Supprimer"        deleted_at: "Activé"        destroy_confirm: "Etes vous sûr de supprimer cet arrêt ainsi que tous ses fils?"        select_parent: "Créer ou éditer la relation enfant -> parent" diff --git a/lib/stif/permission_translator.rb b/lib/stif/permission_translator.rb index 78a4bac18..4acf42884 100644 --- a/lib/stif/permission_translator.rb +++ b/lib/stif/permission_translator.rb @@ -52,7 +52,7 @@ module Stif      def extra_organisation_permissions organisation        if organisation&.name&.downcase == "stif" -        return %w{calendars.share stop_area_referentials.synchronize line_referentials.synchronize}  +        return %w{calendars.share stop_area_referentials.synchronize line_referentials.synchronize}        end        []      end diff --git a/spec/features/compliance_check_sets_spec.rb b/spec/features/compliance_check_sets_spec.rb index 7ba64b6b8..6b7d7a4f8 100644 --- a/spec/features/compliance_check_sets_spec.rb +++ b/spec/features/compliance_check_sets_spec.rb @@ -29,7 +29,7 @@ RSpec.describe "ComplianceCheckSets", type: :feature do      it 'we can see the expected content' do        # Breadcrumbs -      expect_breadcrumb_links "Accueil", "Gestion de l'offre", "Liste des jeux de contrôles" +      expect_breadcrumb_links "Accueil", "Gestion de l'offre", "Liste des rapports de contrôles"        # Headline        expect( page ).to have_content("Jeu de contrôles exécutés #{compliance_check_set.name}") @@ -49,10 +49,10 @@ RSpec.describe "ComplianceCheckSets", type: :feature do        # Direct Children        within(:xpath, xpath_for_div_of_block) do          direct_checks.each do | direct_check | -          expect( page ).to have_content( direct_check.code )  -          expect( page ).to have_content( direct_check.name )  -          expect( page ).to have_content( direct_check.criticity )  -          expect( page ).to have_content( direct_check.comment )  +          expect( page ).to have_content( direct_check.code ) +          expect( page ).to have_content( direct_check.name ) +          expect( page ).to have_content( direct_check.criticity ) +          expect( page ).to have_content( direct_check.comment )          end        end @@ -60,10 +60,10 @@ RSpec.describe "ComplianceCheckSets", type: :feature do        compliance_check_set.compliance_check_blocks.each do | block |          within(:xpath, xpath_for_div_of_block(block)) do            block.compliance_checks.each do | check | -            expect( page ).to have_content( check.code )  -            expect( page ).to have_content( check.name )  -            expect( page ).to have_content( check.criticity )  -            expect( page ).to have_content( check.comment )  +            expect( page ).to have_content( check.code ) +            expect( page ).to have_content( check.name ) +            expect( page ).to have_content( check.criticity ) +            expect( page ).to have_content( check.comment )            end          end        end @@ -86,7 +86,7 @@ RSpec.describe "ComplianceCheckSets", type: :feature do        all_checks.each do | check |          expect( page ).to have_content(check.code)        end -       +      end    end diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index 8c77bd465..83b746d4b 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -59,7 +59,7 @@ describe TableBuilderHelper, type: :helper do          </tr>      </thead>      <tbody> -        <tr> +        <tr class="referential-#{referential.id}">              <td>                  <div class="checkbox"><input type="checkbox" name="#{referential.id}" id="#{referential.id}" value="#{referential.id}" /><label for="#{referential.id}"></label></div>              </td> @@ -213,7 +213,7 @@ describe TableBuilderHelper, type: :helper do          </tr>      </thead>      <tbody> -        <tr> +        <tr class="company-#{company.id}">              <td>#{company.get_objectid.local_id}</td>              <td title="Voir"><a href="/referentials/#{referential.id}/companies/#{company.id}">#{company.name}</a></td>              <td></td> @@ -326,7 +326,7 @@ describe TableBuilderHelper, type: :helper do          </tr>      </thead>      <tbody> -        <tr> +        <tr class="company-#{company.id}">              <td>#{company.get_objectid.local_id}</td>              <td title="Voir"><a href="/referentials/#{referential.id}/companies/#{company.id}">#{company.name}</a></td>              <td></td> diff --git a/spec/lib/stif/permission_translator_spec.rb b/spec/lib/stif/permission_translator_spec.rb index 04fc1c6f3..9771af187 100644 --- a/spec/lib/stif/permission_translator_spec.rb +++ b/spec/lib/stif/permission_translator_spec.rb @@ -1,3 +1,4 @@ +# coding: utf-8  RSpec.describe Stif::PermissionTranslator do    context "No SSO Permissions" do @@ -46,13 +47,13 @@ RSpec.describe Stif::PermissionTranslator do    context "For the STIF organisation" do      let(:organisation){ build_stubbed :organisation, name: "STIF" }      let(:permissions){ %w{calendars.share stop_area_referentials.synchronize line_referentials.synchronize}.sort } -    it "adds the calendars.share permission" do +    it "adds the STIF permission" do        expect(described_class.translate([], organisation).sort).to eq permissions      end      context "with the case changed" do        let(:organisation){ build_stubbed :organisation, name: "StiF" } -      it "adds the calendars.share permission" do +      it "adds the STIF permission" do          expect(described_class.translate([], organisation).sort).to eq permissions        end      end diff --git a/spec/policies/calendar_policy_spec.rb b/spec/policies/calendar_policy_spec.rb index 8b1facc71..a881d0e80 100644 --- a/spec/policies/calendar_policy_spec.rb +++ b/spec/policies/calendar_policy_spec.rb @@ -5,21 +5,24 @@ RSpec.describe CalendarPolicy, type: :policy do    permissions :create? do -    it_behaves_like 'permitted policy', 'calendars.create', archived: true +    it_behaves_like 'permitted policy', 'calendars.create' +  end +  permissions :share? do +    it_behaves_like 'permitted policy and same organisation', 'calendars.share'    end    permissions :share? do      it_behaves_like 'permitted policy and same organisation', 'calendars.share', archived: true    end    permissions :destroy? do -    it_behaves_like 'permitted policy and same organisation', 'calendars.destroy', archived: true +    it_behaves_like 'permitted policy and same organisation', 'calendars.destroy'    end    permissions :edit? do -    it_behaves_like 'permitted policy and same organisation', 'calendars.update', archived: true +    it_behaves_like 'permitted policy and same organisation', 'calendars.update'    end    permissions :new? do -    it_behaves_like 'permitted policy', 'calendars.create', archived: true +    it_behaves_like 'permitted policy', 'calendars.create'    end    permissions :update? do -    it_behaves_like 'permitted policy and same organisation', 'calendars.update', archived: true +    it_behaves_like 'permitted policy and same organisation', 'calendars.update'    end  end diff --git a/spec/support/pundit/pundit_view_policy.rb b/spec/support/pundit/pundit_view_policy.rb index b8434cac0..91be0624c 100644 --- a/spec/support/pundit/pundit_view_policy.rb +++ b/spec/support/pundit/pundit_view_policy.rb @@ -1,16 +1,16 @@  module Pundit    module PunditViewPolicy -    extend ActiveSupport::Concern +    def self.included into +      into.let(:permissions){ nil } +      into.let(:organisation){ referential.try(:organisation) } +      into.let(:current_referential){ referential || build_stubbed(:referential) } +      into.let(:current_user){ build_stubbed :user, permissions: permissions, organisation: organisation } +      into.let(:pundit_user){ UserContext.new(current_user, referential: current_referential) } +      into.before do +        allow(view).to receive(:pundit_user) { pundit_user } -    included do -      before do -        controller.singleton_class.class_eval do -          def policy(instance) -            Class.new do -              def method_missing(*args, &block); true; end -            end.new -          end -          helper_method :policy +        allow(view).to receive(:policy) do |instance| +          ::Pundit.policy pundit_user, instance          end        end      end diff --git a/spec/views/connection_links/index.html.erb_spec.rb b/spec/views/connection_links/index.html.erb_spec.rb index a01380094..1f133e31e 100644 --- a/spec/views/connection_links/index.html.erb_spec.rb +++ b/spec/views/connection_links/index.html.erb_spec.rb @@ -17,9 +17,11 @@ describe "/connection_links/index", :type => :view do      end    end -  it "should render a link to create a new group" do -    render -    expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_referential_connection_link_path(referential)}']") +  with_permission "connection_links.create" do +    it "should render a link to create a new group" do +      render +      expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_referential_connection_link_path(referential)}']") +    end    end  end diff --git a/spec/views/connection_links/show.html.erb_spec.rb b/spec/views/connection_links/show.html.erb_spec.rb deleted file mode 100644 index c04a4f3f1..000000000 --- a/spec/views/connection_links/show.html.erb_spec.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'spec_helper' - -describe "/connection_links/show", :type => :view do - -  assign_referential -  let!(:connection_link) { assign(:connection_link, create(:connection_link)) } -  let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) } - -  before do -    allow(view).to receive_messages(current_organisation: referential.organisation) -  end - -  it "should render h2 with the connection_link name" do -    render -    expect(rendered).to have_selector("h2", :text => Regexp.new(connection_link.name)) -  end - -#  it "should display a map with class 'connection_link'" do -#    pending ": map not yet implemented" -#     render -#     expect(rendered).to have_selector("#map", :class => 'connection_link') -#  end - -  it "should render a link to edit the connection_link" do -    render -    expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.edit_referential_connection_link_path(referential, connection_link)}']") -  end - -  it "should render a link to remove the connection_link" do -    render -    expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.referential_connection_link_path(referential, connection_link)}'][class='remove']") -  end - -end - diff --git a/spec/views/offer_workbenches/show.html.erb_spec.rb b/spec/views/offer_workbenches/show.html.erb_spec.rb index cc01c9d0e..138a1560d 100644 --- a/spec/views/offer_workbenches/show.html.erb_spec.rb +++ b/spec/views/offer_workbenches/show.html.erb_spec.rb @@ -53,5 +53,4 @@ describe "workbenches/show", :type => :view do        expect(rendered).to have_box_for_item different_organisation_referential, true      end    end -  end diff --git a/spec/views/stop_areas/index.html.erb_spec.rb b/spec/views/stop_areas/index.html.erb_spec.rb deleted file mode 100644 index 2dfae1bfd..000000000 --- a/spec/views/stop_areas/index.html.erb_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -require 'spec_helper' - -describe "/stop_areas/index", :type => :view do - -  let!(:stop_area_referential) { assign :stop_area_referential, create(:stop_area_referential) } -  let!(:stop_areas) { assign :stop_areas, Array.new(2) { create(:stop_area, stop_area_referential: stop_area_referential) }.paginate } -  let!(:q) { assign :q, Ransack::Search.new(Chouette::StopArea) } - -  before :each do -    allow(view).to receive(:link_with_search).and_return("#") -  end - -  # it "should render a show link for each group" do -  #   render -  #   stop_areas.each do |stop_area| -  #     expect(rendered).to have_selector(".stop_area a[href='#{view.stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']", :text => stop_area.name) -  #   end -  # end -  # -  # it "should render a link to create a new group" do -  #   render -  #   expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_stop_area_referential_stop_area_path(stop_area_referential)}']") -  # end - -end diff --git a/spec/views/stop_areas/index.html.slim_spec.rb b/spec/views/stop_areas/index.html.slim_spec.rb index ecd76fb03..8daa5eb4b 100644 --- a/spec/views/stop_areas/index.html.slim_spec.rb +++ b/spec/views/stop_areas/index.html.slim_spec.rb @@ -21,8 +21,8 @@ describe "/stop_areas/index", :type => :view do    with_permission "stop_areas.create" do      it { should have_link_for_each_item(stop_areas, "show", -> (stop_area){ view.stop_area_referential_stop_area_path(stop_area_referential, stop_area) }) } -    it { should have_link_for_each_item(stop_areas, "create", -> (stop_area){ view.new_stop_area_referential_stop_area_path(stop_area_referential) }) } -    it { should have_the_right_number_of_links(stop_areas, 2) } +    it { should_not have_link_for_each_item(stop_areas, "create", -> (stop_area){ view.new_stop_area_referential_stop_area_path(stop_area_referential) }) } +    it { should have_the_right_number_of_links(stop_areas, 1) }    end    with_permission "stop_areas.update" do | 
