aws-user-service
Advanced tools
Comparing version 1.2.0 to 1.2.1
29
index.js
@@ -0,3 +1,6 @@ | ||
const MongoRepository = require('senter-mongo-repository') | ||
const AWS = require('aws-sdk') | ||
AWS.config.update({ region: process.env.REGION }) | ||
var noOrganisationOptions = MongoRepository.BuildCallOptions(true, false) | ||
@@ -33,24 +36,8 @@ module.exports = class AwsUserService { | ||
async getOrganisationIdFromRequest(request) { | ||
const realUserId = this.getActualUserIdFromRequest(request) | ||
if (!request.query.impersonatingUserId) { | ||
const user = await this.userRepository.getById(realUserId, realUserId) | ||
if (!user) { | ||
throw new Error('User not found') | ||
} | ||
return user.organisationId | ||
const userId = getUserIdFromRequest(request) | ||
const user = await this.userRepository.getById(userId, null, noOrganisationOptions) | ||
if (!user) { | ||
throw new Error('User not found') | ||
} | ||
// check if current user is Admin | ||
const adminCheckSuccessful = await this.isAdmin(realUserId) | ||
if (adminCheckSuccessful === true) { | ||
// return impersonating user's organisation id | ||
const user = await this.userRepository.getById(request.query.impersonatingUserId, request.query.impersonatingUserId) | ||
if (!user) { | ||
throw new Error('User not found') | ||
} | ||
return user.organisationId | ||
} | ||
console.log('No admin permission to impersonate user', request.query.impersonatingUserId) | ||
throw new Error('Non admin attempt to impersonate'); | ||
return user.organisationId | ||
} | ||
@@ -57,0 +44,0 @@ |
{ | ||
"name": "aws-user-service", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Contain methods to work with asw user", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
4852
111