diff --git a/lib/http/preprocessors.js b/lib/http/preprocessors.js index bf195736a..39511703e 100644 --- a/lib/http/preprocessors.js +++ b/lib/http/preprocessors.js @@ -31,7 +31,7 @@ const emptyAuthInjector = ({ Auth }, context) => context.with({ auth: Auth.by(nu const authHandler = ({ Sessions, Users, Auth }, context) => { const authBySessionToken = (token, onFailure = noop) => Sessions.getByBearerToken(token) .then((session) => { - if (!session.isDefined()) return onFailure(); + if (session.isEmpty()) return onFailure(); return context.with({ auth: Auth.by(session.get()) }); }); @@ -120,7 +120,7 @@ const authHandler = ({ Sessions, Users, Auth }, context) => { // if non-GET run authentication as usual but we'll have to check CSRF afterwards. return maybeSession.then((cxt) => { // we have to use cxt rather than context for the linter // if authentication failed anyway, just do nothing. - if ((cxt == null) || !cxt.auth.session.isDefined()) return; + if ((cxt == null) || cxt.auth.session.isEmpty()) return; const csrf = urlDecode(cxt.body.__csrf); if (csrf.isEmpty() || isBlank(csrf.get()) || (cxt.auth.session.get().csrf !== csrf.get())) { diff --git a/lib/model/query/entities.js b/lib/model/query/entities.js index fa9c52884..f1c6b02d6 100644 --- a/lib/model/query/entities.js +++ b/lib/model/query/entities.js @@ -278,7 +278,7 @@ const _updateEntity = (dataset, entityData, submissionId, submissionDef, submiss // Get version of entity on the server let serverEntity = await Entities.getById(dataset.id, clientEntity.uuid, QueryOptions.forUpdate); - if (!serverEntity.isDefined()) { + if (serverEntity.isEmpty()) { // We probably never get into this case because computeBaseVersion also checks for the existence of the entity // and returns an entity def associated with a top level entity. throw Problem.user.entityNotFound({ entityUuid: clientEntity.uuid, datasetName: dataset.name }); @@ -363,7 +363,7 @@ const _computeBaseVersion = (eventId, dataset, clientEntity, submissionDef, forc const condition = { version: clientEntity.def.baseVersion }; const maybeDef = await Entities.getDef(dataset.id, clientEntity.uuid, new QueryOptions({ condition })); - if (!maybeDef.isDefined()) { + if (maybeDef.isEmpty()) { // If the def doesn't exist, check if the version doesnt exist or the whole entity doesnt exist // There are different problems for each case const maybeEntity = await Entities.getById(dataset.id, clientEntity.uuid); @@ -388,7 +388,7 @@ const _computeBaseVersion = (eventId, dataset, clientEntity, submissionDef, forc const baseEntityVersion = await Entities.getDef(dataset.id, clientEntity.uuid, new QueryOptions({ condition })); - if (!baseEntityVersion.isDefined()) { + if (baseEntityVersion.isEmpty()) { if (forceOutOfOrderProcessing) { // If the base version doesn't exist but we forcing the update anyway, use the latest version on the server as the base. // If that can't be found, throw an error for _processSubmissionEvent to catch so it can try create instead of update. @@ -424,7 +424,7 @@ const _processSubmissionEvent = (event, parentEvent) => async ({ Audits, Dataset const form = await Forms.getByActeeId(event.acteeId); // If form is deleted/purged then submission won't be there either. - if (!form.isDefined()) + if (form.isEmpty()) return null; const existingEntity = await Entities.getDefBySubmissionId(submissionId); @@ -442,7 +442,7 @@ const _processSubmissionEvent = (event, parentEvent) => async ({ Audits, Dataset const submission = await Submissions.getSubAndDefById(submissionDefId); // If Submission is deleted/purged - Safety check, will not be true at this line - if (!submission.isDefined()) + if (submission.isEmpty()) return null; // Don't process draft submissions diff --git a/lib/resources/oidc.js b/lib/resources/oidc.js index 8b7088dc4..43ab2b6c0 100644 --- a/lib/resources/oidc.js +++ b/lib/resources/oidc.js @@ -190,7 +190,7 @@ function errorToFrontend(req, res, errorCode) { async function getUserByEmail({ Users }, email) { const userOption = await Users.getByEmail(email); - if (!userOption.isDefined()) return; + if (userOption.isEmpty()) return; const user = userOption.get(); diff --git a/lib/task/analytics.js b/lib/task/analytics.js index a70977663..b38bfdb37 100644 --- a/lib/task/analytics.js +++ b/lib/task/analytics.js @@ -8,7 +8,6 @@ // except according to the terms contained in the LICENSE file. const config = require('config'); -const { isEmpty } = require('ramda'); const { task } = require('./task'); const { buildSubmission } = require('../data/analytics'); @@ -25,7 +24,7 @@ const runAnalytics = task.withContainer(({ Analytics, Audits, odkAnalytics }) => .then((configuration) => ((configuration.value.enabled === false) ? { sent: false, message: 'Analytics disabled in config' } : Analytics.getLatestAudit() - .then((au) => ((!isEmpty(au) && au.value.details.success === true && !force) + .then((au) => ((au.isDefined() && au.value.details.success === true && !force) ? { sent: false, message: `Analytics sent recently: ${au.value.loggedAt}` } : Analytics.previewMetrics() .then((data) => {