From 29564784b7fe70740fdac322700c5846a1a6d6b4 Mon Sep 17 00:00:00 2001 From: Benjamin Petetot Date: Wed, 8 Jan 2025 15:33:01 +0100 Subject: [PATCH] feat(orga): use pixOrgaTermsOfServiceStatus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Theo Co-authored-by: Jérémy PLUQUET --- orga/app/controllers/terms-of-service.js | 1 + orga/app/models/prescriber.js | 1 + orga/app/models/user.js | 1 + orga/app/routes/authenticated.js | 4 +-- orga/app/routes/terms-of-service.js | 4 +-- orga/mirage/config.js | 2 +- orga/mirage/factories/user.js | 4 +++ orga/tests/acceptance/team-list-test.js | 2 ++ orga/tests/helpers/test-init.js | 26 ++++++++++++++++++-- orga/tests/unit/routes/authenticated-test.js | 6 ++++- 10 files changed, 43 insertions(+), 8 deletions(-) diff --git a/orga/app/controllers/terms-of-service.js b/orga/app/controllers/terms-of-service.js index 27480c6ea59..6d53ca0ef98 100644 --- a/orga/app/controllers/terms-of-service.js +++ b/orga/app/controllers/terms-of-service.js @@ -18,6 +18,7 @@ export default class TermOfServiceController extends Controller { async submit() { await this.currentUser.prescriber.save({ adapterOptions: { acceptPixOrgaTermsOfService: true } }); this.currentUser.prescriber.pixOrgaTermsOfServiceAccepted = true; + this.currentUser.prescriber.pixOrgaTermsOfServiceStatus = 'accepted'; this.router.transitionTo('application'); } } diff --git a/orga/app/models/prescriber.js b/orga/app/models/prescriber.js index 1642a250ab5..4ecefc44163 100644 --- a/orga/app/models/prescriber.js +++ b/orga/app/models/prescriber.js @@ -4,6 +4,7 @@ export default class Prescriber extends Model { @attr('string') firstName; @attr('string') lastName; @attr('boolean') pixOrgaTermsOfServiceAccepted; + @attr('string') pixOrgaTermsOfServiceStatus; @attr('boolean') areNewYearOrganizationLearnersImported; @attr('number') participantCount; @attr('string') lang; diff --git a/orga/app/models/user.js b/orga/app/models/user.js index e35f9299d3a..4628d3e28f8 100644 --- a/orga/app/models/user.js +++ b/orga/app/models/user.js @@ -8,6 +8,7 @@ export default class User extends Model { @attr('string') lang; @attr('boolean') cgu; @attr('boolean') pixOrgaTermsOfServiceAccepted; + @attr('string') pixOrgaTermsOfServiceStatus; @hasMany('membership', { async: true, inverse: 'user' }) memberships; @belongsTo('user-orga-setting', { async: true, inverse: 'user' }) userOrgaSettings; } diff --git a/orga/app/routes/authenticated.js b/orga/app/routes/authenticated.js index de0a9ae83de..1615a3c47e3 100644 --- a/orga/app/routes/authenticated.js +++ b/orga/app/routes/authenticated.js @@ -16,8 +16,8 @@ export default class AuthenticatedRoute extends Route { return; } - const pixOrgaTermsOfServiceAccepted = get(this.currentUser, 'prescriber.pixOrgaTermsOfServiceAccepted'); - if (!pixOrgaTermsOfServiceAccepted) { + const pixOrgaTermsOfServiceStatus = get(this.currentUser, 'prescriber.pixOrgaTermsOfServiceStatus'); + if (pixOrgaTermsOfServiceStatus !== 'accepted') { return this.router.replaceWith('terms-of-service'); } } diff --git a/orga/app/routes/terms-of-service.js b/orga/app/routes/terms-of-service.js index 1cc46471e6a..9119f1b18fd 100644 --- a/orga/app/routes/terms-of-service.js +++ b/orga/app/routes/terms-of-service.js @@ -14,8 +14,8 @@ export default class TermsOfServiceRoute extends Route { return; } - const pixOrgaTermsOfServiceAccepted = get(this.currentUser, 'prescriber.pixOrgaTermsOfServiceAccepted'); - if (pixOrgaTermsOfServiceAccepted) { + const pixOrgaTermsOfServiceStatus = get(this.currentUser, 'prescriber.pixOrgaTermsOfServiceStatus'); + if (pixOrgaTermsOfServiceStatus === 'accepted') { return this.router.replaceWith(''); } } diff --git a/orga/mirage/config.js b/orga/mirage/config.js index f8adab460af..96cbaa0b2c8 100644 --- a/orga/mirage/config.js +++ b/orga/mirage/config.js @@ -87,7 +87,7 @@ function routes() { this.patch('/users/:id/pix-orga-terms-of-service-acceptance', (schema, request) => { const user = schema.users.find(request.params.id); - user.update({ pixOrgaTermsOfServiceAccepted: true }); + user.update({ pixOrgaTermsOfServiceAccepted: true, pixOrgaTermsOfServiceStatus: 'accepted' }); return user; }); diff --git a/orga/mirage/factories/user.js b/orga/mirage/factories/user.js index 1118e9f39ff..6d8754344a7 100644 --- a/orga/mirage/factories/user.js +++ b/orga/mirage/factories/user.js @@ -17,4 +17,8 @@ export default Factory.extend({ pixOrgaTermsOfServiceAccepted() { return faker.datatype.boolean(); }, + + pixOrgaTermsOfServiceStatus() { + return 'requested'; + }, }); diff --git a/orga/tests/acceptance/team-list-test.js b/orga/tests/acceptance/team-list-test.js index c0d582bfae1..5e63f36f7d5 100644 --- a/orga/tests/acceptance/team-list-test.js +++ b/orga/tests/acceptance/team-list-test.js @@ -139,6 +139,7 @@ module('Acceptance | Team List', function (hooks) { email: 'leaving@user.com', lang: 'fr', pixOrgaTermsOfServiceAccepted: true, + pixOrgaTermsOfServiceStatus: 'accepted', }); leavingUser.userOrgaSettings = server.create('user-orga-setting', { user: leavingUser, organization }); leavingUser.memberships = [ @@ -156,6 +157,7 @@ module('Acceptance | Team List', function (hooks) { email: 'left@user.com', lang: 'fr', pixOrgaTermsOfServiceAccepted: true, + pixOrgaTermsOfServiceStatus: 'accepted', }); leavingUser.userOrgaSettings = server.create('user-orga-setting', { user: userLeft, organization }); leavingUser.memberships = [ diff --git a/orga/tests/helpers/test-init.js b/orga/tests/helpers/test-init.js index 6f5f6f34c94..af15e7d097d 100644 --- a/orga/tests/helpers/test-init.js +++ b/orga/tests/helpers/test-init.js @@ -5,6 +5,7 @@ export function createPrescriberByUser({ user, participantCount = 0, features }) lastName: user.lastName, lang: user.lang, pixOrgaTermsOfServiceAccepted: user.pixOrgaTermsOfServiceAccepted, + pixOrgaTermsOfServiceStatus: user.pixOrgaTermsOfServiceStatus, memberships: user.memberships, userOrgaSettings: user.userOrgaSettings, participantCount, @@ -21,7 +22,16 @@ export function createPrescriberWithPixOrgaTermsOfService({ pixOrgaTermsOfServic const email = 'harry@cover.com'; const lang = 'fr'; - const user = server.create('user', { firstName, lastName, email, lang, pixOrgaTermsOfServiceAccepted }); + const pixOrgaTermsOfServiceStatus = pixOrgaTermsOfServiceAccepted ? 'accepted' : 'requested'; + + const user = server.create('user', { + firstName, + lastName, + email, + lang, + pixOrgaTermsOfServiceAccepted, + pixOrgaTermsOfServiceStatus, + }); const organization = server.create('organization', { name: 'BRO & Evil Associates', @@ -40,6 +50,7 @@ export function createPrescriberWithPixOrgaTermsOfService({ pixOrgaTermsOfServic lastName, lang, pixOrgaTermsOfServiceAccepted, + pixOrgaTermsOfServiceStatus, memberships: [membership], userOrgaSettings: userOrgaSettings, features: { MISSIONS_MANAGEMENT: false }, @@ -71,6 +82,7 @@ export function createUserWithMembership() { email: 'harry@cover.com', lang: 'fr', pixOrgaTermsOfServiceAccepted: false, + pixOrgaTermsOfServiceStatus: 'requested', }); return _addUserToOrganization(user); @@ -84,6 +96,7 @@ export function createUserWithMembershipAndTermsOfServiceAccepted({ organization email: 'harry@cover.com', lang: 'fr', pixOrgaTermsOfServiceAccepted: true, + pixOrgaTermsOfServiceStatus: 'accepted', }); server.create('member-identity', { id: user.id, firstName: 'Harry', lastName: 'Cover' }); return _addUserToOrganization(user, { externalId: 'EXTBRO', organizationType }); @@ -96,6 +109,7 @@ export function createUserMembershipWithRole(organizationRole) { email: 'harry@cover.com', lang: 'fr', pixOrgaTermsOfServiceAccepted: true, + pixOrgaTermsOfServiceStatus: 'accepted', }); const organization = server.create('organization', { @@ -122,6 +136,7 @@ export function createUserWithMultipleMemberships() { email: 'harry@cover.com', lang: 'fr', pixOrgaTermsOfServiceAccepted: true, + pixOrgaTermsOfServiceStatus: 'accepted', }); const firstOrganization = server.create('organization', { @@ -158,7 +173,11 @@ export function createPrescriberForOrganization( organizationRole, features, ) { - const user = server.create('user', { ...userAttributes, pixOrgaTermsOfServiceAccepted: true }); + const user = server.create('user', { + ...userAttributes, + pixOrgaTermsOfServiceAccepted: true, + pixOrgaTermsOfServiceStatus: 'accepted', + }); const organization = server.create('organization', organizationAttributes); @@ -194,6 +213,7 @@ export function createMember() { email: 'harry@cover.com', lang: 'fr', pixOrgaTermsOfServiceAccepted: true, + pixOrgaTermsOfServiceStatus: 'accepted', }); server.create('member-identity', { id: user.id, firstName: 'Harry', lastName: 'Cover' }); const organization = server.create('organization', { name: 'BRO & Evil Associates' }); @@ -213,6 +233,7 @@ export function createMember() { lastName: user.lastName, lang: user.lang, pixOrgaTermsOfServiceAccepted: user.pixOrgaTermsOfServiceAccepted, + pixOrgaTermsOfServiceStatus: user.pixOrgaTermsOfServiceStatus, memberships: user.memberships, userOrgaSettings: user.userOrgaSettings, features: { MISSIONS_MANAGEMENT: false }, @@ -228,6 +249,7 @@ export function createUserManagingStudents(role = 'MEMBER', type = 'SCO') { email: 'harry@cover.com', lang: 'fr', pixOrgaTermsOfServiceAccepted: true, + pixOrgaTermsOfServiceStatus: 'accepted', }); const organization = server.create('organization', { diff --git a/orga/tests/unit/routes/authenticated-test.js b/orga/tests/unit/routes/authenticated-test.js index 7deaa857068..e2e85bbe8a1 100644 --- a/orga/tests/unit/routes/authenticated-test.js +++ b/orga/tests/unit/routes/authenticated-test.js @@ -54,7 +54,11 @@ module('Unit | Route | authenticated', function (hooks) { const organizationId = Symbol('organizationId'); class CurrentUserStub extends Service { - prescriber = { placesManagement: true, pixOrgaTermsOfServiceAccepted: true }; + prescriber = { + placesManagement: true, + pixOrgaTermsOfServiceAccepted: true, + pixOrgaTermsOfServiceStatus: 'accepted', + }; organization = { id: organizationId, };