diff --git a/api/controllers/projectNotification.js b/api/controllers/projectNotification.js index b335e3fd..fff50ae5 100644 --- a/api/controllers/projectNotification.js +++ b/api/controllers/projectNotification.js @@ -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; diff --git a/api/controllers/recentActivity.js b/api/controllers/recentActivity.js index bc11f6e5..7f927a5d 100644 --- a/api/controllers/recentActivity.js +++ b/api/controllers/recentActivity.js @@ -15,6 +15,7 @@ var getSanitizedFields = function (fields) { 'contentUrl', 'type', 'notificationName', + 'projectNotification', 'pcp', 'active', 'project', @@ -37,6 +38,7 @@ exports.publicGet = async function (args, res) { 'contentUrl', 'type', 'notificationName', + 'projectNotification', 'pcp', 'active', 'project', diff --git a/api/helpers/models/recentActivity.js b/api/helpers/models/recentActivity.js index b9cfbedf..75b937b0 100644 --- a/api/helpers/models/recentActivity.js +++ b/api/helpers/models/recentActivity.js @@ -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 }, diff --git a/api/helpers/utils.js b/api/helpers/utils.js index 115916c9..b62e9e16 100644 --- a/api/helpers/utils.js +++ b/api/helpers/utils.js @@ -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) && { diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index e88536f9..b1b98718 100644 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -213,7 +213,7 @@ definitions: - +eacDecision - -eacDecision -### Project Definitions +### Activity Definitions RecentActivityId: type: object properties: @@ -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 diff --git a/package.json b/package.json index 729e6c3c..130d8e51 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "reproject": "~1.2.2", "request": "~2.88.0", "request-promise-native": "~1.0.7", - "sharp": "~0.23.0", + "sharp": "~0.32.0", "stream": "~0.0.2", "stream-transform": "~2.0.1", "swagger-tools": "~0.10.4",