[Op#60985] Ensure notifications work in both restricted and unrestricted state independent of permission changes

https://community.openproject.org/work_packages/60985
This commit is contained in:
Kabiru Mwenja
2025-03-26 18:54:26 +03:00
committed by Bruno Pagno
parent ec2c30cb04
commit dbf8decaf5
6 changed files with 16 additions and 12 deletions
@@ -31,18 +31,18 @@
class Notifications::CreateFromModelService
MENTION_USER_TAG_ID_PATTERN =
'<mention[^>]*(?: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 =
'<mention[^>]*(?: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
@@ -31,7 +31,7 @@ module Notifications::CreateFromModelService::CommentStrategy
%i(watched subscribed)
end
def self.permission
def self.permission(*)
:view_news
end
@@ -31,7 +31,7 @@ module Notifications::CreateFromModelService::MessageStrategy
%i(watched subscribed)
end
def self.permission
def self.permission(*)
:view_messages
end
@@ -31,7 +31,7 @@ module Notifications::CreateFromModelService::NewsStrategy
%i(subscribed)
end
def self.permission
def self.permission(*)
:view_news
end
@@ -31,7 +31,7 @@ module Notifications::CreateFromModelService::WikiPageStrategy
%i(watched subscribed)
end
def self.permission
def self.permission(*)
:view_wiki_pages
end
@@ -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)