Skip to content

Commit

Permalink
feat(orga): use pixOrgaTermsOfServiceStatus
Browse files Browse the repository at this point in the history
Co-authored-by: Theo <[email protected]>
Co-authored-by: Jérémy PLUQUET <[email protected]>
  • Loading branch information
3 people committed Jan 8, 2025
1 parent 47f2edf commit 2956478
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions orga/app/controllers/terms-of-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
1 change: 1 addition & 0 deletions orga/app/models/prescriber.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions orga/app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 2 additions & 2 deletions orga/app/routes/authenticated.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
Expand Down
4 changes: 2 additions & 2 deletions orga/app/routes/terms-of-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
}
}
Expand Down
2 changes: 1 addition & 1 deletion orga/mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand Down
4 changes: 4 additions & 0 deletions orga/mirage/factories/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ export default Factory.extend({
pixOrgaTermsOfServiceAccepted() {
return faker.datatype.boolean();
},

pixOrgaTermsOfServiceStatus() {
return 'requested';
},
});
2 changes: 2 additions & 0 deletions orga/tests/acceptance/team-list-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ module('Acceptance | Team List', function (hooks) {
email: '[email protected]',
lang: 'fr',
pixOrgaTermsOfServiceAccepted: true,
pixOrgaTermsOfServiceStatus: 'accepted',
});
leavingUser.userOrgaSettings = server.create('user-orga-setting', { user: leavingUser, organization });
leavingUser.memberships = [
Expand All @@ -156,6 +157,7 @@ module('Acceptance | Team List', function (hooks) {
email: '[email protected]',
lang: 'fr',
pixOrgaTermsOfServiceAccepted: true,
pixOrgaTermsOfServiceStatus: 'accepted',
});
leavingUser.userOrgaSettings = server.create('user-orga-setting', { user: userLeft, organization });
leavingUser.memberships = [
Expand Down
26 changes: 24 additions & 2 deletions orga/tests/helpers/test-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,7 +22,16 @@ export function createPrescriberWithPixOrgaTermsOfService({ pixOrgaTermsOfServic
const email = '[email protected]';
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',
Expand All @@ -40,6 +50,7 @@ export function createPrescriberWithPixOrgaTermsOfService({ pixOrgaTermsOfServic
lastName,
lang,
pixOrgaTermsOfServiceAccepted,
pixOrgaTermsOfServiceStatus,
memberships: [membership],
userOrgaSettings: userOrgaSettings,
features: { MISSIONS_MANAGEMENT: false },
Expand Down Expand Up @@ -71,6 +82,7 @@ export function createUserWithMembership() {
email: '[email protected]',
lang: 'fr',
pixOrgaTermsOfServiceAccepted: false,
pixOrgaTermsOfServiceStatus: 'requested',
});

return _addUserToOrganization(user);
Expand All @@ -84,6 +96,7 @@ export function createUserWithMembershipAndTermsOfServiceAccepted({ organization
email: '[email protected]',
lang: 'fr',
pixOrgaTermsOfServiceAccepted: true,
pixOrgaTermsOfServiceStatus: 'accepted',
});
server.create('member-identity', { id: user.id, firstName: 'Harry', lastName: 'Cover' });
return _addUserToOrganization(user, { externalId: 'EXTBRO', organizationType });
Expand All @@ -96,6 +109,7 @@ export function createUserMembershipWithRole(organizationRole) {
email: '[email protected]',
lang: 'fr',
pixOrgaTermsOfServiceAccepted: true,
pixOrgaTermsOfServiceStatus: 'accepted',
});

const organization = server.create('organization', {
Expand All @@ -122,6 +136,7 @@ export function createUserWithMultipleMemberships() {
email: '[email protected]',
lang: 'fr',
pixOrgaTermsOfServiceAccepted: true,
pixOrgaTermsOfServiceStatus: 'accepted',
});

const firstOrganization = server.create('organization', {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -194,6 +213,7 @@ export function createMember() {
email: '[email protected]',
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' });
Expand All @@ -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 },
Expand All @@ -228,6 +249,7 @@ export function createUserManagingStudents(role = 'MEMBER', type = 'SCO') {
email: '[email protected]',
lang: 'fr',
pixOrgaTermsOfServiceAccepted: true,
pixOrgaTermsOfServiceStatus: 'accepted',
});

const organization = server.create('organization', {
Expand Down
6 changes: 5 additions & 1 deletion orga/tests/unit/routes/authenticated-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down

0 comments on commit 2956478

Please sign in to comment.