Skip to content

Commit

Permalink
refactor: remove indirection
Browse files Browse the repository at this point in the history
This change removes the untyped getActivePersona function, which doesn't do anything useful.

Refs #398, #422
  • Loading branch information
thewilkybarkid committed Nov 8, 2021
1 parent cd16c68 commit fdfd4b8
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 14 deletions.
3 changes: 1 addition & 2 deletions src/backend/controllers/comment.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import router from 'koa-joi-router';
import { getLogger } from '../log.ts';
import { getErrorMessages } from '../utils/errors';
import getActivePersona from '../utils/persona.js';

const log = getLogger('backend:controller:comment');
const Joi = router.Joi;
Expand Down Expand Up @@ -70,7 +69,7 @@ export default function controller(commentModel, fullReviewModel, thisUser) {

ctx.params.fid ? (fid = ctx.params.fid) : null;

authorPersona = getActivePersona(ctx.state.user);
authorPersona = ctx.state.user.defaultPersona;

try {
if (fid) {
Expand Down
3 changes: 1 addition & 2 deletions src/backend/controllers/fullReview.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { QueryOrder } from '@mikro-orm/core';
import { getLogger } from '../log.ts';
import generateDOI from '../utils/generateDOI.ts';
import { getFields } from '../utils/getFields.ts';
import getActivePersona from '../utils/persona';

const log = getLogger('backend:controllers:fullReviews');
const Joi = router.Joi;
Expand Down Expand Up @@ -145,7 +144,7 @@ export default function controller(
}
} else {
const user = await thisUser.getUser(ctx);
authorPersona = await personaModel.findOne(getActivePersona(user));
authorPersona = await personaModel.findOne(user.defaultPersona);
// ensuring anonymous reviewers stay anonymous
authorPersona.isAnonymous
? creators.push({
Expand Down
3 changes: 1 addition & 2 deletions src/backend/controllers/rapidReview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import router from 'koa-joi-router';
import { QueryOrder } from '@mikro-orm/core';
import { getLogger } from '../log.ts';
import { getFields } from '../utils/getFields.ts';
import getActivePersona from '../utils/persona';

const log = getLogger('backend:controllers:rapidReview');
const Joi = router.Joi;
Expand Down Expand Up @@ -110,7 +109,7 @@ export default function controller(rapidReviews, preprints, thisUser) {
let rapidReview, authorPersona, preprint;

try {
authorPersona = getActivePersona(await thisUser.getUser(ctx));
authorPersona = await thisUser.getUser(ctx).then(user => user.defaultPersona);
} catch (err) {
log.error('Failed to load user personas.');
ctx.throw(400, err);
Expand Down
3 changes: 1 addition & 2 deletions src/backend/controllers/request.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import router from 'koa-joi-router';
import { getLogger } from '../log.ts';
import getActivePersona from '../utils/persona.js';

const log = getLogger('backend:controllers:requests');

Expand Down Expand Up @@ -55,7 +54,7 @@ export default function controller(reqModel, preprintModel, thisUser) {
log.error('HTTP 404 Error: Preprint not found');
ctx.throw(404, 'Preprint not found');
}
authorPersona = getActivePersona(await thisUser.getUser(ctx));
authorPersona = await thisUser.getUser(ctx).then(user => user.defaultPersona);

log.debug(`Adding a request.`);

Expand Down
6 changes: 0 additions & 6 deletions src/backend/utils/persona.js

This file was deleted.

0 comments on commit fdfd4b8

Please sign in to comment.