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

Revert "[BIOMAGE-1878] - Add v2 cellsets endpoints" #353

Merged
merged 3 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
8 changes: 2 additions & 6 deletions src/api.v2/controllers/__mocks__/accessController.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const mockGetUserAccess = jest.fn();
const mockInviteUser = jest.fn();
const mockRevokeAccess = jest.fn();
const mockGetExperimentUsers = jest.fn();

module.exports = {
getUserAccess: mockGetUserAccess,
inviteUser: mockInviteUser,
revokeAccess: mockRevokeAccess,
getExperimentUsers: mockGetExperimentUsers,
};
7 changes: 0 additions & 7 deletions src/api.v2/controllers/__mocks__/cellSetsController.js

This file was deleted.

40 changes: 4 additions & 36 deletions src/api.v2/controllers/accessController.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,19 @@
const getExperimentUsers = require('../helpers/access/getExperimentUsers');
const createUserInvite = require('../helpers/access/createUserInvite');
const removeAccess = require('../helpers/access/removeAccess');

const OK = require('../../utils/responses/OK');
const getUserRoles = require('../helpers/access/getUserRoles');
const getLogger = require('../../utils/getLogger');

const logger = getLogger('[AccessController] - ');

const getUserAccess = async (req, res) => {
const getExperimentUsers = async (req, res) => {
const { experimentId } = req.params;

logger.log(`Fetching users for experiment ${experimentId}`);
const users = await getExperimentUsers(experimentId);
const users = await getUserRoles(experimentId);

logger.log(`Users fetched for experiment ${experimentId}`);

res.json(users);
};

const inviteUser = async (req, res) => {
const { experimentId } = req.params;
const {
userEmail, role,
} = req.body;

logger.log(`Inviting users to experiment ${experimentId}`);
await createUserInvite(experimentId, userEmail, role, req.user);

logger.log(`Users invited to experiment ${experimentId}`);

res.json(OK());
};

const revokeAccess = async (req, res) => {
const { experimentId } = req.params;
const { userEmail } = req.body;

logger.log(`Deleting user access from experiment ${experimentId}`);
await removeAccess(experimentId, userEmail);

logger.log(`User access deleted from experiment ${experimentId}`);

res.json(OK());
};

module.exports = {
getUserAccess,
inviteUser,
revokeAccess,
getExperimentUsers,
};
45 changes: 0 additions & 45 deletions src/api.v2/controllers/cellSetsController.js

This file was deleted.

43 changes: 0 additions & 43 deletions src/api.v2/helpers/access/createUserInvite.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
const { getAwsUserAttributesByEmail } = require('../../../utils/aws/user');
const config = require('../../../config');

const UserAccess = require('../../model/UserAccess');

const AccessRole = require('../../../utils/enums/AccessRole');

const getExperimentUsers = async (experimentId) => {
const { cognitoISP } = config;

const getAwsUserAttributesByEmail = async (email) => {
const poolId = await config.awsUserPoolIdPromise;
const user = await cognitoISP.adminGetUser({ UserPoolId: poolId, Username: email }).promise();
return user.UserAttributes;
};

const getUserRoles = async (experimentId) => {
const userData = await new UserAccess().getExperimentUsers(experimentId);

// Remove admin from user list
Expand All @@ -31,4 +39,4 @@ const getExperimentUsers = async (experimentId) => {
return experimentUsers;
};

module.exports = getExperimentUsers;
module.exports = getUserRoles;
12 changes: 0 additions & 12 deletions src/api.v2/helpers/access/removeAccess.js

This file was deleted.

1 change: 0 additions & 1 deletion src/api.v2/helpers/s3/bucketNames.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const config = require('../../../config');

const bucketNames = {
SAMPLE_FILES: `biomage-originals-${config.clusterEnv}`,
CELL_SETS: `cell-sets-${config.clusterEnv}`,
};

module.exports = bucketNames;
27 changes: 0 additions & 27 deletions src/api.v2/helpers/s3/getObject.js

This file was deleted.

18 changes: 0 additions & 18 deletions src/api.v2/helpers/s3/getS3Client.js

This file was deleted.

39 changes: 0 additions & 39 deletions src/api.v2/helpers/s3/patchCellSetsObject.js

This file was deleted.

22 changes: 0 additions & 22 deletions src/api.v2/helpers/s3/putObject.js

This file was deleted.

25 changes: 6 additions & 19 deletions src/api.v2/model/UserAccess.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,34 +38,21 @@ class UserAccess extends BasicModel {
return experimentUsers;
}

async addToInviteAccess(userId, experimentId, role) {
return await this.sql
.insert({ user_id: userId, experiment_id: experimentId, access_role: role })
.into(tableNames.INVITE_ACCESS);
}

async grantAccess(userId, experimentId, role) {
return await this.create(
{ user_id: userId, experiment_id: experimentId, access_role: role },
);
}

async removeAccess(userId, experimentId) {
return await this.delete({ experiment_id: experimentId, user_id: userId });
}

async createNewExperimentPermissions(userId, experimentId) {
logger.log('Setting up access permissions for experiment');

// Create admin permissions
await this.grantAccess(config.adminSub, experimentId, AccessRole.ADMIN);
await this.create(
{ user_id: config.adminSub, experiment_id: experimentId, access_role: AccessRole.ADMIN },
);

if (userId === config.adminSub) {
logger.log('User is the admin, so only creating admin access');
return;
}

await this.grantAccess(userId, experimentId, AccessRole.OWNER);
await this.create(
{ user_id: userId, experiment_id: experimentId, access_role: AccessRole.OWNER },
);
}

async canAccessExperiment(userId, experimentId, url, method) {
Expand Down
14 changes: 2 additions & 12 deletions src/api.v2/routes/access.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
const {
getUserAccess,
inviteUser,
revokeAccess,
getExperimentUsers,
} = require('../controllers/accessController');

const { expressAuthorizationMiddleware } = require('../middlewares/authMiddlewares');

module.exports = {
'access#getExperimentUsers': [
expressAuthorizationMiddleware,
(req, res, next) => getUserAccess(req, res).catch(next),
],
'access#inviteUser': [
expressAuthorizationMiddleware,
(req, res, next) => inviteUser(req, res).catch(next),
],
'access#revokeAccess': [
expressAuthorizationMiddleware,
(req, res, next) => revokeAccess(req, res).catch(next),
(req, res, next) => getExperimentUsers(req, res).catch(next),
],
};
Loading