Skip to content

Commit

Permalink
Merge pull request #809 from HDRUK/release-preprod/v3.0.0
Browse files Browse the repository at this point in the history
Release preprod/v3.0.0
  • Loading branch information
cdjreekie authored Jul 27, 2022
2 parents c65c4d7 + e3455ff commit 1c31fa0
Show file tree
Hide file tree
Showing 50 changed files with 7,168 additions and 328 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"@google-cloud/bigquery": "^5.9.3",
"@google-cloud/monitoring": "^2.1.0",
"@google-cloud/pubsub": "^2.19.4",
"@google-cloud/storage": "^5.3.0",
"@hubspot/api-client": "^4.1.0",
"@sendgrid/mail": "^7.1.0",
Expand Down Expand Up @@ -49,7 +50,7 @@
"lodash": "^4.17.19",
"mailchimp-api-v3": "^1.15.0",
"migrate-mongoose": "^4.0.0",
"moment": "^2.27.0",
"moment": "^2.29.3",
"mongoose": "^5.12.7",
"morgan": "^1.10.0",
"multer": "^1.4.2",
Expand All @@ -66,6 +67,7 @@
"prettier": "^2.2.1",
"query-string": "^6.12.1",
"randomstring": "^1.1.5",
"redis": "4.0.0",
"simple-gcp-logging": "git+https://github.com/HDRUK/simple-gcp-logging.git#main",
"sinon": "^9.2.4",
"snyk": "^1.334.0",
Expand Down
3 changes: 2 additions & 1 deletion src/config/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ app.use('/api/v1/reviews', require('../resources/tool/review.route'));
app.use('/api/v1/relatedobject/', require('../resources/relatedobjects/relatedobjects.route'));

app.use('/api/v1/accounts', require('../resources/account/account.route'));
app.use('/api/v1/search/filter', require('../resources/search/filter.route'));
app.use('/api/v1/search/filter', require('../resources/search/searchFilter.route'));
app.use('/api/v1/search', require('../resources/search/search.router')); // tools projects people

app.use('/api/v1/linkchecker', require('../resources/linkchecker/linkchecker.router'));
Expand Down Expand Up @@ -254,6 +254,7 @@ app.use('/api/v1/global', require('../resources/global/global.route'));

app.use('/api/v1/search-preferences', require('../resources/searchpreferences/searchpreferences.route'));

app.use('/api/v2/questionbank', require('../resources/questionbank/questionbank.route'));
app.use('/api/v2/data-use-registers', require('../resources/dataUseRegister/dataUseRegister.route'));
app.use('/api/v1/locations', require('../resources/spatialfilter/SpatialRouter'));

Expand Down
27 changes: 26 additions & 1 deletion src/resources/auth/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import passport from 'passport';
import jwt from 'jsonwebtoken';
import { to } from 'await-to-js';
import Url from 'url';
import { isEmpty } from 'lodash';
import { isEmpty, isNull } from 'lodash';
import queryString from 'query-string';

import { ROLES } from '../user/user.roles';
Expand Down Expand Up @@ -127,6 +127,18 @@ const getTeams = async () => {
return teams;
};

const userIsTeamManager = () => async (req, res, next) => {
const { user, params } = req;

const members = await TeamModel.findOne({ _id: params.id }, { _id: 0, members: { $elemMatch: { memberid: user._id } } }).lean();
if (!isEmpty(members) && members.members[0].roles.includes(constants.roleTypes.MANAGER)) return next();

return res.status(401).json({
status: 'error',
message: 'Unauthorised to perform this action.',
});
};

const catchLoginErrorAndRedirect = (req, res, next) => {
if (req.auth.err || !req.auth.user) {
if (req.auth.err === 'loginError') {
Expand Down Expand Up @@ -202,6 +214,16 @@ const loginAndSignToken = (req, res, next) => {
});
};

function isUserMemberOfTeamById(user, teamId) {
let { teams } = user;
return teams.filter(team => !isNull(team.publisher)).some(team => team.publisher._id.equals(teamId));
}

function isUserMemberOfTeamByName(user, publisherName) {
let { teams } = user;
return teams.filter(team => !isNull(team.publisher)).some(team => team.publisher.name === publisherName);
}

export {
setup,
signToken,
Expand All @@ -213,4 +235,7 @@ export {
getTeams,
catchLoginErrorAndRedirect,
loginAndSignToken,
isUserMemberOfTeamById,
isUserMemberOfTeamByName,
userIsTeamManager,
};
2 changes: 1 addition & 1 deletion src/resources/base/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default class Repository {

// Pagination
const page = query.page * 1 || 1;
const limit = (query["limit"] !== undefined) ? query.limit * 1 : 500;
const limit = query['limit'] !== undefined ? query.limit * 1 : 1500;
const skip = (page - 1) * limit;
results = results.skip(skip).limit(limit);

Expand Down
4 changes: 2 additions & 2 deletions src/resources/dataUseRegister/dataUseRegister.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export default class DataUseRegisterController extends Controller {
}
let searchQuery = { $and: [{ activeflag: 'active' }] };

searchQuery = getObjectFilters(searchQuery, req, 'dataUseRegister');
searchQuery = getObjectFilters(searchQuery, req.query, 'dataUseRegister');

const aggregateQuery = [
{
Expand Down Expand Up @@ -380,7 +380,7 @@ export default class DataUseRegisterController extends Controller {
const team = await TeamModel.findById(dataUseRegister.publisher.toString());
if (team.notifications.length > 0 && team.notifications[0].optIn) {
team.notifications[0].subscribedEmails.map(teamEmail => {
teamEmailNotification.push({email: teamEmail});
teamEmailNotification.push({ email: teamEmail });
});
}
const dataUseTeamMembers = teamController.getTeamMembersByRole(adminTeam, constants.roleTypes.ADMIN_DATA_USE);
Expand Down
Loading

0 comments on commit 1c31fa0

Please sign in to comment.