diff options
22 files changed, 230 insertions, 151 deletions
| diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 853c2f715..6a9f6942f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -48,7 +48,6 @@ class ApplicationController < ActionController::Base      current_organisation    end -    # Overwriting the sign_out redirect path method    def after_sign_out_path_for(resource_or_scope)      new_user_session_path diff --git a/app/helpers/custom_view_helper.rb b/app/helpers/custom_view_helper.rb new file mode 100644 index 000000000..7e7291c81 --- /dev/null +++ b/app/helpers/custom_view_helper.rb @@ -0,0 +1,9 @@ +module CustomViewHelper + +  def render_custom_view(view) +    view_name = [view, current_organisation.try(:custom_view)].compact.join('_') +    Rails.logger.debug "Render custom view #{view_name}" +    render partial: view_name +  end + +end diff --git a/app/views/dashboards/_dashboard.html.slim b/app/views/dashboards/_dashboard.html.slim new file mode 100644 index 000000000..0b5deffc6 --- /dev/null +++ b/app/views/dashboards/_dashboard.html.slim @@ -0,0 +1,37 @@ +.row +  .col-lg-6.col-md-6.col-sm-6.col-xs-12 +    - @dashboard.current_organisation.workbenches.each do |workbench| +      .panel.panel-default +        .panel-heading +          h3.panel-title.with_actions +            div +              = workbench.name +              span.badge.ml-xs = workbench.referentials.count if workbench.referentials.present? + +            div +              = link_to '', workbench_path(workbench), class: ' fa fa-chevron-right pull-right', title: t('.offers.see') + +        - if workbench.referentials.present? +          .list-group +            - workbench.referentials.limit(5).each do |referential| +              = link_to referential.name, referential_path(referential, workbench_id: referential.workbench_id, current_workbench_id: workbench.id), class: 'list-group-item' +        - else +          .panel-body +            em.small.text-muted = t('.offers.no_content') + +  .col-lg-6.col-md-6.col-sm-6.col-xs-12 +    .panel.panel-default +      .panel-heading +        h3.panel-title +          = "Référentiels d'arrêts" +      .list-group +        - @dashboard.current_organisation.stop_area_referentials.each do |referential| +          = link_to referential.name, stop_area_referential_stop_areas_path(referential), class: 'list-group-item' + +    .panel.panel-default +      .panel-heading +        h3.panel-title +          = "Référentiels de lignes" +      .list-group +        - @dashboard.current_organisation.line_referentials.all.each do |referential| +          = link_to referential.name, line_referential_lines_path(referential), class: 'list-group-item' diff --git a/app/views/layouts/navigation/_main_nav_left.html.slim b/app/views/layouts/navigation/_main_nav_left.html.slim index 837b9cb73..b63c2dd1c 100644 --- a/app/views/layouts/navigation/_main_nav_left.html.slim +++ b/app/views/layouts/navigation/_main_nav_left.html.slim @@ -1,5 +1,3 @@ -- @localizationUrl = "#{params[:controller]}##{params[:action]}" -  .nav-menu#menu_left    .openMenu title='Ouvrir le menu' @@ -7,108 +5,4 @@      .closeMenu title='Fermer le menu'      .brandname = t('brandname') -    #menu-items.panel-group -      .menu-item.panel -        .panel-heading -          h4.panel-title -            = link_to '#miOne', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do -              |Offres courantes - -        #miOne.panel-collapse.collapse -          .list-group -            = link_to root_path, class: "list-group-item #{(@localizationUrl == 'workbenches#index') ? 'active' : ''}" do -              span Tableau de bord -            = link_to '#', class: 'list-group-item' do -              span Offre de mon organisation -            = link_to '#', class: 'list-group-item' do -              span Offre IDF - -      .menu-item.panel -        .panel-heading -          h4.panel-title -            = link_to '#miTwo', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do -              |Espace de travail - -        #miTwo.panel-collapse.collapse -          .list-group -            - if current_user -              = link_to workbench_path(current_offer_workbench), class: "list-group-item #{params[:controller] == 'workbenches' ? 'active' : ''}" do -                span Jeux de données -              = link_to workbench_imports_path(current_offer_workbench), class: "list-group-item #{(params[:controller] == 'imports') ? 'active' : ''}" do -                span Import -              = link_to calendars_path, class: 'list-group-item' do -                span Modèles de calendrier -              = link_to workbench_compliance_check_sets_path(current_offer_workbench), class: 'list-group-item' do -                span Rapport de contrôle -              = link_to compliance_control_sets_path, class: 'list-group-item' do -                span Jeux de contrôle - -      .menu-item.panel -        .panel-heading -          h4.panel-title -            = link_to '#miThree', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do -              |Données - -        #miThree.panel-collapse.collapse -          - if @referential.try(:id) && respond_to?(:current_referential) -            .list-group -              .list-group-item -                = (current_referential.name).upcase -                .list-group -                  = link_to referential_networks_path(current_referential), class: 'list-group-item' do -                    span = t('networks.index.title') - -                  = link_to referential_companies_path(current_referential), class: 'list-group-item' do -                    span = t('companies.index.title') - -                  = link_to '#', class: 'list-group-item disabled' do -                    span Tracés - -                  = link_to referential_time_tables_path(current_referential), class: 'list-group-item' do -                    span = t('time_tables.index.title') - -          - else -            .panel-body -              em.text-muted -                = "Sélectionnez un jeu de données pour accéder à plus de fonctionnalités" - -      .menu-item.panel -        .panel-heading -          h4.panel-title -            = link_to '#miFour', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do -              |Synchronisation - -        #miFour.panel-collapse.collapse -          .list-group -            = link_to line_referential_path(1), class: "list-group-item #{(@localizationUrl == 'line_referentials#show') ? 'active' : ''}" do -              span Synchronisation iLICO -            = link_to stop_area_referential_path(1), class: "list-group-item #{(@localizationUrl == 'stop_area_referentials#show') ? 'active' : ''}" do -              span Synchronisation iCAR - -      .menu-item.panel -        .panel-heading -          h4.panel-title -            = link_to '#miFive', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do -              |Outils - -        #miFive.panel-collapse.collapse -          .list-group -            = link_to Rails.application.config.try(:portal_url), target: '_blank', class: 'list-group-item' do -              span -                span.fa.fa-2x.fa-circle -                |Portail (POSTIF) - -            = link_to Rails.application.config.try(:codifligne_url), target: '_blank', class: 'list-group-item' do -              span -                span.fa.fa-2x.fa-circle -                |iLICO - -            = link_to Rails.application.config.try(:reflex_url), target: '_blank', class: 'list-group-item' do -              span -                span.fa.fa-2x.fa-circle -                |iCAR - -            = link_to '#', target: '_blank', class: 'list-group-item' do -              span -                span.fa.fa-2x.fa-circle -                |Support +    = render_custom_view 'layouts/navigation/main_nav_left_content' diff --git a/app/views/layouts/navigation/_main_nav_left_content.html.slim b/app/views/layouts/navigation/_main_nav_left_content.html.slim new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/app/views/layouts/navigation/_main_nav_left_content.html.slim diff --git a/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim b/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim new file mode 100644 index 000000000..3963d4cd4 --- /dev/null +++ b/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim @@ -0,0 +1,107 @@ +- @localizationUrl = "#{params[:controller]}##{params[:action]}" + +#menu-items.panel-group +  .menu-item.panel +    .panel-heading +      h4.panel-title +        = link_to '#miOne', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do +          |Offres courantes + +    #miOne.panel-collapse.collapse +      .list-group +        = link_to root_path, class: "list-group-item #{(@localizationUrl == 'workbenches#index') ? 'active' : ''}" do +          span Tableau de bord +        = link_to '#', class: 'list-group-item' do +          span Offre de mon organisation +        = link_to '#', class: 'list-group-item' do +          span Offre IDF + +  .menu-item.panel +    .panel-heading +      h4.panel-title +        = link_to '#miTwo', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do +          |Espace de travail + +    #miTwo.panel-collapse.collapse +      .list-group +        - if current_user +          = link_to workbench_path(current_offer_workbench), class: "list-group-item #{params[:controller] == 'workbenches' ? 'active' : ''}" do +            span Jeux de données +          = link_to workbench_imports_path(current_offer_workbench), class: "list-group-item #{(params[:controller] == 'imports') ? 'active' : ''}" do +            span Import +          = link_to calendars_path, class: 'list-group-item' do +            span Modèles de calendrier +          = link_to workbench_compliance_check_sets_path(current_offer_workbench), class: 'list-group-item' do +            span Rapport de contrôle +          = link_to compliance_control_sets_path, class: 'list-group-item' do +            span Jeux de contrôle + +  .menu-item.panel +    .panel-heading +      h4.panel-title +        = link_to '#miThree', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do +          |Données + +    #miThree.panel-collapse.collapse +      - if @referential.try(:id) && respond_to?(:current_referential) +        .list-group +          .list-group-item +            = (current_referential.name).upcase +            .list-group +              = link_to referential_networks_path(current_referential), class: 'list-group-item' do +                span = t('networks.index.title') + +              = link_to referential_companies_path(current_referential), class: 'list-group-item' do +                span = t('companies.index.title') + +              = link_to '#', class: 'list-group-item disabled' do +                span Tracés + +              = link_to referential_time_tables_path(current_referential), class: 'list-group-item' do +                span = t('time_tables.index.title') + +      - else +        .panel-body +          em.text-muted +            = "Sélectionnez un jeu de données pour accéder à plus de fonctionnalités" + +  .menu-item.panel +    .panel-heading +      h4.panel-title +        = link_to '#miFour', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do +          |Synchronisation + +    #miFour.panel-collapse.collapse +      .list-group +        = link_to line_referential_path(1), class: "list-group-item #{(@localizationUrl == 'line_referentials#show') ? 'active' : ''}" do +          span Synchronisation iLICO +        = link_to stop_area_referential_path(1), class: "list-group-item #{(@localizationUrl == 'stop_area_referentials#show') ? 'active' : ''}" do +          span Synchronisation iCAR + +  .menu-item.panel +    .panel-heading +      h4.panel-title +        = link_to '#miFive', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do +          |Outils + +    #miFive.panel-collapse.collapse +      .list-group +        = link_to Rails.application.config.try(:portal_url), target: '_blank', class: 'list-group-item' do +          span +            span.fa.fa-2x.fa-circle +            |Portail (POSTIF) + +        = link_to Rails.application.config.try(:codifligne_url), target: '_blank', class: 'list-group-item' do +          span +            span.fa.fa-2x.fa-circle +            |iLICO + +        = link_to Rails.application.config.try(:reflex_url), target: '_blank', class: 'list-group-item' do +          span +            span.fa.fa-2x.fa-circle +            |iCAR + +        = link_to '#', target: '_blank', class: 'list-group-item' do +          span +            span.fa.fa-2x.fa-circle +            |Support diff --git a/app/views/lines/index.html.slim b/app/views/lines/index.html.slim index c5b2d0f40..911c95e0c 100644 --- a/app/views/lines/index.html.slim +++ b/app/views/lines/index.html.slim @@ -20,7 +20,7 @@            = table_builder_2 @lines,              [ \                TableBuilderHelper::Column.new( \ -                name: 'ID Codifligne', \ +                name: t('id_codif'), \                  attribute: Proc.new { |n| n.get_objectid.short_id }, \                  sortable: false \                ), \ diff --git a/app/views/referential_companies/index.html.slim b/app/views/referential_companies/index.html.slim index 9f5cd5d62..3348dc722 100644 --- a/app/views/referential_companies/index.html.slim +++ b/app/views/referential_companies/index.html.slim @@ -26,7 +26,7 @@            = table_builder_2 @companies,              [ \                TableBuilderHelper::Column.new( \ -                  name: 'ID Codifligne', \ +                  name: t('id_codif'), \                    attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, \                    sortable: false \                ), \ diff --git a/app/views/referential_networks/index.html.slim b/app/views/referential_networks/index.html.slim index e29658f2b..6a2df6d16 100644 --- a/app/views/referential_networks/index.html.slim +++ b/app/views/referential_networks/index.html.slim @@ -26,7 +26,7 @@            = table_builder_2 @networks,              [ \                TableBuilderHelper::Column.new( \ -                name: 'ID Codifligne', \ +                name: t('id_codif'), \                  attribute: Proc.new { |n| n.get_objectid.try(:short_id) }, \                  sortable: false \                ), diff --git a/app/views/referential_stop_areas/show.html.slim b/app/views/referential_stop_areas/show.html.slim index b9a1c9899..7cc078ee0 100644 --- a/app/views/referential_stop_areas/show.html.slim +++ b/app/views/referential_stop_areas/show.html.slim @@ -19,7 +19,7 @@      .row        .col-lg-6.col-md-6.col-sm-12.col-xs-12          = definition_list t('metadatas'), -          { 'ID Reflex' => @stop_area.try(:user_objectid), +          { t('id_reflex') => @stop_area.try(:user_objectid),              'Activé' => (@stop_area.deleted_at ? t('false') : t('true')),              @stop_area.human_attribute_name(:comment) => @stop_area.try(:comment),              @stop_area.human_attribute_name(:stop_area_type) => t("area_types.label.#{@stop_area.stop_area_type}"), diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim index 329be4b5f..734d6ebf3 100644 --- a/app/views/routes/show.html.slim +++ b/app/views/routes/show.html.slim @@ -38,7 +38,7 @@            = table_builder_2 @route_sp,              [ \                TableBuilderHelper::Column.new( \ -                name: 'ID Reflex', \ +                name: t('id_reflex'), \                  attribute: Proc.new { |s| s.try(:stop_area).try(:user_objectid) } \                ), \                TableBuilderHelper::Column.new( \ diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim index b838859bf..1b28f411e 100644 --- a/app/views/stop_areas/index.html.slim +++ b/app/views/stop_areas/index.html.slim @@ -20,7 +20,7 @@            = table_builder_2 @stop_areas,              [ \                TableBuilderHelper::Column.new( \ -                name: 'ID Reflex', \ +                name: t('id_reflex'), \                  attribute: Proc.new { |n| n.get_objectid.try(:short_id) }, \                  sortable: false \                ), \ diff --git a/config/deploy.rb b/config/deploy.rb index 5fff31a4a..a8d44d3e5 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -55,6 +55,12 @@ namespace :deploy do    end    after "bundle:install", "deploy:bundle_link" +  desc "Run yarn install" +  task :yarn do +    run "cd #{release_path} && yarn --production --no-progress install" +  end +  after "bundle:install", "deploy:yarn" +    desc "Symlinks shared configs and folders on each release"    task :symlink_shared, :except => { :no_release => true }  do      run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/" diff --git a/config/initializers/stif.rb b/config/initializers/stif.rb index ca08a7756..eb918131b 100644 --- a/config/initializers/stif.rb +++ b/config/initializers/stif.rb @@ -14,5 +14,11 @@ Rails.application.config.to_prepare do  end unless Rails.env.test?  Rails.application.config.to_prepare do +  Organisation.before_validation(on: :create) do |organisation| +    organisation.custom_view = "stif" +  end +end + +Rails.application.config.to_prepare do    Dashboard.default_class = Stif::Dashboard  end diff --git a/db/migrate/20171001100320_add_custom_view_to_organisations.rb b/db/migrate/20171001100320_add_custom_view_to_organisations.rb new file mode 100644 index 000000000..bd8da50fc --- /dev/null +++ b/db/migrate/20171001100320_add_custom_view_to_organisations.rb @@ -0,0 +1,5 @@ +class AddCustomViewToOrganisations < ActiveRecord::Migration +  def change +    add_column :organisations, :custom_view, :string +  end +end diff --git a/db/migrate/20171001100642_stif_define_custom_view_for_organisations.rb b/db/migrate/20171001100642_stif_define_custom_view_for_organisations.rb new file mode 100644 index 000000000..304c90a1a --- /dev/null +++ b/db/migrate/20171001100642_stif_define_custom_view_for_organisations.rb @@ -0,0 +1,5 @@ +class StifDefineCustomViewForOrganisations < ActiveRecord::Migration +  def change +    Organisation.update_all custom_view: "stif" +  end +end diff --git a/db/schema.rb b/db/schema.rb index 58521fc40..349d8e5eb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -559,6 +559,7 @@ ActiveRecord::Schema.define(version: 20171123110204) do      t.string   "code"      t.datetime "synced_at"      t.hstore   "sso_attributes" +    t.string   "custom_view"    end    add_index "organisations", ["code"], name: "index_organisations_on_code", unique: true, using: :btree diff --git a/db/seeds/chouette.seeds.rb b/db/seeds/chouette.seeds.rb index 6adafa3e9..1cbdb584d 100644 --- a/db/seeds/chouette.seeds.rb +++ b/db/seeds/chouette.seeds.rb @@ -1,38 +1,6 @@ -# coding: utf-8 -# This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). +path = File.join(File.expand_path('../seeds', __FILE__), "*.rb") -stop_area_referential = StopAreaReferential.find_or_create_by!(name: "Reflex", objectid_format: "netex") -line_referential = LineReferential.find_or_create_by!(name: "CodifLigne", objectid_format: "netex") - -# Organisations -stif = Organisation.find_or_create_by!(code: "STIF") do |org| -  org.name = 'STIF' -end -operator = Organisation.find_or_create_by!(code: 'transporteur-a') do |organisation| -  organisation.name = "Transporteur A" +Dir.glob(path).sort.each do |file| +  puts "Seed #{file}" +  load file  end - -# Member -line_referential.add_member stif, owner: true -line_referential.add_member operator - -stop_area_referential.add_member stif, owner: true -stop_area_referential.add_member operator - -# Users -stif.users.find_or_create_by!(username: "admin") do |user| -  user.email = 'stif-boiv@af83.com' -  user.password = "secret" -  user.name = "STIF Administrateur" -end - -operator.users.find_or_create_by!(username: "transporteur") do |user| -  user.email = 'stif-boiv+transporteur@af83.com' -  user.password = "secret" -  user.name = "Martin Lejeune" -end - -# Include all Lines in organisation functional_scope -stif.update sso_attributes: { functional_scope: line_referential.lines.pluck(:objectid) } -operator.update sso_attributes: { functional_scope: line_referential.lines.limit(3).pluck(:objectid) } diff --git a/db/seeds/stif.rb b/db/seeds/stif.rb new file mode 100644 index 000000000..d31a35cfc --- /dev/null +++ b/db/seeds/stif.rb @@ -0,0 +1,38 @@ +# coding: utf-8 +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). + +stop_area_referential = StopAreaReferential.find_or_create_by!(name: "Reflex") +line_referential = LineReferential.find_or_create_by!(name: "CodifLigne") + +# Organisations +stif = Organisation.find_or_create_by!(code: "STIF") do |org| +  org.name = 'STIF' +end +operator = Organisation.find_or_create_by!(code: 'transporteur-a') do |organisation| +  organisation.name = "Transporteur A" +end + +# Member +line_referential.add_member stif, owner: true +line_referential.add_member operator + +stop_area_referential.add_member stif, owner: true +stop_area_referential.add_member operator + +# Users +stif.users.find_or_create_by!(username: "admin") do |user| +  user.email = 'stif-boiv@af83.com' +  user.password = "secret" +  user.name = "STIF Administrateur" +end + +operator.users.find_or_create_by!(username: "transporteur") do |user| +  user.email = 'stif-boiv+transporteur@af83.com' +  user.password = "secret" +  user.name = "Martin Lejeune" +end + +# Include all Lines in organisation functional_scope +stif.update sso_attributes: { functional_scope: line_referential.lines.pluck(:objectid) } +operator.update sso_attributes: { functional_scope: line_referential.lines.limit(3).pluck(:objectid) } diff --git a/spec/controllers/devise/cas_sessions_controller_spec.rb b/spec/controllers/devise/cas_sessions_controller_spec.rb index e4436f6c1..934bc1da2 100644 --- a/spec/controllers/devise/cas_sessions_controller_spec.rb +++ b/spec/controllers/devise/cas_sessions_controller_spec.rb @@ -22,7 +22,7 @@ RSpec.describe Devise::CasSessionsController, type: :controller do      it 'cannot login and will be redirected to the login page, with a corresponding message' do        get :service -      expect(controller).to set_flash[:alert].to(%r{IBOO}) +      expect(controller).to set_flash[:alert].to(%r{Vous ne pouvez pas vous connecter car vous n'avez pas les permissions})        expect(response).to redirect_to "http://stif-portail-dev.af83.priv/sessions/logout?service=http%3A%2F%2Ftest.host%2Fusers%2Fservice"      end    end diff --git a/spec/features/api_keys/edit_api_key_feature_spec.rb b/spec/features/api_keys/edit_api_key_feature_spec.rb index 256c4218b..9248e2b17 100644 --- a/spec/features/api_keys/edit_api_key_feature_spec.rb +++ b/spec/features/api_keys/edit_api_key_feature_spec.rb @@ -12,6 +12,8 @@ RSpec.describe 'Edit API Key', type: :feature do      let( :unique_name ){ SecureRandom.uuid }      it 'complete workflow' do +      skip "Specific to STIF Dashboard" if Dashboard.default_class != Stif::Dashboard +        visit dashboard_path        # api_key's new name does not exist yet        expect( page ).not_to have_content(unique_name) diff --git a/spec/features/api_keys/new_api_key_feature_spec.rb b/spec/features/api_keys/new_api_key_feature_spec.rb index 988690f3c..fc5497788 100644 --- a/spec/features/api_keys/new_api_key_feature_spec.rb +++ b/spec/features/api_keys/new_api_key_feature_spec.rb @@ -13,6 +13,8 @@ RSpec.describe 'New API Key', type: :feature do      it 'complete workflow' do +      skip "Specific to STIF Dashboard" if Dashboard.default_class != Stif::Dashboard +        # /workbenches        visit dashboard_path        expect(page).to have_link(create_label, href: new_api_key_path) | 
