Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRESIDECMS-2698 add an option to raise a notification to a specific consumer #1546

Open
wants to merge 2 commits into
base: stable
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions system/services/notifications/NotificationService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ component autodoc=true displayName="Notification Service" {
* @data.hint Supporting data for the notification. This is used, in combination with the topic, to render the alert for the end users.
*
*/
public string function createNotification( required string topic, required string type, required struct data ) autodoc=true {
public string function createNotification(
required string topic
, required string type
, required struct data
, string consumer = ""
) autodoc=true {
var topicConfig = getGlobalTopicConfiguration( arguments.topic );
var args = Duplicate( arguments );

Expand All @@ -81,7 +86,7 @@ component autodoc=true displayName="Notification Service" {
} );

if ( existingNotification.recordCount ) {
createNotificationConsumers( existingNotification.id, args.topic, args.data );
createNotificationConsumers( existingNotification.id, args.topic, args.data, args.consumer );
return existingNotification.id;
}

Expand All @@ -91,7 +96,7 @@ component autodoc=true displayName="Notification Service" {

_announceInterception( "postCreateNotification", args );

createNotificationConsumers( args.notificationId, topic, args.data );
createNotificationConsumers( args.notificationId, topic, args.data, args.consumer );

if ( Len( Trim( topicConfig.send_to_email_address ?: "" ) ) ) {
sendGlobalNotificationEmail(
Expand Down Expand Up @@ -467,11 +472,24 @@ component autodoc=true displayName="Notification Service" {
}
}

public void function createNotificationConsumers( required string notificationId, required string topic, required struct data ) {
var subscribedToAll = _getUserDao().selectData( selectFields=[ "id" ], filter={ subscribed_to_all_notifications=true, active=true } );
var subscribedToTopic = _getSubscriptionDao().selectData( selectFields=[ "security_user", "get_email_notifications" ], filter={ topic=arguments.topic , "security_user.active"=true } );
var subscribers = {};
var interceptorArgs = Duplicate( arguments );
public void function createNotificationConsumers(
required string notificationId
, required string topic
, required struct data
, string consumer = ""
) {
var subscribedToAllFilter = { subscribed_to_all_notifications=true, active=true };
var subscribedToTopicFilter = { topic=arguments.topic, "security_user.active"=true };

if ( len( arguments.consumer ) ) {
subscribedToAllFilter.id = arguments.consumer;
subscribedToTopicFilter.security_user = arguments.consumer;
}

var subscribedToAll = _getUserDao().selectData( selectFields=[ "id" ], filter=subscribedToAllFilter );
var subscribedToTopic = _getSubscriptionDao().selectData( selectFields=[ "security_user", "get_email_notifications" ], filter=subscribedToTopicFilter );
var subscribers = {};
var interceptorArgs = Duplicate( arguments );

for( var subscriber in subscribedToAll ){ subscribers[ subscriber.id ] = {}; }
for( var subscriber in subscribedToTopic ){ subscribers[ subscriber.security_user ] = subscriber; }
Expand Down