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

Public-18: Allow Notifications in news list #749

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading