Skip to content

Commit

Permalink
Merge branch 'release/4.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
oxypomme committed Aug 9, 2024
2 parents 4fba3e2 + b71161a commit d99681f
Show file tree
Hide file tree
Showing 46 changed files with 1,671 additions and 408 deletions.
4 changes: 3 additions & 1 deletion api/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"password": "KIBANA_PASSWORD",
"port": "EZMESURE_KIBANA_PORT",
"host": "EZMESURE_KIBANA_HOST",
"dateFormat": "EZMESURE_KIBANA_DATE_FORMAT",
"syncSchedule": "EZMESURE_KIBANA_SYNC_SCHEDULE"
},
"redis": {
Expand Down Expand Up @@ -61,7 +62,8 @@
"concurrency": "EZMESURE_HARVEST_CONCURRENCY",
"maxDeferrals": "EZMESURE_MAX_DEFERRALS",
"deferralBackoffDuration": "EZMESURE_DEFERRAL_BACKOFF_DURATION",
"busyBackoffDuration": "EZMESURE_BUSY_BACKOFF_DURATION"
"busyBackoffDuration": "EZMESURE_BUSY_BACKOFF_DURATION",
"cancelSchedule": "EZMESURE_HARVEST_CANCEL_SCHEDULE"
}
},
"counter": {
Expand Down
2 changes: 2 additions & 0 deletions api/config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
password: 'changeme',
port: 5601,
host: 'localhost',
dateFormat: 'DD MMM YYYY',
syncSchedule: '0 0 0 * * *',
},
redis: {
Expand Down Expand Up @@ -77,6 +78,7 @@ module.exports = {
maxDeferrals: 5,
deferralBackoffDuration: 10 * oneMinute,
busyBackoffDuration: 10 * oneMinute,
cancelSchedule: '0 0 0 * * *',
},
},
counter: {
Expand Down
7 changes: 4 additions & 3 deletions api/lib/controllers/files/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ function validateFile(filePath, $t) {

exports.upload = async function upload(ctx) {
let { fileName } = ctx.request.params;
const { user } = ctx.state;

ctx.action = 'file/upload';

Expand All @@ -93,7 +94,6 @@ exports.upload = async function upload(ctx) {

fileName = fileName.replace(/\s/g, '_');

const { user } = ctx.state;
const domain = user.email.split('@')[1];

const relativePath = path.join(domain, user.username, fileName);
Expand All @@ -117,9 +117,10 @@ exports.upload = async function upload(ctx) {
if (result instanceof Error) {
await fse.unlink(filePath);
ctx.throw(400, result.message);
} else {
ctx.status = 204;
return;
}

ctx.status = 204;
};

exports.list = async function list(ctx) {
Expand Down
43 changes: 43 additions & 0 deletions api/lib/controllers/institutions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,49 @@ exports.updateInstitution = async (ctx) => {
ctx.body = updatedInstitution;
};

exports.updateInstitutionSushiReady = async (ctx) => {
ctx.action = 'institutions/update';
const { institution } = ctx.state;
const { body } = ctx.request;

const origin = ctx.get('origin');

const wasSushiReady = institution.sushiReadySince;

ctx.metadata = {
institutionId: institution.id,
institutionName: institution.name,
};

const updatedInstitution = await (new InstitutionsService()).update({
where: { id: institution.id },
data: { sushiReadySince: body.value },
});
appLogger.verbose(`Institution [${institution.id}] is updated`);

const { sushiReadySince } = updatedInstitution;
const sushiReadyChanged = (wasSushiReady && sushiReadySince === null)
|| (!wasSushiReady && sushiReadySince);

if (sushiReadyChanged) {
sendMail({
from: sender,
to: supportRecipients,
subject: sushiReadySince ? 'Fin de saisie SUSHI' : 'Reprise de saisie SUSHI',
...generateMail('sushi-ready-change', {
institutionName: institution.name,
institutionSushiLink: `${origin}/institutions/${institution.id}/sushi`,
sushiReadySince,
}),
}).catch((err) => {
appLogger.error(`Failed to send sushi-ready-change mail: ${err}`);
});
}

ctx.status = 200;
ctx.body = updatedInstitution;
};

exports.importInstitutions = async (ctx) => {
ctx.action = 'institutions/import';
const { body = [] } = ctx.request;
Expand Down
22 changes: 0 additions & 22 deletions api/lib/controllers/institutions/admin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const config = require('config');
const kibana = require('../../services/kibana');

const { sendMail, generateMail } = require('../../services/mail');

Expand All @@ -22,27 +21,6 @@ function sendValidateInstitution(receivers) {
});
}

exports.getInstitutionState = async (ctx) => {
const { institution } = ctx.state;

const spaces = await institution.getSpaces();

const patterns = await Promise.all(
spaces
.filter((space) => space && space.id)
.map((space) => kibana.getIndexPatterns({ spaceId: space.id, perPage: 1000 })),
);

ctx.type = 'json';
ctx.status = 200;
ctx.body = {
spaces,
indices: await institution.getIndices(),
indexPatterns: patterns.reduce((acc, current) => [...acc, ...current], []),
roles: await institution.checkRoles(),
};
};

exports.validateInstitution = async (ctx) => {
const { body = {} } = ctx.request;
const { value: validated } = body;
Expand Down
27 changes: 15 additions & 12 deletions api/lib/controllers/institutions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
importInstitutions,
getInstitution,
updateInstitution,
updateInstitutionSushiReady,
} = require('./actions');

const memberships = require('./memberships');
Expand All @@ -33,10 +34,7 @@ const {
removeSubInstitution,
} = require('./subinstitutions');

const {
getInstitutionState,
validateInstitution,
} = require('./admin');
const { validateInstitution } = require('./admin');

router.use(sushi.prefix('/:institutionId/sushi').middleware());
router.use(repositories.prefix('/:institutionId/repositories').middleware());
Expand Down Expand Up @@ -111,28 +109,33 @@ router.route({
},
});

router.use(requireAdmin);

router.route({
method: 'DELETE',
path: '/:institutionId',
method: 'PUT',
path: '/:institutionId/sushiReadySince',
handler: [
fetchInstitution(),
deleteInstitution,
requireMemberPermissions(FEATURES.sushi.write),
updateInstitutionSushiReady,
],
validate: {
type: 'json',
params: {
institutionId: Joi.string().trim().required(),
},
body: {
value: Joi.date().allow(null),
},
},
});

router.use(requireAdmin);

router.route({
method: 'GET',
path: '/:institutionId/state',
method: 'DELETE',
path: '/:institutionId',
handler: [
fetchInstitution(),
getInstitutionState,
deleteInstitution,
],
validate: {
params: {
Expand Down
1 change: 1 addition & 0 deletions api/lib/controllers/institutions/sushi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ router.route({
query: standardQueryParams.manyValidation,
},
});

module.exports = router;
Loading

0 comments on commit d99681f

Please sign in to comment.