Skip to content

Commit

Permalink
Public-18: Allow Notifications in news list (#749)
Browse files Browse the repository at this point in the history
* Public-18: Allow Notifications in news list

* Update package.json

Sharp 0.32.0 wasn't building
  • Loading branch information
Ckoelewyn authored Sep 17, 2024
1 parent 55c16b7 commit bb68f3b
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 1 deletion.
40 changes: 40 additions & 0 deletions api/controllers/projectNotification.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,53 @@
var _ = require('lodash');
const defaultLog = require('winston').loggers.get('default');
const mongoose = require('mongoose');
const Actions = require('../helpers/actions');
const Utils = require('../helpers/utils');
const constants = require('../helpers/constants');



exports.protectedOptions = function (args, res) {
res.status(200).send();
};

// Gets a list of all Project Notifications
exports.protectedGet = async function (args, res) {
var skip = null, limit = null, sort = null;
var count = false;
var query = {};

// Admin only
if (args.swagger.params.fields.value) {
args.swagger.params.fields.value.push('directoryStructure');
}
var fields = args.swagger.params.fields.value;

// set query to get project notifications
_.assignIn(query, { '_schemaName': 'ProjectNotification'});

try {
var data = await Utils.runDataQuery('ProjectNotification',
args.swagger.params.auth_payload.realm_access.roles,
query,
fields,
null,
sort,
skip,
limit,
count,
null,
true,
);
Utils.recordAction('Get', 'ProjectNotification', args.swagger.params.auth_payload.preferred_username);

return Actions.sendResponse(res, 200, data);
} catch (error) {
defaultLog.info('Error:', error);
return Actions.sendResponse(res, 400, {error: error.message });
}
};

// Create a new Project Notification
exports.protectedPost = async function (args, res) {
const requestData = args.swagger.params.projectNotification.value;
Expand Down
2 changes: 2 additions & 0 deletions api/controllers/recentActivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var getSanitizedFields = function (fields) {
'contentUrl',
'type',
'notificationName',
'projectNotification',
'pcp',
'active',
'project',
Expand All @@ -37,6 +38,7 @@ exports.publicGet = async function (args, res) {
'contentUrl',
'type',
'notificationName',
'projectNotification',
'pcp',
'active',
'project',
Expand Down
1 change: 1 addition & 0 deletions api/helpers/models/recentActivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = require ('../models')('RecentActivity', {
type : { type: String, default: null },
notificationName : { type: String, default: null },
pcp : { type: 'ObjectId', ref: 'CommentPeriod', default: null, index: true },
projectNotification : { type: 'ObjectId', ref: 'projectNotification', default: null, index: true},
active : { type: Boolean, default: false },
project : { type: 'ObjectId', ref: 'Project', default: null, index: true },
content : { type: String, default: null },
Expand Down
14 changes: 14 additions & 0 deletions api/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,20 @@ exports.runDataQuery = async function (modelType, role, query, fields, sortWarmU
'preserveNullAndEmptyArrays': true
}
},
(modelType !== 'Project') && {
'$lookup': {
'from': 'epic',
'localField': 'project._id',
'foreignField': '_id',
'as': 'projectNotification'
}
},
(modelType !== 'Project') && {
'$unwind': {
'path': '$projectNotification',
'preserveNullAndEmptyArrays': true
}
},
//Unpack the default key inside a nested call with project data
// To unpack the legislation data into the project key
(modelType !== 'Project' && populateProject) && {
Expand Down
55 changes: 54 additions & 1 deletion api/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ definitions:
- +eacDecision
- -eacDecision

### Project Definitions
### Activity Definitions
RecentActivityId:
type: object
properties:
Expand Down Expand Up @@ -5071,6 +5071,59 @@ paths:
description: "Access Denied"
schema:
$ref: "#/definitions/Error"
get:
tags:
- projectNotification
summary: "Get a list of project notifications."
operationId: protectedGet
description: "Authenticated access to retrieve a list of project notifications."
security:
- Bearer: []
x-security-scopes:
- staff
- sysadmin
parameters:
- in: query
name: fields
description: "Project fields to return."
required: false
type: array
collectionFormat: pipes
items:
type: string
enum: *projectNotificationFields
- in: query
name: pageNum
type: number
required: false
description: "Page Number (default 100 results)"
- in: query
name: pageSize
type: number
required: false
description: "Number of results per page (if 'pageNum' is specified)."
- in: query
name: count
description: "Enables/Disables count. Query count=true to enable."
required: false
type: boolean
- in: query
name: sortBy
description: "Comment fields to sort by."
required: false
type: array
items:
type: string
enum: *commentSortByFields
responses:
"200":
description: "Success"
schema:
$ref: "#/definitions/ProjectNotificationObject"
"403":
description: "Access Denied"
schema:
$ref: "#/definitions/Error"
post:
tags:
- projectNotification
Expand Down

0 comments on commit bb68f3b

Please sign in to comment.