Skip to content

Commit

Permalink
[FEATURE] Conditionner l'affichage du bloc en fonction de si la compl…
Browse files Browse the repository at this point in the history
…émentaire sélectionnée possède un référentiel externe (PIX-12215)

 #8829
  • Loading branch information
pix-service-auto-merge committed May 13, 2024
2 parents 644712c + 6951f32 commit 2a3c1c6
Show file tree
Hide file tree
Showing 19 changed files with 405 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ async function _findAllowedCertificationCenterAccesses(certificationCenterIds) {
isRelatedToManagingStudentsOrganization: 'organizations.isManagingStudents',
tags: knex.raw('array_agg(?? order by ??)', ['tags.name', 'tags.name']),
habilitations: knex.raw(
`array_agg(json_build_object('id', "complementary-certifications".id, 'label', "complementary-certifications".label, 'key', "complementary-certifications".key) order by "complementary-certifications".id)`,
`array_agg(json_build_object(
'id', "complementary-certifications".id,
'label', "complementary-certifications".label,
'key', "complementary-certifications".key,
'hasComplementaryReferential', "complementary-certifications"."hasComplementaryReferential"
) order by "complementary-certifications".id)`,
),
isV3Pilot: 'certification-centers.isV3Pilot',
isComplementaryAlonePilot: knex.raw(
Expand Down Expand Up @@ -123,6 +128,21 @@ async function _findAllowedCertificationCenterAccesses(certificationCenterIds) {
.orderBy('certification-centers.id')
.groupBy('certification-centers.id', 'organizations.isManagingStudents');

return _toDomain(allowedCertificationCenterAccessDTOs);
}

function _cleanTags(allowedCertificationCenterAccessDTO) {
return _(allowedCertificationCenterAccessDTO.tags).compact().uniq().value();
}

function _cleanHabilitations(allowedCertificationCenterAccessDTO) {
return _(allowedCertificationCenterAccessDTO.habilitations)
.filter((habilitation) => habilitation.id > 0)
.uniqBy('id')
.value();
}

function _toDomain(allowedCertificationCenterAccessDTOs) {
return _.map(allowedCertificationCenterAccessDTOs, (allowedCertificationCenterAccessDTO) => {
return new AllowedCertificationCenterAccess({
...allowedCertificationCenterAccessDTO,
Expand All @@ -133,17 +153,6 @@ async function _findAllowedCertificationCenterAccesses(certificationCenterIds) {
habilitations: _cleanHabilitations(allowedCertificationCenterAccessDTO),
});
});

function _cleanTags(allowedCertificationCenterAccessDTO) {
return _(allowedCertificationCenterAccessDTO.tags).compact().uniq().value();
}

function _cleanHabilitations(allowedCertificationCenterAccessDTO) {
return _(allowedCertificationCenterAccessDTO.habilitations)
.filter((habilitation) => Boolean(habilitation.id))
.uniqBy('id')
.value();
}
}

async function _findNotDisabledCertificationCenterMemberships(userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ const serialize = function (certificationPointOfContact) {
(access) => {
return {
...access,
habilitations: access.habilitations,
habilitations: access.habilitations.map(({ id, label, key, hasComplementaryReferential }) => ({
id,
label,
key,
hasComplementaryReferential,
})),
isAccessBlockedCollege: access.isAccessBlockedCollege(),
isAccessBlockedLycee: access.isAccessBlockedLycee(),
isAccessBlockedAEFE: access.isAccessBlockedAEFE(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ describe('Acceptance | Route | CertificationPointOfContact', function () {
userId,
certificationCenterId,
}).id;
const complementaryCertification = databaseBuilder.factory.buildComplementaryCertification({
hasComplementaryReferential: true,
});
databaseBuilder.factory.buildComplementaryCertificationHabilitation({
certificationCenterId,
complementaryCertificationId: complementaryCertification.id,
});

// Pilot complementary
const certificationCenterComplementaryAlonePilotId = databaseBuilder.factory.buildCertificationCenter({
Expand Down Expand Up @@ -74,7 +81,14 @@ describe('Acceptance | Route | CertificationPointOfContact', function () {
{
attributes: {
'external-id': 'EX123',
habilitations: [],
habilitations: [
{
id: complementaryCertification.id,
label: complementaryCertification.label,
key: complementaryCertification.key,
hasComplementaryReferential: true,
},
],
'is-access-blocked-aefe': false,
'is-access-blocked-agri': false,
'is-access-blocked-college': false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,12 @@ describe('Integration | Repository | CertificationPointOfContact', function () {
it('should return all the certification center habilitations', async function () {
// given
databaseBuilder.factory.buildComplementaryCertification({ id: 1, label: 'Certif comp 1', key: 'COMP_1' });
databaseBuilder.factory.buildComplementaryCertification({ id: 2, label: 'Certif comp 2', key: 'COMP_2' });
databaseBuilder.factory.buildComplementaryCertification({
id: 2,
label: 'Certif comp 2',
key: 'COMP_2',
hasComplementaryReferential: true,
});
databaseBuilder.factory.buildComplementaryCertification({ id: 3, label: 'Certif comp 3', key: 'COMP_3' });
databaseBuilder.factory.buildCertificationCenter({
id: 1,
Expand Down Expand Up @@ -351,8 +356,8 @@ describe('Integration | Repository | CertificationPointOfContact', function () {
isV3Pilot: true,
relatedOrganizationTags: [],
habilitations: [
{ id: 1, label: 'Certif comp 1', key: 'COMP_1' },
{ id: 2, label: 'Certif comp 2', key: 'COMP_2' },
{ id: 1, label: 'Certif comp 1', key: 'COMP_1', hasComplementaryReferential: false },
{ id: 2, label: 'Certif comp 2', key: 'COMP_2', hasComplementaryReferential: true },
],
});
const expectedSecondAllowedCertificationCenterAccess = domainBuilder.buildAllowedCertificationCenterAccess({
Expand All @@ -363,7 +368,7 @@ describe('Integration | Repository | CertificationPointOfContact', function () {
isRelatedToManagingStudentsOrganization: false,
isV3Pilot: true,
relatedOrganizationTags: [],
habilitations: [{ id: 3, label: 'Certif comp 3', key: 'COMP_3' }],
habilitations: [{ id: 3, label: 'Certif comp 3', key: 'COMP_3', hasComplementaryReferential: false }],
});

const expectedCertificationPointOfContact = domainBuilder.buildCertificationPointOfContact({
Expand All @@ -387,7 +392,12 @@ describe('Integration | Repository | CertificationPointOfContact', function () {
it('should return the certification point of contact with tags and habilitations', async function () {
// given
databaseBuilder.factory.buildComplementaryCertification({ id: 1, label: 'Certif comp 1', key: 'COMP_1' });
databaseBuilder.factory.buildComplementaryCertification({ id: 2, label: 'Certif comp 2', key: 'COMP_2' });
databaseBuilder.factory.buildComplementaryCertification({
id: 2,
label: 'Certif comp 2',
key: 'COMP_2',
hasComplementaryReferential: true,
});
databaseBuilder.factory.buildCertificationCenter({
id: 1,
name: 'Centre de certif',
Expand Down Expand Up @@ -459,8 +469,8 @@ describe('Integration | Repository | CertificationPointOfContact', function () {
isRelatedToManagingStudentsOrganization: false,
relatedOrganizationTags: ['tag1', 'tag2'],
habilitations: [
{ id: 1, label: 'Certif comp 1', key: 'COMP_1' },
{ id: 2, label: 'Certif comp 2', key: 'COMP_2' },
{ id: 1, label: 'Certif comp 1', key: 'COMP_1', hasComplementaryReferential: false },
{ id: 2, label: 'Certif comp 2', key: 'COMP_2', hasComplementaryReferential: true },
],
});
const expectedCertificationPointOfContact = domainBuilder.buildCertificationPointOfContact({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ describe('Unit | Serializer | JSONAPI | certification-point-of-contact-serialize
describe('#serialize()', function () {
it('should convert a CertificationPointOfContact model into JSON API data', function () {
// given
const habilitation1 = { id: 1, label: 'Certif comp 1', key: 'CERTIF_COMP_1', hasComplementaryReferential: true };
const habilitation2 = { id: 2, label: 'Certif comp 2', key: 'CERTIF_COMP_2', hasComplementaryReferential: true };
sinon.stub(settings.features, 'pixCertifScoBlockedAccessDateCollege').value('2022-06-01');
sinon.stub(settings.features, 'pixCertifScoBlockedAccessDateLycee').value('2022-08-01');

Expand All @@ -19,10 +21,7 @@ describe('Unit | Serializer | JSONAPI | certification-point-of-contact-serialize
isRelatedToManagingStudentsOrganization: false,
isV3Pilot: false,
relatedOrganizationTags: [],
habilitations: [
{ id: 1, name: 'Certif comp 1' },
{ id: 2, name: 'Certif comp 2' },
],
habilitations: [habilitation1, habilitation2],
});

const allowedCertificationCenterAccess2 = domainBuilder.buildAllowedCertificationCenterAccess({
Expand Down Expand Up @@ -121,10 +120,7 @@ describe('Unit | Serializer | JSONAPI | certification-point-of-contact-serialize
'pix-certif-sco-blocked-access-date-college': '2022-06-01',
'pix-certif-sco-blocked-access-date-lycee': '2022-08-01',
'related-organization-tags': [],
habilitations: [
{ id: 1, name: 'Certif comp 1' },
{ id: 2, name: 'Certif comp 2' },
],
habilitations: [habilitation1, habilitation2],
},
},
{
Expand Down
33 changes: 0 additions & 33 deletions certif/app/components/complementary-certification-options.hbs

This file was deleted.

9 changes: 0 additions & 9 deletions certif/app/components/complementary-certification-options.js

This file was deleted.

8 changes: 4 additions & 4 deletions certif/app/components/enrolled-candidates.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PixButton
id="add-candidate"
class="certification-candidates-add-button__text"
@triggerAction={{this.openNewCertificationCandidateModal}}
@triggerAction={{this.openNewCandidateModal}}
@size="small"
>
{{t "pages.sessions.detail.candidates.list.actions.inscription.label"}}
Expand Down Expand Up @@ -172,9 +172,9 @@
/>
{{/if}}

<NewCertificationCandidateModal
@showModal={{this.showNewCertificationCandidateModal}}
@closeModal={{this.closeNewCertificationCandidateModal}}
<NewCandidateModal
@showModal={{this.showNewCandidateModal}}
@closeModal={{this.closeNewCandidateModal}}
@countries={{@countries}}
@saveCandidate={{this.addCertificationCandidate}}
@candidateData={{this.newCandidate}}
Expand Down
12 changes: 6 additions & 6 deletions certif/app/components/enrolled-candidates.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class EnrolledCandidates extends Component {
@tracked newCandidate = {};
@tracked shouldDisplayCertificationCandidateModal = false;
@tracked certificationCandidateInDetailsModal = null;
@tracked showNewCertificationCandidateModal = false;
@tracked showNewCandidateModal = false;

@action
async deleteCertificationCandidate(certificationCandidate) {
Expand Down Expand Up @@ -67,7 +67,7 @@ export default class EnrolledCandidates extends Component {
const success = await this.saveCertificationCandidate(certificationCandidate);
if (success) {
this.candidatesInStaging.removeObject(candidate);
this.closeNewCertificationCandidateModal();
this.closeNewCandidateModal();
}
return success;
}
Expand Down Expand Up @@ -133,14 +133,14 @@ export default class EnrolledCandidates extends Component {
}

@action
openNewCertificationCandidateModal() {
openNewCandidateModal() {
this.addCertificationCandidateInStaging();
this.showNewCertificationCandidateModal = true;
this.showNewCandidateModal = true;
}

@action
closeNewCertificationCandidateModal() {
this.showNewCertificationCandidateModal = false;
closeNewCandidateModal() {
this.showNewCandidateModal = false;
}

_createCertificationCandidateRecord(certificationCandidateData) {
Expand Down
18 changes: 18 additions & 0 deletions certif/app/components/new-candidate-modal/complementary-list.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="new-candidate-modal-form__field">
<fieldset id="complementary-certifications">
<legend class="label">
{{t "common.forms.certification-labels.additional-certification"}}
</legend>
<PixRadioButton name="complementary-certifications" {{on "change" (fn @updateComplementaryCertification null)}}>
<:label>{{t "common.labels.candidate.none"}}</:label>
</PixRadioButton>
{{#each @complementaryCertificationsHabilitations as |complementaryCertificationHabilitation|}}
<PixRadioButton
name="complementary-certifications"
{{on "change" (fn @updateComplementaryCertification complementaryCertificationHabilitation)}}
>
<:label>{{complementaryCertificationHabilitation.label}}</:label>
</PixRadioButton>
{{/each}}
</fieldset>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="new-candidate-modal-form__field">
<fieldset id="is-complementary-alone">
<legend class="label">
{{t "common.forms.certification-labels.complementary-alone"}}
</legend>
<PixRadioButton name="complementary-alone">
<:label>{{t "common.labels.complementary-alone.pix-plus"}}</:label>
</PixRadioButton>
<PixRadioButton name="complementary-alone">
<:label>{{t "common.labels.complementary-alone.pix-and-pix-plus"}}</:label>
</PixRadioButton>
</fieldset>
</div>
Loading

0 comments on commit 2a3c1c6

Please sign in to comment.