diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index af00e9060..0180cfcb4 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -3,10 +3,13 @@ class ServicesController < ApplicationController include LinkImporterUtils before_action :set_service, except: :index + before_action :check_permissions, except: :index + + helper_method :org_name_for_current_user def index - @services = Service.enabled.order(broken_link_count: :desc) - raise "Missing Data" if @services.empty? + @services = services_for_user(current_user).enabled.order(broken_link_count: :desc) + # raise "Missing Data" if @services.empty? @breadcrumbs = index_breadcrumbs end @@ -18,6 +21,22 @@ def show @breadcrumbs = service_breadcrumbs(@service) end + def update_owner_form + raise GDS::SSO::PermissionDeniedError, "You do not have permission to view this page" unless gds_editor? + + @breadcrumbs = service_breadcrumbs(@service) + [{ title: "Update Owner", url: update_owner_form_service_path(@service) }] + end + + def update_owner + Rails.logger.info(params) + + raise GDS::SSO::PermissionDeniedError, "You do not have permission to view this page" unless gds_editor? + + @service.update!(organisation_slugs: params["service"]["organisation_slugs"].split(" ")) + + redirect_to service_path(@service, filter: "broken_links") + end + def download_links_form @breadcrumbs = service_breadcrumbs(@service) + [{ title: "Download Links", url: download_links_form_service_path(@service) }] end @@ -40,10 +59,20 @@ def upload_links_csv private + def services_for_user(user) + return Service.all if gds_editor? + + Service.where(":organisation_slugs = ANY(organisation_slugs)", organisation_slugs: user.organisation_slug) + end + def set_service @service = Service.find_by!(slug: params[:service_slug]) end + def check_permissions + raise GDS::SSO::PermissionDeniedError, "You do not have permission to view this page" unless permission_for_service?(@service) + end + def links_for_service @links_for_service ||= filtered_links(@service.links) .includes(%i[interaction local_authority service_interaction]) diff --git a/app/presenters/service_presenter.rb b/app/presenters/service_presenter.rb index 3f5c9860b..c2bf1b1fa 100644 --- a/app/presenters/service_presenter.rb +++ b/app/presenters/service_presenter.rb @@ -6,6 +6,7 @@ def summary_list(view_context) summary_items = [ { field: "Local Government Service List (LGSL) Code", value: lgsl_code }, + { field: "Owning Departments", value: organisation_slugs.join(", ") }, { field: "Page title(s) on GOV.UK", value: govuk_links.compact.any? ? govuk_links.compact.join("
").html_safe : "Not used on GOV.UK" }, ] diff --git a/app/views/services/index.html.erb b/app/views/services/index.html.erb index 5fb4181d6..74aca3c8d 100644 --- a/app/views/services/index.html.erb +++ b/app/views/services/index.html.erb @@ -1,9 +1,10 @@ -<% content_for :page_title, "Services" %> +<% title = gds_editor? ? "Services" : "Services for #{org_name_for_current_user}" %> +<% content_for :page_title, title %> <% breadcrumb :services %> <%= render "govuk_publishing_components/components/heading", { - text: "Services (#{@services.count})", + text: "#{title} (#{@services.count})", heading_level: 1, font_size: "l", margin_bottom: 5, diff --git a/app/views/services/show.html.erb b/app/views/services/show.html.erb index 725c9fd52..fcdfc6aa8 100644 --- a/app/views/services/show.html.erb +++ b/app/views/services/show.html.erb @@ -15,12 +15,15 @@