Skip to content

Commit

Permalink
[TECH] Migration de la route de dépublication de session (PIX-15676).
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Dec 12, 2024
2 parents 79e7b29 + 9493eec commit 1a587cd
Show file tree
Hide file tree
Showing 21 changed files with 491 additions and 446 deletions.
28 changes: 0 additions & 28 deletions api/lib/application/sessions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,34 +69,6 @@ const register = async function (server) {
tags: ['api', 'session', 'publication'],
},
},
{
method: 'PATCH',
path: '/api/admin/sessions/{id}/unpublish',
config: {
validate: {
params: Joi.object({
id: identifiersType.sessionId,
}),
},
pre: [
{
method: (request, h) =>
securityPreHandlers.hasAtLeastOneAccessOf([
securityPreHandlers.checkAdminMemberHasRoleSuperAdmin,
securityPreHandlers.checkAdminMemberHasRoleCertif,
securityPreHandlers.checkAdminMemberHasRoleSupport,
])(request, h),
assign: 'hasAuthorizationToAccessAdminScope',
},
],
handler: sessionController.unpublish,
notes: [
'- **Cette route est restreinte aux utilisateurs authentifiés**\n' +
"- Dépublie toutes les certifications courses d'une session",
],
tags: ['api', 'session', 'publication'],
},
},
]);
};

Expand Down
10 changes: 0 additions & 10 deletions api/lib/application/sessions/session-controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as juryCertificationSummaryRepository from '../../../src/certification/session-management/infrastructure/repositories/jury-certification-summary-repository.js';
import * as sessionManagementSerializer from '../../../src/certification/session-management/infrastructure/serializers/session-serializer.js';
import { SessionPublicationBatchError } from '../../../src/shared/application/http-errors.js';
import { logger } from '../../../src/shared/infrastructure/utils/logger.js';
import { usecases } from '../../domain/usecases/index.js';
Expand Down Expand Up @@ -39,18 +38,9 @@ const publishInBatch = async function (request, h) {
return h.response().code(204);
};

const unpublish = async function (request, h, dependencies = { sessionManagementSerializer }) {
const sessionId = request.params.id;

const session = await usecases.unpublishSession({ sessionId });

return dependencies.sessionManagementSerializer.serialize({ session });
};

const sessionController = {
getJuryCertificationSummaries,
publishInBatch,
unpublish,
};

export { sessionController };
Expand Down
2 changes: 0 additions & 2 deletions api/lib/domain/usecases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ import * as badgeForCalculationRepository from '../../infrastructure/repositorie
import { campaignParticipationResultRepository } from '../../infrastructure/repositories/campaign-participation-result-repository.js';
import * as campaignRepository from '../../infrastructure/repositories/campaign-repository.js';
import * as certifiableProfileForLearningContentRepository from '../../infrastructure/repositories/certifiable-profile-for-learning-content-repository.js';
import * as certificationRepository from '../../infrastructure/repositories/certification-repository.js';
import * as complementaryCertificationCourseResultRepository from '../../infrastructure/repositories/complementary-certification-course-result-repository.js';
import * as flashAssessmentResultRepository from '../../infrastructure/repositories/flash-assessment-result-repository.js';
import * as frameworkRepository from '../../infrastructure/repositories/framework-repository.js';
Expand Down Expand Up @@ -235,7 +234,6 @@ const dependencies = {
certificationCourseRepository,
certificationCpfCityRepository,
certificationOfficerRepository,
certificationRepository,
challengeRepository,
codeGenerator,
codeUtils,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ const publish = async function (request, h, dependencies = { sessionManagementSe
return dependencies.sessionManagementSerializer.serialize({ session });
};

const unpublish = async function (request, h, dependencies = { sessionManagementSerializer }) {
const sessionId = request.params.sessionId;

const session = await usecases.unpublishSession({ sessionId });

return dependencies.sessionManagementSerializer.serialize({ session });
};

export const sessionPublicationController = {
publish,
unpublish,
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,34 @@ const register = async function (server) {
tags: ['api', 'session', 'publication'],
},
},
{
method: 'PATCH',
path: '/api/admin/sessions/{sessionId}/unpublish',
config: {
validate: {
params: Joi.object({
sessionId: identifiersType.sessionId,
}),
},
pre: [
{
method: (request, h) =>
securityPreHandlers.hasAtLeastOneAccessOf([
securityPreHandlers.checkAdminMemberHasRoleSuperAdmin,
securityPreHandlers.checkAdminMemberHasRoleCertif,
securityPreHandlers.checkAdminMemberHasRoleSupport,
])(request, h),
assign: 'hasAuthorizationToAccessAdminScope',
},
],
handler: sessionPublicationController.unpublish,
notes: [
'- **Cette route est restreinte aux utilisateurs authentifiés**\n' +
"- Dépublie toutes les certifications courses d'une session",
],
tags: ['api', 'session', 'publication'],
},
},
]);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import lodash from 'lodash';

import * as mailService from '../../../../../src/certification/session-management/domain/services/mail-service.js';
import { mailService } from '../../../../../src/certification/session-management/domain/services/mail-service.js';
import {
CertificationCourseNotPublishableError,
SendingEmailToRefererError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { injectDependencies } from '../../../../shared/infrastructure/utils/depe
import { importNamedExportsFromDirectory } from '../../../../shared/infrastructure/utils/import-named-exports-from-directory.js';
import * as certificationBadgesService from '../../../shared/domain/services/certification-badges-service.js';
import * as certificationCpfService from '../../../shared/domain/services/certification-cpf-service.js';
import * as certificationCenterRepository from '../../../shared/infrastructure/repositories/certification-center-repository.js';
import * as sharedSessionRepository from '../../../shared/infrastructure/repositories/session-repository.js';
import {
answerRepository,
Expand All @@ -33,6 +34,7 @@ import * as sessionPublicationService from '../services/session-publication-serv
* @typedef {import('../../infrastructure/repositories/index.js').FinalizedSessionRepository} FinalizedSessionRepository
* @typedef {import('../../infrastructure/repositories/index.js').JuryCertificationSummaryRepository} JuryCertificationSummaryRepository
* @typedef {import('../../infrastructure/repositories/index.js').SupervisorAccessRepository} SupervisorAccessRepository
* @typedef {import('../../../../shared/infrastructure/repositories/index.js').CertificationCenterRepository} CertificationCenterRepository
* @typedef {import('../../infrastructure/repositories/index.js').CertificationOfficerRepository} CertificationOfficerRepository
* @typedef {import('../../infrastructure/repositories/index.js').CertificationIssueReportRepository} CertificationIssueReportRepository
* @typedef {import('../../infrastructure/repositories/index.js').FinalizedSessionRepository} FinalizedSessionRepository
Expand Down Expand Up @@ -76,6 +78,7 @@ import * as sessionPublicationService from '../services/session-publication-serv
* @typedef {assessmentResultRepository} AssessmentResultRepository
* @typedef {certificationAssessmentRepository} CertificationAssessmentRepository
* @typedef {certificationBadgesService} CertificationBadgesService
* @typedef {certificationCenterRepository} CertificationCenterRepository
* @typedef {certificationIssueReportRepository} CertificationIssueReportRepository
* @typedef {competenceMarkRepository} CompetenceMarkRepository
* @typedef {certificationCourseRepository} CertificationCourseRepository
Expand Down Expand Up @@ -123,6 +126,7 @@ const dependencies = {
certificationBadgesService,
placementProfileService,
certificationCpfService,
certificationCenterRepository,
certificationChallengeRepository,
certificationRepository,
certificationIssueReportRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const unpublishSession = async function ({
}) {
const session = await sharedSessionRepository.getWithCertificationCandidates({ id: sessionId });

await certificationRepository.unpublishCertificationCoursesBySessionId(sessionId);
await certificationRepository.unpublishCertificationCoursesBySessionId({ sessionId });

session.publishedAt = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ const publishCertificationCourses = async function (certificationStatuses) {
.merge(['isPublished', 'updatedAt']);
};

export { getStatusesBySessionId, publishCertificationCourses };
const unpublishCertificationCoursesBySessionId = async function ({ sessionId }) {
await knex('certification-courses').where({ sessionId }).update({ isPublished: false, updatedAt: new Date() });
};

export { getStatusesBySessionId, publishCertificationCourses, unpublishCertificationCoursesBySessionId };

This file was deleted.

Loading

0 comments on commit 1a587cd

Please sign in to comment.