Skip to content

Commit

Permalink
Assign to Me - not working (bcgov#1327)
Browse files Browse the repository at this point in the history
* Update token parsing for current user idpUserId

Signed-off-by: Jason Sherman <[email protected]>

* set username to use value similar to the old values

Signed-off-by: Jason Sherman <[email protected]>

---------

Signed-off-by: Jason Sherman <[email protected]>
  • Loading branch information
usingtechnology authored Apr 25, 2024
1 parent c3b1d1b commit e1cfc2e
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 124 deletions.
4 changes: 2 additions & 2 deletions app/frontend/src/components/forms/submission/StatusPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default {
};
},
computed: {
...mapState(useAuthStore, ['identityProviderIdentity']),
...mapState(useAuthStore, ['user']),
...mapState(useFormStore, [
'form',
'formSubmission',
Expand Down Expand Up @@ -146,7 +146,7 @@ export default {
assignToCurrentUser() {
this.assignee = this.formReviewers.find(
(f) => f.idpUserId === this.identityProviderIdentity
(f) => f.idpUserId === this.user.idpUserId
);
},
Expand Down
30 changes: 24 additions & 6 deletions app/frontend/src/store/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,16 @@ export const useAuthStore = defineStore('auth', {
},
isAdmin: (state) => state.hasResourceRoles(['admin']),
keycloakSubject: (state) => state.keycloak.subject,
identityProviderIdentity: (state) => state.keycloak.tokenParsed.idp_userid,
identityProviderIdentity: (state) => {
// leaving this for backwards compatibility.
// please call user.idpUserId instead
const idpStore = useIdpStore();
return idpStore.getTokenMapValue(
state.tokenParsed.identity_provider,
'idpUserId',
state.tokenParsed
);
},
moduleLoaded: (state) => !!state.keycloak,
realmAccess: (state) => state.keycloak.tokenParsed.realm_access,
resourceAccess: (state) => state.keycloak.tokenParsed.client_roles,
Expand All @@ -65,6 +74,7 @@ export const useAuthStore = defineStore('auth', {
user: (state) => {
const idpStore = useIdpStore();
const user = {
idpUserId: '',
username: '',
firstName: '',
lastName: '',
Expand All @@ -78,17 +88,25 @@ export const useAuthStore = defineStore('auth', {
public: !state.authenticated,
};
if (state.authenticated) {
if (state.tokenParsed.idp_username) {
user.username = state.tokenParsed.idp_username;
} else {
user.username = state.tokenParsed.preferred_username;
}
user.firstName = state.tokenParsed.given_name;
user.lastName = state.tokenParsed.family_name;
user.fullName = state.tokenParsed.name;
user.email = state.tokenParsed.email;
const idp = idpStore.findByHint(state.tokenParsed.identity_provider);
user.idp = idp;
user.username = idpStore.getTokenMapValue(
state.tokenParsed.identity_provider,
'username',
state.tokenParsed
);
user.idpUserId = idpStore.getTokenMapValue(
state.tokenParsed.identity_provider,
'idpUserId',
state.tokenParsed
);
if (!user.username) {
user.username = state.tokenParsed.preferred_username;
}
}

return user;
Expand Down
13 changes: 13 additions & 0 deletions app/frontend/src/store/identityProviders.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,18 @@ export const useIdpStore = defineStore('idps', {
}
return undefined;
},
getTokenMapValue(hint, field, token) {
if (hint && this.providers) {
const idp = this.providers.find((x) => x.idp === hint);
if (idp) {
// now find this field...
const tokenKey = idp.tokenmap[field];
if (tokenKey) {
return token[tokenKey];
}
}
}
return undefined;
},
},
});
248 changes: 135 additions & 113 deletions app/frontend/tests/unit/fixtures/identityProviders.json
Original file line number Diff line number Diff line change
@@ -1,119 +1,141 @@
[
{
"code": "idir",
"display": "IDIR",
"active": true,
"idp": "idir",
"createdBy": "migration-002",
"createdAt": "2024-01-24T22:35:49.703Z",
"updatedBy": null,
"updatedAt": "2024-01-24T22:35:49.703Z",
"primary": true,
"login": true,
"permissions": [
"views_form_stepper",
"views_admin",
"views_file_download",
"views_form_emails",
"views_form_export",
"views_form_manage",
"views_form_preview",
"views_form_submissions",
"views_form_teamS",
"views_form_view",
"views_user_submissions"
],
"roles": [
"owner",
"team_manager",
"form_designer",
"submission_reviewer",
"form_submitter"
],
"extra": {}
{
"code": "idir",
"display": "IDIR",
"active": true,
"idp": "idir",
"createdBy": "migration-002",
"createdAt": "2024-01-24T22:35:49.703Z",
"updatedBy": null,
"updatedAt": "2024-01-24T22:35:49.703Z",
"primary": true,
"login": true,
"permissions": [
"views_form_stepper",
"views_admin",
"views_file_download",
"views_form_emails",
"views_form_export",
"views_form_manage",
"views_form_preview",
"views_form_submissions",
"views_form_teamS",
"views_form_view",
"views_user_submissions"
],
"roles": [
"owner",
"team_manager",
"form_designer",
"submission_reviewer",
"form_submitter"
],
"tokenmap": {
"idpUserId": "idir_user_guid",
"keycloakId": "idir_user_guid",
"username": "idir_username",
"firstName": "given_name",
"lastName": "family_name",
"fullName": "name",
"email": "email",
"idp": "identity_provider"
},
{
"code": "bceid-basic",
"display": "Basic BCeID",
"active": true,
"idp": "bceidbasic",
"createdBy": "migration-022",
"createdAt": "2024-01-24T22:35:49.703Z",
"updatedBy": null,
"updatedAt": "2024-01-24T22:35:49.703Z",
"primary": false,
"login": true,
"permissions": [
"views_user_submissions"
],
"roles": [
"form_submitter"
],
"extra": {
"formAccessSettings": "idim",
"addTeamMemberSearch": {
"text": {
"message": "trans.manageSubmissionUsers.searchInputLength",
"minLength": 6
},
"email": {
"exact": true,
"message": "trans.manageSubmissionUsers.exactBCEIDSearch"
}
}
}
"extra": {}
},
{
"code": "bceid-basic",
"display": "Basic BCeID",
"active": true,
"idp": "bceidbasic",
"createdBy": "migration-022",
"createdAt": "2024-01-24T22:35:49.703Z",
"updatedBy": null,
"updatedAt": "2024-01-24T22:35:49.703Z",
"primary": false,
"login": true,
"permissions": ["views_user_submissions"],
"roles": ["form_submitter"],
"tokenmap": {
"idpUserId": "bceid_user_guid",
"keycloakId": "bceid_user_guid",
"username": "bceid_username",
"firstName": null,
"lastName": null,
"fullName": "name",
"email": "email",
"idp": "identity_provider"
},
{
"code": "bceid-business",
"display": "Business BCeID",
"active": true,
"idp": "bceidbusiness",
"createdBy": "migration-022",
"createdAt": "2024-01-24T22:35:49.703Z",
"updatedBy": null,
"updatedAt": "2024-01-24T22:35:49.703Z",
"primary": false,
"login": true,
"permissions": [
"views_form_export",
"views_form_manage",
"views_form_submissions",
"views_form_teamS",
"views_form_view",
"views_user_submissions"
],
"roles": [
"team_manager",
"submission_reviewer",
"form_submitter"
],
"extra": {
"formAccessSettings": "idim",
"addTeamMemberSearch": {
"text": {
"message": "trans.manageSubmissionUsers.searchInputLength",
"minLength": 6
},
"email": {
"exact": true,
"message": "trans.manageSubmissionUsers.exactBCEIDSearch"
}
}
"extra": {
"formAccessSettings": "idim",
"addTeamMemberSearch": {
"text": {
"message": "trans.manageSubmissionUsers.searchInputLength",
"minLength": 6
},
"email": {
"exact": true,
"message": "trans.manageSubmissionUsers.exactBCEIDSearch"
}
}
}
},
{
"code": "bceid-business",
"display": "Business BCeID",
"active": true,
"idp": "bceidbusiness",
"createdBy": "migration-022",
"createdAt": "2024-01-24T22:35:49.703Z",
"updatedBy": null,
"updatedAt": "2024-01-24T22:35:49.703Z",
"primary": false,
"login": true,
"permissions": [
"views_form_export",
"views_form_manage",
"views_form_submissions",
"views_form_teamS",
"views_form_view",
"views_user_submissions"
],
"roles": ["team_manager", "submission_reviewer", "form_submitter"],
"tokenmap": {
"idpUserId": "bceid_user_guid",
"keycloakId": "bceid_user_guid",
"username": "bceid_username",
"firstName": null,
"lastName": null,
"fullName": "name",
"email": "email",
"idp": "identity_provider"
},
{
"code": "public",
"display": "Public",
"active": true,
"idp": "public",
"createdBy": "migration-002",
"createdAt": "2024-01-24T22:35:49.703Z",
"updatedBy": null,
"updatedAt": "2024-01-24T22:35:49.703Z",
"primary": false,
"login": false,
"permissions": [],
"roles": null,
"extra": {}
"extra": {
"formAccessSettings": "idim",
"addTeamMemberSearch": {
"text": {
"message": "trans.manageSubmissionUsers.searchInputLength",
"minLength": 6
},
"email": {
"exact": true,
"message": "trans.manageSubmissionUsers.exactBCEIDSearch"
}
}
}
]
},
{
"code": "public",
"display": "Public",
"active": true,
"idp": "public",
"createdBy": "migration-002",
"createdAt": "2024-01-24T22:35:49.703Z",
"updatedBy": null,
"updatedAt": "2024-01-24T22:35:49.703Z",
"primary": false,
"login": false,
"permissions": [],
"roles": null,
"extra": {}
}
]
9 changes: 6 additions & 3 deletions app/frontend/tests/unit/store/modules/auth.getters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ describe('auth getters', () => {
name: 'John Doe',
email: '[email protected]',
identity_provider: 'idir',
idp_userid: zeroGuid,
idir_user_guid: zeroGuid,
idir_username: 'JDOE',
preferred_username: 'johndoe',
realm_access: {},
client_roles: roles,
Expand Down Expand Up @@ -185,12 +186,13 @@ describe('auth getters', () => {
it('creates an auth user when authenticated', () => {
expect(store.user).toBeTruthy();
expect(store.user).toEqual({
username: 'johndoe',
username: 'JDOE',
firstName: 'John',
lastName: 'Doe',
fullName: 'John Doe',
email: '[email protected]',
idp: {code: 'idir', display: 'IDIR', hint: 'idir'},
idp: { code: 'idir', display: 'IDIR', hint: 'idir' },
idpUserId: zeroGuid,
public: false,
});
});
Expand All @@ -201,6 +203,7 @@ describe('auth getters', () => {

expect(store.user).toBeTruthy();
expect(store.user).toEqual({
idpUserId: '',
username: '',
firstName: '',
lastName: '',
Expand Down

0 comments on commit e1cfc2e

Please sign in to comment.