From 3163c3f8e90f5545c1527bcbf501145ae24b51f6 Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Mon, 20 Apr 2026 14:29:16 +0100 Subject: [PATCH] Create page to list notifications --- app/abilities/ability.rb | 1 + app/controllers/notifications_controller.rb | 12 +++++++++ app/views/layouts/_header.html.erb | 1 + app/views/notifications/index.html.erb | 11 ++++++++ config/locales/en.yml | 7 +++++ config/routes.rb | 2 ++ .../notifications_controller_test.rb | 26 +++++++++++++++++++ test/system/web_notifications_test.rb | 16 ++++++++++++ 8 files changed, 76 insertions(+) create mode 100644 app/controllers/notifications_controller.rb create mode 100644 app/views/notifications/index.html.erb create mode 100644 test/controllers/notifications_controller_test.rb create mode 100644 test/system/web_notifications_test.rb diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index 867c8cbba..1d747110a 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -42,6 +42,7 @@ class Ability can :update, :account_terms can :create, :account_pd_declaration can :read, :dashboard + can :index, :notification can [:read, :update], [:preferences, :profile] can [:create, :subscribe, :unsubscribe], DiaryEntry can [:update, :hide, :unhide], DiaryEntry, :user => user diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb new file mode 100644 index 000000000..a6a6fd4a7 --- /dev/null +++ b/app/controllers/notifications_controller.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class NotificationsController < ApplicationController + layout :site_layout + + before_action :authorize_web + before_action :set_locale + + authorize_resource :class => false + + before_action :check_database_readable +end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 97717b12a..e047cd5a0 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -64,6 +64,7 @@ <%= number_with_delimiter(current_user.new_messages.size) %> <% end %> <%= link_to t("users.show.my profile"), current_user, :class => "dropdown-item" %> + <%= link_to t("users.show.my_notifications"), notifications_path, :class => "dropdown-item" %> <%= link_to t("users.show.my_account"), account_path, :class => "dropdown-item" %> <%= link_to t("users.show.my_preferences"), basic_preferences_path, :class => "dropdown-item" %> diff --git a/app/views/notifications/index.html.erb b/app/views/notifications/index.html.erb new file mode 100644 index 000000000..7de863324 --- /dev/null +++ b/app/views/notifications/index.html.erb @@ -0,0 +1,11 @@ +<% content_for :heading do %> +

<%= t ".title" %>

+

+ <%= t( + ".point_to_preferences_html", + :link => link_to(t(".link_text"), notification_preferences_path) + ) %> +

+<% end %> + +

<%= t(".no_notifications") %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index bc7a85271..eee55bbd8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -605,6 +605,12 @@ en: followed_diaries: "diary entries" nearby_changesets: "nearby user changesets" nearby_diaries: "nearby user diary entries" + notifications: + index: + title: Notifications + no_notifications: You have no notifications at the moment + point_to_preferences_html: "You can adjust how you receive notifications in %{link}." + link_text: the preferences section diary_entries: new: title: New Diary Entry @@ -3226,6 +3232,7 @@ en: my traces: My Traces my notes: My Notes my messages: My Messages + my_notifications: My Notifications my profile: My Profile my_account: My Account my comments: My Comments diff --git a/config/routes.rb b/config/routes.rb index ab6655bfe..57a4cd89f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -356,6 +356,8 @@ OpenStreetMap::Application.routes.draw do get "/preferences", :to => redirect(:path => "/preferences/basic"), :as => nil get "/preferences/edit", :to => redirect(:path => "/preferences/basic"), :as => nil + resources :notifications, :only => [:index] + # friendships scope "/user/:display_name" do resource :follow, :only => [:create, :destroy, :show], :path => "follow" diff --git a/test/controllers/notifications_controller_test.rb b/test/controllers/notifications_controller_test.rb new file mode 100644 index 000000000..4de95aefb --- /dev/null +++ b/test/controllers/notifications_controller_test.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require "test_helper" + +class NotificationsControllerTest < ActionDispatch::IntegrationTest + def test_routes + assert_routing( + { :path => "/notifications", :method => :get }, + { :controller => "notifications", :action => "index" } + ) + end + + def test_index + session_for(create(:user)) + get notifications_path + + assert_response :success + assert_template "index" + end + + def test_index_unauthorized + get notifications_path + + assert_redirected_to login_path(:referer => notifications_path) + end +end diff --git a/test/system/web_notifications_test.rb b/test/system/web_notifications_test.rb new file mode 100644 index 000000000..010bc85e9 --- /dev/null +++ b/test/system/web_notifications_test.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +require "application_system_test_case" + +class WebNotificationsTest < ApplicationSystemTestCase + test "no notifications available" do + user = create(:user) + sign_in_as(user) + + click_on user.display_name + click_on "My Notifications" + + assert_text "Notifications" + assert_text "You have no notifications" + end +end -- 2.47.3