From dbf8decaf5e70ecec27dcf5c43b86e15a999c2cb Mon Sep 17 00:00:00 2001 From: Kabiru Mwenja Date: Wed, 26 Mar 2025 18:54:26 +0300 Subject: [PATCH] [Op#60985] Ensure notifications work in both restricted and unrestricted state independent of permission changes https://community.openproject.org/work_packages/60985 --- .../notifications/create_from_model_service.rb | 12 ++++++------ .../create_from_model_service/comment_strategy.rb | 2 +- .../create_from_model_service/message_strategy.rb | 2 +- .../create_from_model_service/news_strategy.rb | 2 +- .../create_from_model_service/wiki_page_strategy.rb | 2 +- .../work_package_strategy.rb | 8 ++++++-- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/services/notifications/create_from_model_service.rb b/app/services/notifications/create_from_model_service.rb index 0613b821920..9bdd65d434e 100644 --- a/app/services/notifications/create_from_model_service.rb +++ b/app/services/notifications/create_from_model_service.rb @@ -31,18 +31,18 @@ class Notifications::CreateFromModelService MENTION_USER_TAG_ID_PATTERN = ']*(?:data-type="user"[^>]*data-id="(\d+)")|(?:data-id="(\d+)"[^>]*data-type="user")[^>]*>' - .freeze + MENTION_USER_HASH_ID_PATTERN = '\buser#(\d+)\b' - .freeze + MENTION_USER_LOGIN_PATTERN = - '\buser:"(.+?)"'.freeze + '\buser:"(.+?)"' MENTION_GROUP_TAG_ID_PATTERN = ']*(?:data-type="group"[^>]*data-id="(\d+)")|(?:data-id="(\d+)"[^>]*data-type="group")[^>]*>' - .freeze + MENTION_GROUP_HASH_ID_PATTERN = '\bgroup#(\d+)\b' - .freeze + COMBINED_MENTION_PATTERN = [MENTION_USER_TAG_ID_PATTERN, MENTION_USER_HASH_ID_PATTERN, @@ -247,7 +247,7 @@ class Notifications::CreateFromModelService def settings_for_allowed_users(user_scope, reason) NotificationSetting .where(reason => true) - .where(user: user_scope.where(id: User.allowed(strategy.permission, project))) + .where(user: user_scope.where(id: User.allowed(strategy.permission(journal, reason), project))) end # Returns the text of the model (currently suited to work package description and subject) eligible diff --git a/app/services/notifications/create_from_model_service/comment_strategy.rb b/app/services/notifications/create_from_model_service/comment_strategy.rb index ff48df4bb26..66cbabf6920 100644 --- a/app/services/notifications/create_from_model_service/comment_strategy.rb +++ b/app/services/notifications/create_from_model_service/comment_strategy.rb @@ -31,7 +31,7 @@ module Notifications::CreateFromModelService::CommentStrategy %i(watched subscribed) end - def self.permission + def self.permission(*) :view_news end diff --git a/app/services/notifications/create_from_model_service/message_strategy.rb b/app/services/notifications/create_from_model_service/message_strategy.rb index 8ca67d94d61..18637d42b32 100644 --- a/app/services/notifications/create_from_model_service/message_strategy.rb +++ b/app/services/notifications/create_from_model_service/message_strategy.rb @@ -31,7 +31,7 @@ module Notifications::CreateFromModelService::MessageStrategy %i(watched subscribed) end - def self.permission + def self.permission(*) :view_messages end diff --git a/app/services/notifications/create_from_model_service/news_strategy.rb b/app/services/notifications/create_from_model_service/news_strategy.rb index b069d337e88..b5181aaf76d 100644 --- a/app/services/notifications/create_from_model_service/news_strategy.rb +++ b/app/services/notifications/create_from_model_service/news_strategy.rb @@ -31,7 +31,7 @@ module Notifications::CreateFromModelService::NewsStrategy %i(subscribed) end - def self.permission + def self.permission(*) :view_news end diff --git a/app/services/notifications/create_from_model_service/wiki_page_strategy.rb b/app/services/notifications/create_from_model_service/wiki_page_strategy.rb index d67ee4b7490..47e32d4b57f 100644 --- a/app/services/notifications/create_from_model_service/wiki_page_strategy.rb +++ b/app/services/notifications/create_from_model_service/wiki_page_strategy.rb @@ -31,7 +31,7 @@ module Notifications::CreateFromModelService::WikiPageStrategy %i(watched subscribed) end - def self.permission + def self.permission(*) :view_wiki_pages end diff --git a/app/services/notifications/create_from_model_service/work_package_strategy.rb b/app/services/notifications/create_from_model_service/work_package_strategy.rb index d8db68c83f4..bc076498758 100644 --- a/app/services/notifications/create_from_model_service/work_package_strategy.rb +++ b/app/services/notifications/create_from_model_service/work_package_strategy.rb @@ -31,8 +31,12 @@ module Notifications::CreateFromModelService::WorkPackageStrategy %i(mentioned assigned responsible watched commented created processed prioritized scheduled shared) end - def self.permission - :view_work_packages + def self.permission(journal, reason) + if journal.restricted? && %i[mentioned commented].include?(reason) + :view_comments_with_restricted_visibility + else + :view_work_packages + end end def self.supports_ian?(_reason)