Skip to content

Commit

Permalink
Merge pull request #249 from adhocteam/cm-393-read-regions-permissions
Browse files Browse the repository at this point in the history
Cm 393 read regions permissions
  • Loading branch information
rahearn authored Mar 17, 2021
2 parents 7130afd + 2195443 commit 23f4978
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ parameters:
default: "main"
type: string
sandbox_git_branch: # change to feature branch to test deployment
default: "rolling-deploys"
default: "cm-393-read-regions-permissions"
type: string
prod_new_relic_app_id:
default: "877570491"
Expand Down
3 changes: 1 addition & 2 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CronJob } from 'cron';
import { hsesAuth } from './middleware/authMiddleware';
import updateGrantsGrantees from './lib/updateGrantsGrantees';

import findOrCreateUser, { getUserReadRegions } from './services/accessValidation';
import findOrCreateUser from './services/accessValidation';

import { logger, auditLogger, requestLogger } from './logger';

Expand Down Expand Up @@ -82,7 +82,6 @@ app.get(oauth2CallbackPath, async (req, res) => {
});

req.session.userId = dbUser.id;
req.session.readRegions = await getUserReadRegions(dbUser.id);
auditLogger.info(`User ${dbUser.id} logged in`);

logger.debug(`referrer path: ${req.session.referrerPath}`);
Expand Down
3 changes: 1 addition & 2 deletions src/middleware/authMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {} from 'dotenv/config';
import ClientOAuth2 from 'client-oauth2';
import { auditLogger } from '../logger';
import { validateUserAuthForAccess, getUserReadRegions } from '../services/accessValidation';
import { validateUserAuthForAccess } from '../services/accessValidation';

export const hsesAuth = new ClientOAuth2({
clientId: process.env.AUTH_CLIENT_ID,
Expand Down Expand Up @@ -45,7 +45,6 @@ export default async function authMiddleware(req, res, next) {
if (process.env.NODE_ENV !== 'production' && process.env.BYPASS_AUTH === 'true') {
auditLogger.warn(`Bypassing authentication in authMiddleware - using User ${process.env.CURRENT_USER_ID}`);
req.session.userId = process.env.CURRENT_USER_ID;
req.session.readRegions = await getUserReadRegions(process.env.CURRENT_USER_ID);
}
let userId = null;
if (req.session) {
Expand Down
3 changes: 2 additions & 1 deletion src/routes/activityReports/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { goalsForGrants } from '../../services/goals';
import { userById, usersWithPermissions } from '../../services/users';
import { REPORT_STATUSES, DECIMAL_BASE } from '../../constants';
import { getUserReadRegions } from '../../services/accessValidation';

const { APPROVE_REPORTS } = SCOPES;

Expand Down Expand Up @@ -200,7 +201,7 @@ export async function getReport(req, res) {
* @param {*} res - response
*/
export async function getReports(req, res) {
const { readRegions } = req.session;
const readRegions = await getUserReadRegions(req.session.userId);
const reportsWithCount = await activityReports(readRegions, req.query);
if (!reportsWithCount) {
res.sendStatus(404);
Expand Down

0 comments on commit 23f4978

Please sign in to comment.