Brandon Nicholls

RESCOI-873: Added logArguments() to most functions

......@@ -52,6 +52,8 @@ const DEFAULT_PORT = 8090;
initFeatureFlags(flags);
function conditionallyLogRequests(app, logLevel) {
log.logArguments('conditionallyLogRequests', {logLevel});
if (logLevel <= LOG_LEVEL.INFO) {
app.use((req, res, next) => {
const startTime = new Date().getTime();
......
......@@ -23,6 +23,8 @@ const AdditionalReviewerDB = {};
export default AdditionalReviewerDB;
AdditionalReviewerDB.getAdditionalReviewer = async function (knex, id) {
this.log.logArguments({id});
const reviewer = await knex('additional_reviewer')
.first(
'name',
......@@ -36,6 +38,7 @@ AdditionalReviewerDB.getAdditionalReviewer = async function (knex, id) {
'assigned_by as assignedBy'
)
.where({id});
if (reviewer && reviewer.dates) {
reviewer.dates = JSON.parse(reviewer.dates);
}
......@@ -46,6 +49,8 @@ AdditionalReviewerDB.getDisclosuresForReviewer = async function(
knex,
schoolId
) {
this.log.logArguments({schoolId});
return await knex('additional_reviewer as ar')
.select(
'd.type_cd as typeCd',
......@@ -74,6 +79,8 @@ AdditionalReviewerDB.getDisclosureIdsForReviewer = async function(
knex,
schoolId
) {
this.log.logArguments({schoolId});
const reviewers = await knex('additional_reviewer')
.select('disclosure_id as disclosureId')
.where({
......@@ -91,6 +98,8 @@ AdditionalReviewerDB.getReviewerForDisclosureAndUser = async function (
schoolId,
disclosureId
) {
this.log.logArguments({schoolId, disclosureId});
const criteria = {
disclosure_id: disclosureId,
active: true
......@@ -110,6 +119,8 @@ AdditionalReviewerDB.createAdditionalReviewer = async function (
reviewer,
displayName
) {
this.log.logArguments({reviewer, displayName});
reviewer.dates = [
{
type: DATE_TYPE.ASSIGNED,
......@@ -135,6 +146,8 @@ AdditionalReviewerDB.createAdditionalReviewer = async function (
};
AdditionalReviewerDB.unassignAdditionalReviewer = async function (knex, id) {
this.log.logArguments({id});
const preExistingDates = await knex
.first('dates as dates')
.from('additional_reviewer')
......@@ -161,6 +174,8 @@ AdditionalReviewerDB.unassignAdditionalReviewer = async function (knex, id) {
};
AdditionalReviewerDB.updateAdditionalReviewer = function (knex, id, updates) {
this.log.logArguments({id, updates});
if (updates.dates) {
updates.dates = JSON.stringify(updates.dates);
}
......@@ -178,6 +193,8 @@ AdditionalReviewerDB.findAdditionalReviewer = async function (
userId,
disclosureId
) {
this.log.logArguments({userId, disclosureId});
return await knex('additional_reviewer')
.first('id')
.where({
......@@ -193,6 +210,13 @@ AdditionalReviewerDB.saveRecommendation = async function (
declarationId,
dispositionType
) {
this.log.logArguments({
schoolId,
disclosureId,
declarationId,
dispositionType
});
const additionalReviewer = await AdditionalReviewerDB.findAdditionalReviewer(
knex,
schoolId,
......@@ -239,6 +263,13 @@ AdditionalReviewerDB.saveProjectRecommendation = async function (
projectPersonId,
dispositionType
) {
this.log.logArguments({
schoolId,
disclosureId,
projectPersonId,
dispositionType
});
const additionalReviewer = await AdditionalReviewerDB.findAdditionalReviewer(
knex,
schoolId,
......
......@@ -26,6 +26,8 @@ CommonDB.usingMySql = function(knex) {
};
CommonDB.isDisclosureUsers = async function (knex, disclosureId, userId) {
this.log.logArguments({disclosureId, userId});
const result = await knex
.first('user_id')
.from('disclosure')
......@@ -38,6 +40,8 @@ CommonDB.isDisclosureUsers = async function (knex, disclosureId, userId) {
};
CommonDB.isFinancialEntityUsers = async function (knex, id, userId) {
this.log.logArguments({id, userId});
const result = await knex
.first('d.user_id')
.from('fin_entity as fe')
......@@ -51,6 +55,8 @@ CommonDB.isFinancialEntityUsers = async function (knex, id, userId) {
};
CommonDB.isProjectUsers = async function (knex, projectId, userId) {
this.log.logArguments({projectId, userId});
const result = await knex
.first('id')
.from('project_person')
......@@ -63,6 +69,8 @@ CommonDB.isProjectUsers = async function (knex, projectId, userId) {
};
CommonDB.getDisclosureForFinancialEntity = async function (knex, id) {
this.log.logArguments({id});
const entity = await knex('fin_entity')
.first('disclosure_id as disclosureId')
.where({id});
......@@ -75,6 +83,8 @@ CommonDB.verifyRelationshipIsUsers = async function (
userId,
relationshipId
) {
this.log.logArguments({userId, relationshipId});
const rows = await knex
.first('r.id')
.from('relationship as r')
......
......@@ -55,6 +55,8 @@ const SCREENING_QUESTIONNAIRE_TYPE_CD = 1;
const FIN_ENTITY_QUESTIONNAIRE_TYPE_CD = 2;
ConfigDB.createDeleteQueries = async function (knex, collection, tableProps) {
this.log.logArguments({collection, tableProps});
let sel = knex(tableProps.table).select(tableProps.pk);
if (tableProps.where) {
sel = sel.where(tableProps.where);
......@@ -80,6 +82,8 @@ ConfigDB.createDeleteQueries = async function (knex, collection, tableProps) {
};
ConfigDB.createInsertQueries = async function(knex, collection, tableProps) {
this.log.logArguments({collection, tableProps});
return await Promise.all(
collection.map(async (line) => {
const tmpId = line.tmpId;
......@@ -99,6 +103,8 @@ ConfigDB.createInsertQueries = async function(knex, collection, tableProps) {
};
ConfigDB.createUpdateQueries = function(knex, collection, tableProps) {
this.log.logArguments({collection, tableProps});
return Promise.all(
collection.map(line => {
delete line.tmpId;
......@@ -111,6 +117,8 @@ ConfigDB.createUpdateQueries = function(knex, collection, tableProps) {
};
ConfigDB.rowExists = async function(knex, table, primaryKeyColumn, value) {
this.log.logArguments({table, primaryKeyColumn, value});
const result = await knex
.first(primaryKeyColumn)
.from(table)
......@@ -124,6 +132,8 @@ ConfigDB.createCollectionQueries = async function(
collection,
tableProps
) {
this.log.logArguments({collection, tableProps});
const updates = [];
const inserts = [];
for (const line of collection) {
......@@ -166,6 +176,8 @@ ConfigDB.createCollectionQueries = async function(
};
ConfigDB.convertQuestionFormat = function(questions, questionnaireId) {
this.log.logArguments({questions, questionnaireId});
return questions.map(question => {
question.question = JSON.stringify(question.question);
question.questionnaire_id = questionnaireId;
......@@ -183,6 +195,8 @@ ConfigDB.getNotificationTemplates = async function(
hostname,
notificationsMode
) {
this.log.logArguments({hostname, notificationsMode});
if (notificationsMode > NOTIFICATIONS_MODE.OFF) {
const templates = await knex.select(
'template_id as templateId',
......@@ -233,6 +247,8 @@ ConfigDB.createMatrixTypes = async function(knex) {
};
ConfigDB.getQuestionnaireQuestions = async function (knex, typeCd) {
this.log.logArguments({typeCd});
const questionnaire = await knex
.first('id')
.from('questionnaire')
......@@ -312,6 +328,8 @@ ConfigDB.getGeneralConfig = async function (knex) {
};
ConfigDB.getConfig = async function (dbInfo, knex, hostname) {
this.log.logArguments({hostname});
let config = {};
const notificationsMode = getNotificationsInfo(dbInfo).notificationsMode;
......@@ -354,6 +372,8 @@ ConfigDB.getConfig = async function (dbInfo, knex, hostname) {
};
ConfigDB.updateParentIdOnChildren = function (children, updatedParents) {
this.log.logArguments({children, updatedParents});
return children.map(question => {
if (isNaN(question.parent)) {
const parent = updatedParents.find(p => {
......@@ -369,6 +389,8 @@ ConfigDB.updateParentIdOnChildren = function (children, updatedParents) {
};
ConfigDB.saveScreeningQuestionnaire = async function(knex, questions) {
this.log.logArguments({questions});
const questionnaire = await knex
.first('id')
.from('questionnaire')
......@@ -412,6 +434,8 @@ ConfigDB.saveScreeningQuestionnaire = async function(knex, questions) {
};
ConfigDB.saveEntityQuestionnaire = async function(knex, questions) {
this.log.logArguments({questions});
const result = await knex
.first('*')
.from('questionnaire')
......@@ -444,6 +468,8 @@ ConfigDB.saveEntityQuestionnaire = async function(knex, questions) {
};
ConfigDB.setConfig = async function(dbInfo, knex, userId, body, hostname) {
this.log.logArguments({userId, body, hostname});
const config = snakeizeJson(body);
if (config.disposition_types && Array.isArray(config.disposition_types)) {
......@@ -596,6 +622,8 @@ ConfigDB.setConfig = async function(dbInfo, knex, userId, body, hostname) {
};
ConfigDB.archiveConfig = async function(knex, userId, userName, config) {
this.log.logArguments({userId, userName, config});
delete config.id;
const id = await knex('config')
.insert({
......@@ -609,6 +637,8 @@ ConfigDB.archiveConfig = async function(knex, userId, userName, config) {
};
ConfigDB.getArchivedConfig = async function (knex, id) {
this.log.logArguments({id});
if (cachedConfigs[id]) {
return cachedConfigs[id];
}
......@@ -650,6 +680,8 @@ ConfigDB.getRequiredProjectTypes = function (knex) {
};
ConfigDB.getProjectTypeDescription = async function (knex, typeCd) {
this.log.logArguments({typeCd});
const projectType = await knex('project_type')
.first('description')
.where({type_cd: typeCd});
......@@ -658,6 +690,8 @@ ConfigDB.getProjectTypeDescription = async function (knex, typeCd) {
};
ConfigDB.getCoreTemplateIdByTemplateId = async function (knex, templateId) {
this.log.logArguments({templateId});
const template = await knex('notification_template')
.first('core_template_id as coreTemplateId', 'active')
.where({template_id: templateId});
......
This diff is collapsed. Click to expand it.
......@@ -26,6 +26,8 @@ FeaturesDB.getFeatureFlags = async function(knex) {
};
FeaturesDB.setFeatureFlagState = async function(knex, key, active) {
this.log.logArguments({key, active});
const rowsUpdated = await knex('feature_flag')
.update({active})
.where({key});
......
......@@ -24,6 +24,8 @@ const FileDB = {};
export default FileDB;
FileDB.getFile = async function getFile(knex, userInfo, id) {
this.log.logArguments({id});
const criteria = {
id
};
......@@ -58,6 +60,8 @@ FileDB.getFile = async function getFile(knex, userInfo, id) {
};
FileDB.getFiles = function (knex, userInfo, refId, fileType) {
this.log.logArguments({refId, fileType});
const query = knex
.select('name', 'key')
.from('file')
......@@ -93,6 +97,8 @@ FileDB.getFiles = function (knex, userInfo, refId, fileType) {
};
FileDB.getFilesForReview = function (knex, userInfo, refId, fileType) {
this.log.logArguments({refId, fileType});
const query = knex
.select('name', 'key', 'id')
.from('file')
......@@ -160,6 +166,8 @@ FileDB.saveNewFiles = async function(knex, body, files, userInfo) {
};
FileDB.deleteFiles = async function(dbInfo, knex, userInfo, fileId) {
this.log.logArguments({fileId});
const criteria = {
id: fileId
};
......
......@@ -38,6 +38,8 @@ NotificationsDB.notificationTemplateIsForCOI = async function(
knex,
templateId
) {
this.log.logArguments({templateId});
const row = await knex
.first('template_id')
.from('notification_template')
......
......@@ -25,6 +25,8 @@ const PIDB = {};
export default PIDB;
PIDB.queryUsingIndexOracle = function(knex, term) {
this.log.logArguments({term});
return knex
.distinct('submitted_by as value')
.from('disclosure as d')
......@@ -33,6 +35,8 @@ PIDB.queryUsingIndexOracle = function(knex, term) {
};
PIDB.queryWithoutIndexOracle = function(knex, term) {
this.log.logArguments({term});
return knex
.distinct('submitted_by as value')
.from('disclosure as d')
......@@ -41,6 +45,8 @@ PIDB.queryWithoutIndexOracle = function(knex, term) {
};
PIDB.queryUsingIndexMySQL = function(knex, term) {
this.log.logArguments({term});
return knex
.distinct('submitted_by as value')
.from('disclosure as d')
......@@ -49,6 +55,8 @@ PIDB.queryUsingIndexMySQL = function(knex, term) {
};
PIDB.queryWithoutIndexMySQL = function(knex, term) {
this.log.logArguments({term});
return knex
.distinct('submitted_by as value')
.from('disclosure as d')
......@@ -57,17 +65,23 @@ PIDB.queryWithoutIndexMySQL = function(knex, term) {
};
PIDB.addReviewerCriteria = function(query, schoolId) {
this.log.logArguments({schoolId});
return query
.leftJoin('additional_reviewer as ar', 'ar.disclosure_id', 'd.id')
.andWhere({'ar.user_id': schoolId});
};
PIDB.checkTerm = function(term) {
this.log.logArguments({term});
const reg = new RegExp('^[-\'.a-zA-Z ]+$');
return reg.test(term);
};
PIDB.getSuggestions = async function(knex, term, userInfo) {
this.log.logArguments({term});
let indexQuery;
let noIndexQuery;
if (knex.dbType === 'mysql') {
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
......@@ -38,6 +38,8 @@ TravelLogDB.getTravelLogEntries = function(
sortDirection,
filter
) {
this.log.logArguments({userId, sortColumn, sortDirection, filter});
let dbSortColumn;
const dbSortDirection = sortDirection === 'DESCENDING' ? 'desc' : undefined;
switch (sortColumn) {
......@@ -122,6 +124,8 @@ TravelLogDB.createNewEntity = async function(
entry,
status
) {
this.log.logArguments({disclosureId, entry, status});
const id = await knex('fin_entity').insert({
disclosure_id: disclosureId,
name: entry.entityName,
......@@ -138,6 +142,8 @@ TravelLogDB.createNewRelationship = async function(
entry,
status
) {
this.log.logArguments({entityId, entry, status});
const relationshipId = await knex('relationship').insert({
fin_entity_id: entityId,
relationship_cd: ENTITY_RELATIONSHIP.TRAVEL,
......@@ -160,6 +166,8 @@ TravelLogDB.createNewRelationship = async function(
};
TravelLogDB.isSubmitted = function(status) {
this.log.logArguments({status});
if (EDITABLE_STATUSES.includes(status)) {
return false;
}
......@@ -172,6 +180,8 @@ TravelLogDB.getExistingFinancialEntity = function(
entityName,
disclosureId
) {
this.log.logArguments({entityName, disclosureId});
return knex('fin_entity')
.first('id')
.where({
......@@ -186,6 +196,8 @@ TravelLogDB.handleTravelLogEntry = async function(
entry,
status
) {
this.log.logArguments({disclosureId, entry, status});
const entity = await TravelLogDB.getExistingFinancialEntity(
knex,
entry.entityName,
......@@ -216,6 +228,8 @@ TravelLogDB.handleTravelLogEntry = async function(
};
TravelLogDB.getAnnualDisclosureForUser = function(knex, schoolId) {
this.log.logArguments({schoolId});
return knex('disclosure')
.first(
'status_cd',
......@@ -228,6 +242,8 @@ TravelLogDB.getAnnualDisclosureForUser = function(knex, schoolId) {
};
TravelLogDB.createTravelLogEntry = async function(knex, entry, userInfo) {
this.log.logArguments({entry});
const disclosure = await TravelLogDB.getAnnualDisclosureForUser(
knex,
userInfo.schoolId
......@@ -267,6 +283,8 @@ TravelLogDB.createTravelLogEntry = async function(knex, entry, userInfo) {
};
TravelLogDB.getRelationshipsEntity = async function(knex, id) {
this.log.logArguments({id});
const relationship = await knex('relationship')
.first('fin_entity_id')
.where('id', id);
......@@ -275,18 +293,24 @@ TravelLogDB.getRelationshipsEntity = async function(knex, id) {
};
TravelLogDB.deleteTravelRelationship = function(knex, id) {
this.log.logArguments({id});
return knex('travel_relationship')
.del()
.where('relationship_id', id);
};
TravelLogDB.deleteRelationship = function(knex, id) {
this.log.logArguments({id});
return knex('relationship')
.del()
.where('id', id);
};
TravelLogDB.getQuestionnaireAnswerIds = async function(knex, id) {
this.log.logArguments({id});
const answers = await knex('fin_entity_answer')
.select('questionnaire_answer_id')
.where('fin_entity_id', id);
......@@ -297,24 +321,32 @@ TravelLogDB.getQuestionnaireAnswerIds = async function(knex, id) {
};
TravelLogDB.deleteFinEntityAnswers = function(knex, id) {
this.log.logArguments({id});
return knex('fin_entity_answer')
.del()
.where('fin_entity_id', id);
};
TravelLogDB.deleteQuestionnaireAnswers = function(knex, answerIds) {
this.log.logArguments({answerIds});
return knex('questionnaire_answer')
.del()
.whereIn('id', answerIds);
};
TravelLogDB.deleteEntityAnswers = async function(knex, id) {
this.log.logArguments({id});
const answerIds = await TravelLogDB.getQuestionnaireAnswerIds(knex, id);
await TravelLogDB.deleteFinEntityAnswers(knex, id);
return await TravelLogDB.deleteQuestionnaireAnswers(knex, answerIds);
};
TravelLogDB.getEntityFiles = function(knex, id) {
this.log.logArguments({id});
return knex('file')
.select('id', 'key')
.where({
......@@ -324,6 +356,8 @@ TravelLogDB.getEntityFiles = function(knex, id) {
};
TravelLogDB.deleteDbFiles = function(knex, id) {
this.log.logArguments({id});
return knex('file')
.del()
.where({
......@@ -349,12 +383,16 @@ TravelLogDB.deleteFileData = function(dbInfo, files) {
};
TravelLogDB.deleteEntityFiles = async function(knex, dbInfo, id) {
this.log.logArguments({id});
const files = await TravelLogDB.getEntityFiles(knex, id);
await TravelLogDB.deleteDbFiles(knex, id);
return await TravelLogDB.deleteFileData(dbInfo, files);
};
TravelLogDB.deleteEntity = function(knex, id) {
this.log.logArguments({id});
return knex('fin_entity')
.del()
.where('id', id);
......@@ -365,6 +403,8 @@ TravelLogDB.deleteEntityIfAllRelationshipsAreDeleted = async function(
knex,
entityId
) {
this.log.logArguments({entityId});
const row = await knex('relationship')
.first('id')
.where('fin_entity_id', entityId);
......@@ -377,6 +417,8 @@ TravelLogDB.deleteEntityIfAllRelationshipsAreDeleted = async function(
};
TravelLogDB.deleteTravelLogEntry = async function(dbInfo, knex, id, userInfo) {
this.log.logArguments({id});
const isAllowed = await CommonDB.verifyRelationshipIsUsers(
knex,
userInfo.schoolId,
......@@ -400,6 +442,8 @@ TravelLogDB.deleteTravelLogEntry = async function(dbInfo, knex, id, userInfo) {
};
TravelLogDB.createTravelRelationshipFromEntry = function(entry) {
this.log.logArguments({entry});
const travelRelationship = {};
if (entry.amount) {
travelRelationship.amount = entry.amount;
......@@ -424,6 +468,8 @@ TravelLogDB.createTravelRelationshipFromEntry = function(entry) {
};
TravelLogDB.createRelationshipFromEntry = function(entry) {
this.log.logArguments({entry});
const relationship = {};
if (entry.active !== undefined) {
relationship.active = entry.active;
......@@ -432,6 +478,8 @@ TravelLogDB.createRelationshipFromEntry = function(entry) {
};
TravelLogDB.updateTravelRelationship = function(knex, entry, id) {
this.log.logArguments({entry, id});
const travelRelationship = TravelLogDB.createTravelRelationshipFromEntry(
entry
);
......@@ -445,6 +493,8 @@ TravelLogDB.updateTravelRelationship = function(knex, entry, id) {
};
TravelLogDB.updateRelationship = function(knex, entry, id) {
this.log.logArguments({entry, id});
const relationship = TravelLogDB.createRelationshipFromEntry(entry);
if (Object.keys(relationship).length > 0) {
return knex('relationship')
......@@ -456,6 +506,8 @@ TravelLogDB.updateRelationship = function(knex, entry, id) {
};
TravelLogDB.handleOldEntity = function(knex, dbInfo, entityId) {
this.log.logArguments({entityId});
return TravelLogDB.deleteEntityIfAllRelationshipsAreDeleted(
dbInfo,
knex,
......@@ -464,6 +516,8 @@ TravelLogDB.handleOldEntity = function(knex, dbInfo, entityId) {
};
TravelLogDB.getEntityNameFromId = async function(knex, id) {
this.log.logArguments({id});
const entity = await knex('fin_entity')
.first('name')
.where('id', id);
......@@ -471,6 +525,8 @@ TravelLogDB.getEntityNameFromId = async function(knex, id) {
};
TravelLogDB.getEntityIdFromName = async function(knex, name, disclosureId) {
this.log.logArguments({name, disclosureId});
const entity = await knex('fin_entity')
.first('id')
.where({
......@@ -486,18 +542,24 @@ TravelLogDB.getEntityIdFromName = async function(knex, name, disclosureId) {
};
TravelLogDB.getRelationship = function(knex, id) {
this.log.logArguments({id});
return knex('relationship')
.first('fin_entity_id')
.where('id', id);
};
TravelLogDB.updateRelationshipEntityId = function(knex, id, entityId) {
this.log.logArguments({id, entityId});
return knex('relationship')
.update({fin_entity_id: entityId})
.where('id', id);
};
TravelLogDB.updateEntity = async function(knex, dbInfo, entry, id, schoolId) {
this.log.logArguments({entry, id, schoolId});
const relationship = await TravelLogDB.getRelationship(knex, id);
const entityName = await TravelLogDB.getEntityNameFromId(
......@@ -547,6 +609,8 @@ TravelLogDB.updateTravelLogEntry = async function(
id,
userInfo
) {
this.log.logArguments({entry, id});
const isAllowed = await CommonDB.verifyRelationshipIsUsers(
knex,
userInfo.schoolId,
......
......@@ -27,7 +27,6 @@ debug.formatArgs = function(...originalArgs) {
const c = this.color;
args[0] = `${new Date().toISOString()} \u001b[3${c};1m${this.namespace} \u001b[0m${args[0]}`;
args.push(`\u001b[3${c}m+${debug.humanize(this.diff)}\u001b[0m`);
} else {
args[0] = `${new Date().toISOString()} ${this.namespace} ${args[0]}`;
}
......@@ -102,6 +101,7 @@ export function createLogger(loggerName) {
log.logArguments = (functionName, parameters) => {
logger(`${functionName}`);
logger('ARGUMENTS:');
for (const param in parameters) {
logger(`\t${param} =`);
logger(`\t\t${JSON.stringify(parameters[param])}`);
......@@ -130,7 +130,7 @@ function createContext(moduleName, functionName) {
if (logLevel <= LOG_LEVEL.VERBOSE) {
context.log.logArguments = (parameters) => {
context.log.logger(`${functionName}`);
context.log.logger('ARGUMENTS:');
for (const param in parameters) {
context.log.logger(`\t${param} =`);
context.log.logger(`\t\t${JSON.stringify(parameters[param])}`);
......@@ -159,7 +159,7 @@ export function addLoggers(container) {
result = container[moduleName][`__${functionName}`].apply(context, args);
}
context.log.verbose(
`Completed ${moduleName}:${functionName} in ${Date.now() - startTime} millis`
`Completed ${moduleName}:${functionName} in ${Date.now() - startTime}ms`
);
return result;
};
......
......@@ -49,6 +49,8 @@ const END_POINTS = {
};
async function isUserInRole(researchCoreUrl, role, schoolId, authToken) {
log.logArguments('isUserInRole', {role, schoolId});
try {
const response = await request.get(`${researchCoreUrl}/research-sys/api/v1/roles/${role}/principals/${schoolId}?qualification=unitNumber:*`)
.set('Authorization', `Bearer ${authToken}`);
......@@ -64,6 +66,8 @@ async function isUserInRole(researchCoreUrl, role, schoolId, authToken) {
}
async function getUserRoles(dbInfo, schoolId, authToken) {
log.logArguments('getUserRoles', {schoolId});
const authInfo = getAuthorizationInfo(dbInfo);
const isAdmin = await isUserInRole(authInfo.researchCoreUrl, authInfo.adminRole, schoolId, authToken);
if (isAdmin) {
......@@ -127,6 +131,8 @@ export async function getUserInfo(dbInfo, hostname, authToken) {
will need to further filter once returned.
*/
export async function getUserInfosByQuery(dbInfo, hostname, authToken, queryValue) {
log.logArguments('getUserInfosByQuery', {queryValue});
try {
const cachedUserInfo = queryValue ? cache.get(queryValue) : undefined;
if (cachedUserInfo) {
......@@ -156,16 +162,22 @@ export function getAuthLink(req) {
}
export async function getReviewers(dbInfo, authToken, unit) {
log.logArguments('getReviewers', {unit});
const authInfo = getAuthorizationInfo(dbInfo);
return await getUsersInRole(authInfo.researchCoreUrl, authToken, authInfo.reviewerRole, REVIEWER_CACHE_KEY, unit);
}
export async function getAdmins(dbInfo, authToken, unit) {
log.logArguments('getAdmins', {unit});
const authInfo = getAuthorizationInfo(dbInfo);
return await getUsersInRole(authInfo.researchCoreUrl, authToken, authInfo.adminRole, ADMIN_CACHE_KEY, unit);
}
export async function getUsersInRole(url, authToken, role, cacheKey, unit) {
log.logArguments('getUsersInRole', {role, cacheKey, unit});
try {
const query = {};
......
......@@ -36,6 +36,8 @@ catch (err) {
}
export async function getFileStream(dbInfo, key) {
log.logArguments('getFileStream', {key});
if (!client) {
log.error('No file service configured');
return;
......@@ -44,6 +46,8 @@ export async function getFileStream(dbInfo, key) {
}
export function deleteFile(dbInfo, key, callback) {
log.logArguments('deleteFile', {key});
if (!client) {
log.error('No file service configured');
return;
......
......@@ -18,6 +18,8 @@
import fs from 'fs';
import path from 'path';
import {createLogger} from '../../log';
const log = createLogger('FileService');
const filePath = process.env.LOCAL_FILE_DESTINATION || 'uploads/';
......@@ -34,6 +36,8 @@ function canReadFile(fileName) {
}
export async function getFileStream(dbInfo, key) {
log.logArguments('getFileStream', {key});
const fileName = path.join(filePath, cleanKey(key));
const canRead = await canReadFile(fileName);
if (canRead === false) {
......@@ -44,6 +48,8 @@ export async function getFileStream(dbInfo, key) {
}
export function deleteFile(dbInfo, key, callback) {
log.logArguments('deleteFile', {key});
fs.unlink(path.join(filePath, cleanKey(key)), err => {
callback(err);
});
......
......@@ -98,6 +98,8 @@ export function getRequestInfo(dbInfo, hostname) {
}
function createCoreTemplate(notificationTemplate, hostname, applicationId) {
log.logArguments('createCoreTemplate', {notificationTemplate, applicationId});
return {
applicationId,
displayName: createDisplayName(hostname, notificationTemplate.description),
......@@ -120,6 +122,8 @@ export async function updateTemplateData(
hostname,
notificationTemplate
) {
log.logArguments('updateTemplateData', {notificationTemplate});
const requestInfo = getRequestInfo(dbInfo, hostname);
const template = createCoreTemplate(
notificationTemplate,
......@@ -137,6 +141,8 @@ export async function createNewTemplate(
hostname,
notificationTemplate
) {
log.logArguments('createNewTemplate', {notificationTemplate});
const requestInfo = getRequestInfo(dbInfo, hostname);
const coreTemplate = createCoreTemplate(
notificationTemplate,
......@@ -152,6 +158,8 @@ export async function createNewTemplate(
}
export async function getUserInfo(dbInfo, hostname, userId) {
log.logArguments('getUserInfo', {userId});
const notificationsInfo = getNotificationsInfo(dbInfo);
const userInfos = await getUserInfosByQuery(
dbInfo,
......@@ -180,8 +188,8 @@ export async function getAdminRecipients(dbInfo, authHeader) {
export async function sendNotification(dbInfo, hostname, notification) {
const requestInfo = getRequestInfo(dbInfo, hostname);
log.info('Requesting notification be sent:');
log.info(JSON.stringify(notification));
log.logValue('Requesting notification be sent:', notification);
let response;
try {
response = await request
......@@ -220,6 +228,8 @@ export async function sendNotification(dbInfo, hostname, notification) {
}
async function checkStatuses(dbInfo, hostname, receiptIds) {
log.logArguments('checkStatuses', {receiptIds});
for (const receiptId of receiptIds) {
const detail = await getNotificationReceiptDetail(
dbInfo,
......@@ -240,6 +250,7 @@ async function checkStatuses(dbInfo, hostname, receiptIds) {
async function recordNotificationRequest(knex, addresses, receiptIds) {
log.logArguments('recordNotificationRequest', {addresses, receiptIds});
await knex('notification_request')
.insert({
timestamp: new Date(),
......@@ -249,6 +260,8 @@ async function recordNotificationRequest(knex, addresses, receiptIds) {
}
export async function getNotificationReceiptDetail(dbInfo, hostname, id) {
log.logArguments('getNotificationReceiptDetail', {id});
const requestInfo = getRequestInfo(dbInfo, hostname);
let response;
......
......@@ -108,6 +108,8 @@ const TEMPLATES = {
};
export function getDefaults(notificationTemplate) {
log.logArguments('getDefaults', {notificationTemplate});