Skip to content

Commit

Permalink
feat(admin): Add OIDC information
Browse files Browse the repository at this point in the history
  • Loading branch information
theotime2005 committed Feb 4, 2025
1 parent b97cdcd commit c18f004
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
16 changes: 16 additions & 0 deletions admin/app/components/users/user-overview.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ export default class UserOverview extends Component {
@service pixToast;
@service references;
@service store;
@service oidcIdentityProviders;

@tracked displayAnonymizeModal = false;
@tracked isEditionMode = false;
@tracked authenticationMethods = [];

languages = this.references.availableLanguages;
locales = this.references.availableLocales;
Expand All @@ -39,6 +41,9 @@ export default class UserOverview extends Component {
constructor() {
super(...arguments);
this.form = this.store.createRecord('user-form');
Promise.resolve(this.args.user.authenticationMethods).then((authenticationMethods) => {
this.authenticationMethods = authenticationMethods;
});
}

get externalURL() {
Expand Down Expand Up @@ -86,6 +91,14 @@ export default class UserOverview extends Component {
return this.args.user.username ? null : 'obligatoire';
}

get useOidcAuthentication() {
const oidcProvidersCodes = this.oidcIdentityProviders.list.map((provider) => provider.code);
const userHasThisOidcAuthenticationMethod = this.authenticationMethods.any((authenticationMethod) =>
oidcProvidersCodes.includes(authenticationMethod.identityProvider),
);
return userHasThisOidcAuthenticationMethod ? 'Oui' : 'Non';
}

_initForm() {
this.form.firstName = this.args.user.firstName;
this.form.lastName = this.args.user.lastName;
Expand Down Expand Up @@ -331,6 +344,9 @@ export default class UserOverview extends Component {
{{/if}}
</span>
</li>
<li class="user-detail-personal-information-section__user-informations flex space-between gap-4x">
<span>SSO : {{this.useOidcAuthentication}}</span>
</li>
</ul>

<ul class="user-detail-personal-information-section__infogroup">
Expand Down
71 changes: 71 additions & 0 deletions admin/tests/integration/components/users/user-overview-test.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,14 @@ module('Integration | Component | users | user-overview', function (hooks) {

test('displays the update button', async function (assert) {
// given
const store = this.owner.lookup('service:store');
const user = {
firstName: 'John',
lastName: 'Harry',
email: '[email protected]',
username: 'john.harry0102',
};
user.authenticationMethods = [await store.createRecord('authentication-method', { identityProvider: 'abc' })];

// when
const screen = await render(<template><UserOverview @user={{user}} /></template>);
Expand Down Expand Up @@ -392,13 +394,15 @@ module('Integration | Component | users | user-overview', function (hooks) {
module('When the admin member click to update user details', function () {
test('displays the edit and cancel buttons', async function (assert) {
// given
const store = this.owner.lookup('service:store');
const user = {
firstName: 'John',
lastName: 'Harry',
email: '[email protected]',
username: null,
lang: null,
};
user.authenticationMethods = [await store.createRecord('authentication-method', { identityProvider: 'abc' })];

// when
const screen = await render(<template><UserOverview @user={{user}} /></template>);
Expand All @@ -416,6 +420,7 @@ module('Integration | Component | users | user-overview', function (hooks) {
firstName: 'John',
email: '[email protected]',
username: null,
authenticationMethods: [],
});

// when
Expand Down Expand Up @@ -450,6 +455,7 @@ module('Integration | Component | users | user-overview', function (hooks) {
firstName: 'John',
email: '[email protected]',
username: null,
authenticationMethods: [],
});

// when
Expand All @@ -469,6 +475,7 @@ module('Integration | Component | users | user-overview', function (hooks) {
firstName: 'John',
email: '[email protected]',
username: null,
authenticationMethods: [],
});

// when
Expand All @@ -486,6 +493,7 @@ module('Integration | Component | users | user-overview', function (hooks) {
firstName: 'John',
email: '[email protected]',
username: null,
authenticationMethods: [],
});

// when
Expand All @@ -505,6 +513,7 @@ module('Integration | Component | users | user-overview', function (hooks) {
firstName: 'John',
email: null,
username: 'user.name1212',
authenticationMethods: [],
});

// when
Expand All @@ -522,6 +531,7 @@ module('Integration | Component | users | user-overview', function (hooks) {
firstName: 'John',
email: null,
username: 'user.name1212',
authenticationMethods: [],
});

// when
Expand All @@ -543,6 +553,7 @@ module('Integration | Component | users | user-overview', function (hooks) {
firstName: 'John',
email: null,
username: undefined,
authenticationMethods: [],
});

// when
Expand All @@ -563,6 +574,7 @@ module('Integration | Component | users | user-overview', function (hooks) {
firstName: 'John',
email: '[email protected]',
username: null,
authenticationMethods: [],
});

const screen = await render(<template><UserOverview @user={{user}} /></template>);
Expand All @@ -588,6 +600,7 @@ module('Integration | Component | users | user-overview', function (hooks) {
firstName: 'John',
email: '[email protected]',
username: null,
authenticationMethods: [],
});

const screen = await render(<template><UserOverview @user={{user}} /></template>);
Expand Down Expand Up @@ -660,6 +673,7 @@ module('Integration | Component | users | user-overview', function (hooks) {
firstName: 'John',
email: '[email protected]',
isPixAgent: true,
authenticationMethods: [],
});

// when
Expand All @@ -675,11 +689,67 @@ module('Integration | Component | users | user-overview', function (hooks) {
assert.dom(anonymizationDisabledTooltip).exists();
});
});

module('Displays OIDC information', function (hooks) {
class OidcIdentityProvidersStub extends Service {
get list() {
return [
{
code: 'SUNLIGHT_NAVIGATIONS',
organizationName: 'Sunlight Navigations',
},
];
}
}

hooks.beforeEach(function () {
this.owner.register('service:oidc-identity-providers', OidcIdentityProvidersStub);
});

test('When user has not OIDC authentication method', async function (assert) {
// given
const store = this.owner.lookup('service:store');
const user = {
firstName: 'John',
lastName: 'Harry',
email: '[email protected]',
username: 'john.harry0102',
};
user.authenticationMethods = [await store.createRecord('authentication-method', { identityProvider: 'abc' })];

// when
const screen = await render(<template><UserOverview @user={{user}} /></template>);

// then
assert.dom(screen.getByText('SSO : Non')).exists();
});

test('When user has OIDC authentication method', async function (assert) {
// given
const store = this.owner.lookup('service:store');
const user = {
firstName: 'John',
lastName: 'Harry',
email: '[email protected]',
username: 'john.harry0102',
};
user.authenticationMethods = [
await store.createRecord('authentication-method', { identityProvider: 'SUNLIGHT_NAVIGATIONS' }),
];

// when
const screen = await render(<template><UserOverview @user={{user}} /></template>);

// then
assert.dom(screen.getByText('SSO : Oui')).exists();
});
});
});

module('When the admin member does not have access to users actions scope', function () {
test('does not display the action buttons "Modifier" and "Anonymiser cet utilisateur"', async function (assert) {
// given
const store = this.owner.lookup('service:store');
class AccessControlStub extends Service {
hasAccessToUsersActionsScope = false;
}
Expand All @@ -690,6 +760,7 @@ module('Integration | Component | users | user-overview', function (hooks) {
email: '[email protected]',
username: 'john.harry0102',
};
user.authenticationMethods = [await store.createRecord('authentication-method', { identityProvider: 'abc' })];
this.owner.register('service:access-control', AccessControlStub);

// when
Expand Down

0 comments on commit c18f004

Please sign in to comment.