Skip to content

Commit

Permalink
Allow announcements API to support staff targeting
Browse files Browse the repository at this point in the history
  • Loading branch information
kueda committed Jun 26, 2023
1 parent f2d02ac commit 97651e6
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/controllers/v1/announcements_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,19 @@ const AnnouncementsController = class AnnouncementsController {
// when request is unauthenticated, or authenticated user has confirmed their email,
// exclude announcements that are targeting users with unconfirmed emails
if ( !req.userSession || ( req.userSession && req.userSession.emailConfirmed ) ) {
query = query.left_join( "preferences", null, "announcements.id = preferences.owner_id AND"
+ " preferences.owner_type = 'Announcement' AND preferences.name = 'target_unconfirmed_users'"
+ " AND preferences.value='t'" )
.where( "preferences.id IS NULL" );
query = query.left_join( "preferences prefs_unconfirmed", null, "announcements.id = prefs_unconfirmed.owner_id AND"
+ " prefs_unconfirmed.owner_type = 'Announcement' AND prefs_unconfirmed.name = 'target_unconfirmed_users'"
+ " AND prefs_unconfirmed.value='t'" )
.where( "prefs_unconfirmed.id IS NULL" );
}

// when request is unauthenticated, or authenticated is not staff,
// exclude announcements that are targeting staff
if ( !req.userSession || ( req.userSession && !req.userSession.isAdmin ) ) {
query = query.left_join( "preferences prefs_staff", null, "announcements.id = prefs_staff.owner_id AND"
+ " prefs_staff.owner_type = 'Announcement' AND prefs_staff.name = 'target_staff'"
+ " AND prefs_staff.value='t'" )
.where( "prefs_staff.id IS NULL" );
}

let announcementRows;
Expand Down

0 comments on commit 97651e6

Please sign in to comment.