diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index d48d57b41..517199e93 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -1,13 +1,15 @@ class NotificationsController < ApplicationController - def dismiss - current_user.oldest_active_unread_notification.mark_as_read! for: current_user - - redirect_back(fallback_location: root_path) + if current_user.blank? + redirect_to root_path + else + current_user.newest_active_unread_notification.mark_as_read! for: current_user + redirect_back(fallback_location: root_path) + end end def show - @notification = current_user.oldest_active_unread_notification + @notification = current_user&.newest_active_unread_notification || Notification.newest_active_unauthenticated_notification if @notification&.page_content render "show" else diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e91261466..0ec004c5c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -10,9 +10,9 @@ module ApplicationHelper end def govuk_header_classes(current_user) - if current_user && current_user.support? + if current_user&.support? "app-header app-header--orange" - elsif current_user && Notification.unread_by(current_user).present? && !current_page?(notifications_path) + elsif (current_user.blank? || current_user.active_unread_notifications.present?) && !current_page?(notifications_path) "app-header app-header__no-border-bottom" else "app-header" @@ -20,7 +20,7 @@ module ApplicationHelper end def govuk_phase_banner_tag(current_user) - if current_user && current_user.support? + if current_user&.support? { colour: "orange", text: "Support beta" } else { text: "Beta" } diff --git a/app/models/notification.rb b/app/models/notification.rb index f136948f6..0b8bb77d1 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -2,4 +2,9 @@ class Notification < ApplicationRecord acts_as_readable scope :active, -> { where("start_date <= ?", Time.zone.now).where("end_date >= ?", Time.zone.now) } + scope :unauthenticated, -> { where(show_on_unauthenticated_pages: true) } + + def self.newest_active_unauthenticated_notification + active.unauthenticated.last + end end diff --git a/app/models/user.rb b/app/models/user.rb index 1f6412b6a..aba948425 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -233,8 +233,8 @@ class User < ApplicationRecord Notification.active.unread_by(self) end - def oldest_active_unread_notification - active_unread_notifications.first + def newest_active_unread_notification + active_unread_notifications.last end protected diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index afe153016..342e47bba 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -101,8 +101,12 @@ end end %> - <% if current_user.present? && Notification.unread_by(current_user).present? && !current_page?(notifications_path)%> - <%= render "notifications/notification_banner" %> + <% unless current_page?(notifications_path) %> + <% if current_user&.active_unread_notifications.present? %> + <%= render "notifications/notification_banner", notification_count: current_user.active_unread_notifications.count, notification: current_user.newest_active_unread_notification %> + <% elsif !current_user.present? && Notification.unauthenticated.present? %> + <%= render "notifications/notification_banner", notification_count: Notification.unauthenticated.count, notification: Notification.newest_active_unauthenticated_notification %> + <% end %> <% end %> diff --git a/app/views/notifications/_notification_banner.html.erb b/app/views/notifications/_notification_banner.html.erb index 18defb23f..c3d44a1c0 100644 --- a/app/views/notifications/_notification_banner.html.erb +++ b/app/views/notifications/_notification_banner.html.erb @@ -3,19 +3,21 @@
- <% if current_user.active_unread_notifications.count > 1 %> -

Notification 1 of <%= current_user.active_unread_notifications.count %>

+ <% if notification_count > 1 && current_user.present?%> +

Notification 1 of <%= notification_count %>

<% end %> -

<%= current_user.oldest_active_unread_notification.title %>

- <% if current_user.oldest_active_unread_notification.page_content.present? %> +

<%= notification.title %>

+ <% if notification.page_content.present? %>
- <%= govuk_link_to current_user.oldest_active_unread_notification.link_text, notifications_path, class: "govuk-link--inverse govuk-!-font-weight-bold"%> + <%= govuk_link_to notification.link_text, notifications_path, class: "govuk-link--inverse govuk-!-font-weight-bold"%>
<% end %>
-

- <%= govuk_link_to "Dismiss", dismiss_notifications_path, class: "govuk-link--inverse"%> -

+ <% if current_user.present? %> +

+ <%= govuk_link_to "Dismiss", dismiss_notifications_path, class: "govuk-link--inverse"%> +

+ <% end %>
diff --git a/app/views/notifications/show.html.erb b/app/views/notifications/show.html.erb index 347020cbe..fa94bc277 100644 --- a/app/views/notifications/show.html.erb +++ b/app/views/notifications/show.html.erb @@ -13,5 +13,5 @@
- <%= govuk_button_link_to "Back to Home", root_path %> + <%= govuk_button_link_to "Back to #{current_user.present? ? "Home": "Start"}", root_path %>
diff --git a/app/views/start/index.html.erb b/app/views/start/index.html.erb index 17e15d34e..a726be277 100644 --- a/app/views/start/index.html.erb +++ b/app/views/start/index.html.erb @@ -23,10 +23,10 @@

If you need to set up a new account, speak to your organisation’s CORE data coordinator. If you don’t know who that is, <%= govuk_link_to("contact the helpdesk", GlobalConstants::HELPDESK_URL) %>.

You can <%= govuk_mail_to("dluhc.digital-services@levellingup.gov.uk", "request an account", subject: "CORE: Request a new account") %> if your organisation doesn’t have one.

<%= govuk_link_to guidance_path do %>Guidance for submitting social housing lettings and sales data (CORE)<% end %>

+


-
<%= render partial: "layouts/collection_resources" %>