Skip to content

Commit

Permalink
revert changes for getCurrentUser
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Sherman <[email protected]>
  • Loading branch information
usingtechnology committed Jan 16, 2025
1 parent 9de9225 commit 39edd18
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
2 changes: 0 additions & 2 deletions app/src/forms/form/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const { Permissions, Roles, Statuses } = require('../common/constants');
const formMetadataService = require('./formMetadata/service');
const { eventStreamService, SUBMISSION_EVENT_TYPES } = require('../../components/eventStreamService');
const eventStreamConfigService = require('./eventStreamConfig/service');
const cacheService = require('../../components/cacheService');
const Rolenames = [Roles.OWNER, Roles.TEAM_MANAGER, Roles.FORM_DESIGNER, Roles.SUBMISSION_REVIEWER, Roles.FORM_SUBMITTER, Roles.SUBMISSION_APPROVER];

const service = {
Expand Down Expand Up @@ -117,7 +116,6 @@ const service = {
return { id: uuidv4(), createdBy: currentUser.usernameIdp, userId: currentUser.id, formId: obj.id, role: r };
});
await FormRoleUser.query(trx).insert(userRoles);
await cacheService.clearCurrentUser(currentUser);

// create a unpublished draft
const draft = {
Expand Down
45 changes: 17 additions & 28 deletions app/src/forms/rbac/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const { Roles } = require('../common/constants');
const { queryUtils } = require('../common/utils');
const authService = require('../auth/service');
const idpService = require('../../components/idpService');
const cacheService = require('../../components/cacheService');

const service = {
list: async () => {
Expand All @@ -21,7 +20,6 @@ const service = {

await FormRoleUser.query(trx).insert(obj);
await trx.commit();
await cacheService.clearCurrentUsersById([obj.userId]);
const result = await service.read(obj.id);
return result;
} catch (err) {
Expand All @@ -44,7 +42,6 @@ const service = {

await FormRoleUser.query(trx).patchAndFetchById(obj.id, update);
await trx.commit();
await cacheService.clearCurrentUsersById([obj.userId]);
const result = await service.read(obj.id);
return result;
} catch (err) {
Expand All @@ -62,36 +59,31 @@ const service = {
},

delete: async (id) => {
const obj = await FormRoleUser.query().findById(id).throwIfNotFound();
await cacheService.clearCurrentUsersById([obj.userId]);
return FormRoleUser.query().deleteById(id);
return FormRoleUser.query().deleteById(id).throwIfNotFound();
},

readUser: async (id) => {
return User.query().findById(id).throwIfNotFound();
},

getCurrentUser: async (currentUser, params) => {
let user = await cacheService.getCurrentUser(currentUser, params);
if (!user) {
user = Object.assign({}, currentUser);
const accessLevels = [];
if (user.public) {
accessLevels.push('public');
} else {
if (params.public) accessLevels.push('public');
if (params.idp) accessLevels.push('idp');
if (params.team) accessLevels.push('team');
}

const forms = await authService.getUserForms(user, {
...params,
active: true,
});
const filteredForms = authService.filterForms(user, forms, accessLevels);
user.forms = filteredForms;
await cacheService.setCurrentUser(currentUser, params, user);
const user = Object.assign({}, currentUser);
const accessLevels = [];
if (user.public) {
accessLevels.push('public');
} else {
if (params.public) accessLevels.push('public');
if (params.idp) accessLevels.push('idp');
if (params.team) accessLevels.push('team');
}

const forms = await authService.getUserForms(user, {
...params,
active: true,
});
const filteredForms = authService.filterForms(user, forms, accessLevels);
user.forms = filteredForms;

return user;
},

Expand Down Expand Up @@ -166,7 +158,6 @@ const service = {
trx = await FormRoleUser.startTransaction();
// remove existing mappings...
await FormRoleUser.query(trx).delete().where('formId', formId).where('userId', userId);
await cacheService.clearCurrentUsersById([userId]);

// create the batch and insert...
if (!Array.isArray(data)) {
Expand Down Expand Up @@ -233,7 +224,6 @@ const service = {
trx = await FormRoleUser.startTransaction();
// remove existing mappings...
await FormRoleUser.query(trx).delete().where('formId', formId).whereIn('userId', data);
await cacheService.clearCurrentUsersById(data);

await trx.commit();
return;
Expand Down Expand Up @@ -278,7 +268,6 @@ const service = {
trx = await FormRoleUser.startTransaction();
// remove existing mappings...
await FormRoleUser.query(trx).delete().where('userId', userId).where('formId', formId);
await cacheService.clearCurrentUsersById([userId]);

// add an id and save them
const items = data.map((d) => {
Expand Down

0 comments on commit 39edd18

Please sign in to comment.