diff --git a/app/components/sdg/goals/index_component.html.erb b/app/components/sdg/goals/index_component.html.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/components/sdg/goals/index_component.rb b/app/components/sdg/goals/index_component.rb new file mode 100644 index 000000000..3d89921ca --- /dev/null +++ b/app/components/sdg/goals/index_component.rb @@ -0,0 +1,7 @@ +class SDG::Goals::IndexComponent < ApplicationComponent + attr_reader :goals + + def initialize(goals) + @goals = goals + end +end diff --git a/app/controllers/sdg/goals_controller.rb b/app/controllers/sdg/goals_controller.rb new file mode 100644 index 000000000..ea5498c2b --- /dev/null +++ b/app/controllers/sdg/goals_controller.rb @@ -0,0 +1,9 @@ +class SDG::GoalsController < ApplicationController + include FeatureFlags + feature_flag :sdg + load_and_authorize_resource + + def index + @goals = @goals.order(:code) + end +end diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 432099150..5f9dcb3a5 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -27,6 +27,8 @@ module Abilities can [:read], Legislation::Question can [:read, :map, :share], Legislation::Proposal can [:search, :comments, :read, :create, :new_comment], Legislation::Annotation + + can :read, ::SDG::Goal end end end diff --git a/app/models/abilities/sdg/manager.rb b/app/models/abilities/sdg/manager.rb index f3368fa87..5685aab4e 100644 --- a/app/models/abilities/sdg/manager.rb +++ b/app/models/abilities/sdg/manager.rb @@ -4,7 +4,6 @@ class Abilities::SDG::Manager def initialize(user) merge Abilities::Common.new(user) - can :read, ::SDG::Goal can :read, ::SDG::Target end end diff --git a/app/views/sdg/goals/index.html.erb b/app/views/sdg/goals/index.html.erb new file mode 100644 index 000000000..7dfb01513 --- /dev/null +++ b/app/views/sdg/goals/index.html.erb @@ -0,0 +1 @@ +<%= render SDG::Goals::IndexComponent.new(@goals) %> diff --git a/app/views/shared/_subnavigation.html.erb b/app/views/shared/_subnavigation.html.erb index 95553b4a4..4a393e50a 100644 --- a/app/views/shared/_subnavigation.html.erb +++ b/app/views/shared/_subnavigation.html.erb @@ -42,12 +42,20 @@ accesskey: "5" %> <% end %> + <% if feature?(:sdg) %> +
  • + <%= layout_menu_link_to t("layouts.header.sdg"), + sdg_goals_path, + controller_path.split("/").first == "sdg", + accesskey: "6" %> +
  • + <% end %> <% if feature?(:help_page) %>
  • <%= layout_menu_link_to t("layouts.header.help"), help_path, current_page?(help_path), - accesskey: "6" %> + accesskey: "7" %>
  • <% end %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 5a47cdb64..a1c7a886c 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -251,6 +251,7 @@ en: other: You have %{count} new notifications notifications: Notifications no_notifications: "You don't have new notifications" + sdg: "SDG" notifications: index: empty_notifications: You don't have new notifications. diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 7f7b2b713..b9da8ab10 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -251,6 +251,7 @@ es: other: Tienes %{count} notificaciones nuevas notifications: Notificaciones no_notifications: "No tienes notificaciones nuevas" + sdg: "ODS" notifications: index: empty_notifications: No tienes notificaciones nuevas. diff --git a/config/routes.rb b/config/routes.rb index aeb715684..acbdf90d1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,6 +21,7 @@ Rails.application.routes.draw do draw :poll draw :proposal draw :related_content + draw :sdg draw :sdg_management draw :tag draw :user diff --git a/config/routes/sdg.rb b/config/routes/sdg.rb new file mode 100644 index 000000000..9c065b9a6 --- /dev/null +++ b/config/routes/sdg.rb @@ -0,0 +1,3 @@ +namespace :sdg do + resources :goals, only: :index +end diff --git a/spec/controllers/sdg/goals_spec.rb b/spec/controllers/sdg/goals_spec.rb new file mode 100644 index 000000000..f72c283dd --- /dev/null +++ b/spec/controllers/sdg/goals_spec.rb @@ -0,0 +1,13 @@ +require 'rails_helper' + +describe SDG::GoalsController do + context "featured disabled" do + before do + Setting["feature.sdg"] = false + end + + it "raises feature disabled" do + expect { get :index }.to raise_exception(FeatureFlags::FeatureDisabled) + end + end +end diff --git a/spec/models/abilities/administrator_spec.rb b/spec/models/abilities/administrator_spec.rb index f237964dc..873768d87 100644 --- a/spec/models/abilities/administrator_spec.rb +++ b/spec/models/abilities/administrator_spec.rb @@ -107,7 +107,6 @@ describe Abilities::Administrator do it { should be_able_to(:create, LocalCensusRecords::Import) } it { should be_able_to(:show, LocalCensusRecords::Import) } - it { should be_able_to(:read, SDG::Goal) } it { should be_able_to(:read, SDG::Target) } it { should be_able_to(:read, SDG::Manager) } diff --git a/spec/models/abilities/common_spec.rb b/spec/models/abilities/common_spec.rb index 336116012..b060f5944 100644 --- a/spec/models/abilities/common_spec.rb +++ b/spec/models/abilities/common_spec.rb @@ -305,7 +305,6 @@ describe Abilities::Common do it { should be_able_to(:disable_recommendations, Proposal) } end - it { should_not be_able_to(:read, SDG::Goal) } it { should_not be_able_to(:read, SDG::Target) } it { should_not be_able_to(:read, SDG::Manager) } diff --git a/spec/models/abilities/everyone_spec.rb b/spec/models/abilities/everyone_spec.rb index a5399e25b..81b82dcd5 100644 --- a/spec/models/abilities/everyone_spec.rb +++ b/spec/models/abilities/everyone_spec.rb @@ -53,7 +53,7 @@ describe Abilities::Everyone do it { should_not be_able_to(:summary, create(:legislation_process, :open)) } it { should_not be_able_to(:summary, create(:legislation_process, :past, :not_published)) } - it { should_not be_able_to(:read, SDG::Goal) } + it { should be_able_to(:read, SDG::Goal) } it { should_not be_able_to(:read, SDG::Target) } it { should_not be_able_to(:read, SDG::Manager) } diff --git a/spec/models/abilities/moderator_spec.rb b/spec/models/abilities/moderator_spec.rb index 762583534..1b2bd4f48 100644 --- a/spec/models/abilities/moderator_spec.rb +++ b/spec/models/abilities/moderator_spec.rb @@ -109,7 +109,6 @@ describe Abilities::Moderator do it { should_not be_able_to(:comment_as_administrator, legislation_question) } end - it { should_not be_able_to(:read, SDG::Goal) } it { should_not be_able_to(:read, SDG::Target) } it { should_not be_able_to(:read, SDG::Manager) } diff --git a/spec/models/abilities/organization_spec.rb b/spec/models/abilities/organization_spec.rb index 2553b3f18..874a5ce40 100644 --- a/spec/models/abilities/organization_spec.rb +++ b/spec/models/abilities/organization_spec.rb @@ -23,7 +23,6 @@ describe "Abilities::Organization" do it { should be_able_to(:create, Comment) } it { should_not be_able_to(:vote, Comment) } - it { should_not be_able_to(:read, SDG::Goal) } it { should_not be_able_to(:read, SDG::Target) } it { should_not be_able_to(:read, SDG::Manager) } diff --git a/spec/models/abilities/sdg/manager.rb b/spec/models/abilities/sdg/manager.rb index 004ad0ada..43e1e20f4 100644 --- a/spec/models/abilities/sdg/manager.rb +++ b/spec/models/abilities/sdg/manager.rb @@ -7,7 +7,6 @@ describe "Abilities::SDG::Manager" do let(:user) { sdg_manager.user } let(:sdg_manager) { create(:sdg_manager) } - it { should be_able_to(:read, SDG::Goal) } it { should be_able_to(:read, SDG::Target) } it { should_not be_able_to(:read, SDG::Manager) } diff --git a/spec/models/abilities/valuator_spec.rb b/spec/models/abilities/valuator_spec.rb index 634dd7e92..328c1cb48 100644 --- a/spec/models/abilities/valuator_spec.rb +++ b/spec/models/abilities/valuator_spec.rb @@ -40,7 +40,6 @@ describe Abilities::Valuator do it { should_not be_able_to(:comment_valuation, assigned_investment) } end - it { should_not be_able_to(:read, SDG::Goal) } it { should_not be_able_to(:read, SDG::Target) } it { should_not be_able_to(:read, SDG::Manager) } diff --git a/spec/system/sdg/goals_spec.rb b/spec/system/sdg/goals_spec.rb new file mode 100644 index 000000000..313765c5c --- /dev/null +++ b/spec/system/sdg/goals_spec.rb @@ -0,0 +1,24 @@ +require "rails_helper" + +describe "SDG Goals", :js do + before do + Setting["feature.sdg"] = true + end + + describe "SDG navigation link" do + scenario "is not present when the feature is disabled" do + Setting["feature.sdg"] = false + + visit root_path + + within("#navigation_bar") { expect(page).not_to have_link "SDG" } + end + + scenario "routes to the goals index" do + visit root_path + within("#navigation_bar") { click_link "SDG" } + + expect(page).to have_current_path sdg_goals_path + end + end +end