Skip to content

Commit 290465d

Browse files
authored
[MDS-6691] Save more data about MS users (#3724)
* parse token data in user-profile resource from MS users and update the data. Add more fields to MS user table, update model. Add versioning, fix issues with circular dependencies so it works. Update a field name. TS-ify the user list page * add fix for cypress tests * pr comments * add back param required for post * rename function
1 parent 05fa9b4 commit 290465d

File tree

43 files changed

+1554
-333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1554
-333
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
-- Add new columns to minespace_user table to align with user table structure
2+
ALTER TABLE minespace_user
3+
ADD COLUMN sub VARCHAR,
4+
ADD COLUMN email VARCHAR,
5+
ADD COLUMN given_name VARCHAR,
6+
ADD COLUMN family_name VARCHAR,
7+
ADD COLUMN display_name VARCHAR,
8+
ADD COLUMN identity_provider VARCHAR,
9+
ADD COLUMN bceid_user_guid VARCHAR,
10+
ADD COLUMN last_logged_in TIMESTAMPTZ,
11+
ADD COLUMN create_user VARCHAR(255),
12+
ADD COLUMN create_timestamp TIMESTAMP WITH TIME ZONE DEFAULT now(),
13+
ADD COLUMN update_user VARCHAR(255),
14+
ADD COLUMN update_timestamp TIMESTAMP WITH TIME ZONE DEFAULT now();
15+
16+
ALTER TABLE minespace_user
17+
RENAME COLUMN email_or_username TO bceid_username;
18+
19+
ALTER TABLE minespace_user
20+
DROP COLUMN IF EXISTS keycloak_guid;
21+
22+
COMMENT ON COLUMN minespace_user.sub IS 'User subject identifier from identity provider';
23+
COMMENT ON COLUMN minespace_user.email IS 'User email address';
24+
COMMENT ON COLUMN minespace_user.given_name IS 'User given/first name';
25+
COMMENT ON COLUMN minespace_user.family_name IS 'User family/last name';
26+
COMMENT ON COLUMN minespace_user.display_name IS 'User display name';
27+
COMMENT ON COLUMN minespace_user.bceid_username IS 'BCeID username (renamed from email_or_username)';
28+
COMMENT ON COLUMN minespace_user.identity_provider IS 'Identity provider used for authentication';
29+
COMMENT ON COLUMN minespace_user.bceid_user_guid IS 'BCeID user GUID';
30+
COMMENT ON COLUMN minespace_user.last_logged_in IS 'Timestamp of last login';
31+
COMMENT ON COLUMN minespace_user.create_user IS 'User who created the record';
32+
COMMENT ON COLUMN minespace_user.create_timestamp IS 'Timestamp when record was created';
33+
COMMENT ON COLUMN minespace_user.update_user IS 'User who last updated the record';
34+
COMMENT ON COLUMN minespace_user.update_timestamp IS 'Timestamp when record was last updated';
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- This file was generated by the generate_history_table_ddl command
2+
-- The file contains the corresponding history table definition for the minespace_user table
3+
CREATE TABLE minespace_user_version (
4+
create_user VARCHAR(60),
5+
create_timestamp TIMESTAMP WITHOUT TIME ZONE,
6+
update_user VARCHAR(60),
7+
update_timestamp TIMESTAMP WITHOUT TIME ZONE,
8+
deleted_ind BOOLEAN default FALSE,
9+
user_id INTEGER NOT NULL,
10+
bceid_username VARCHAR(100),
11+
sub VARCHAR,
12+
email VARCHAR,
13+
given_name VARCHAR,
14+
family_name VARCHAR,
15+
display_name VARCHAR,
16+
identity_provider VARCHAR,
17+
bceid_user_guid VARCHAR,
18+
last_logged_in TIMESTAMP WITHOUT TIME ZONE,
19+
transaction_id BIGINT NOT NULL,
20+
end_transaction_id BIGINT,
21+
operation_type SMALLINT NOT NULL,
22+
PRIMARY KEY (user_id, transaction_id)
23+
);
24+
CREATE INDEX ix_minespace_user_version_operation_type ON minespace_user_version (operation_type);
25+
CREATE INDEX ix_minespace_user_version_end_transaction_id ON minespace_user_version (end_transaction_id);
26+
CREATE INDEX ix_minespace_user_version_transaction_id ON minespace_user_version (transaction_id);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- This file was generated by the generate_history_table_ddl command
2+
-- The file contains the data migration to backfill history records for the minespace_user table
3+
with transaction AS (insert into transaction(id) values(DEFAULT) RETURNING id)
4+
insert into minespace_user_version (transaction_id, operation_type, end_transaction_id, "create_user", "create_timestamp", "update_user", "update_timestamp", "deleted_ind", "user_id", "bceid_username", "sub", "email", "given_name", "family_name", "display_name", "identity_provider", "bceid_user_guid", "last_logged_in")
5+
select t.id, '0', null, "create_user", "create_timestamp", "update_user", "update_timestamp", "deleted_ind", "user_id", "bceid_username", "sub", "email", "given_name", "family_name", "display_name", "identity_provider", "bceid_user_guid", "last_logged_in"
6+
from "minespace_user",transaction t;

services/common/src/components/mine/MineUserAccess.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { FC, useEffect } from "react";
22
import { useAppDispatch, useAppSelector } from "@mds/common/redux/rootState";
33
import { fetchMinespaceUsersByMine, getMinespaceUsersByMineGuid } from "@mds/common/redux/slices/minespaceSlice";
44
import CoreTable from "../common/CoreTable";
5-
import { renderTextColumn } from "../common/CoreTableCommonColumns";
5+
import { renderDateColumn, renderTextColumn } from "../common/CoreTableCommonColumns";
66
import { Col, Row, Typography } from "antd";
77
import { getIsCore } from "@mds/common/redux/reducers/authenticationReducer";
88
import { MDS_EMAIL } from "@mds/common/constants/strings";
@@ -24,7 +24,10 @@ const MineUserAccess: FC<MineUserAccessParams> = ({ mineGuid }) => {
2424
}, []);
2525

2626
const columns = [
27-
renderTextColumn("email_or_username", "BCeID/Email", true)
27+
renderTextColumn("display_name", "Name", true),
28+
renderTextColumn("bceid_username", "BCeID", true),
29+
renderTextColumn("email", "Email", true),
30+
renderDateColumn("last_logged_in", "Last Login", true),
2831
];
2932

3033
return (<Row>

services/common/src/interfaces/mine.interface.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ export interface IMine {
3232
latest_mine_status: IMineStatus;
3333
mine_status: IMineStatus[];
3434
}
35+
36+
export interface IMineName {
37+
mine_guid: string;
38+
mine_name: string;
39+
mine_no: string;
40+
latitude?: string;
41+
longitude?: string;
42+
}

services/common/src/interfaces/minespaceUser.interface.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
export interface IMinespaceUser {
22
user_id: number;
3-
email_or_username: string;
4-
keycloak_guid?: string;
3+
sub: string;
4+
email: string;
5+
given_name: string;
6+
family_name: string;
7+
display_name: string;
8+
bceid_username: string;
9+
identity_provider: string;
10+
last_logged_in: string;
511
mines: string[];
612
}
713

services/common/src/redux/slices/minespaceSlice.spec.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { IMinespaceUser } from "@mds/common/interfaces";
12
import {
23
minespaceReducer,
34
createMinespaceUser,
@@ -40,11 +41,17 @@ jest.mock("antd", () => ({
4041
describe("minespaceSlice", () => {
4142
let store;
4243

43-
const mockMinespaceUser = {
44+
const mockMinespaceUser: IMinespaceUser = {
4445
user_id: 1,
45-
email_or_username: "test@example.com",
46-
keycloak_guid: "123-456-789",
46+
bceid_username: "test@example.com",
4747
mines: ["mine-guid-1", "mine-guid-2"],
48+
sub: "sub-guid-string@bceidboth",
49+
email: "email@email.com",
50+
given_name: "Given",
51+
family_name: "Family",
52+
display_name: "Given Family",
53+
identity_provider: "bceidboth",
54+
last_logged_in: "2025-10-31 22:39:29.200932+00"
4855
};
4956

5057
const mockMinespaceUserMine = {
@@ -113,7 +120,7 @@ describe("minespaceSlice", () => {
113120
}));
114121

115122
const payload = {
116-
email_or_username: "test@example.com",
123+
bceid_username: "test@example.com",
117124
mine_guids: ["mine-guid-1"],
118125
};
119126

@@ -144,7 +151,7 @@ describe("minespaceSlice", () => {
144151
}));
145152

146153
const payload = {
147-
email_or_username: "test@example.com",
154+
bceid_username: "test@example.com",
148155
mine_guids: ["mine-guid-1"],
149156
};
150157

services/common/src/redux/slices/minespaceSlice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ export const getMinespaceUserEmailHash = createSelector(
364364
(users) =>
365365
users.reduce(
366366
(map, fields) => ({
367-
[fields.email_or_username]: fields,
367+
[fields.bceid_username]: fields,
368368
...map,
369369
}),
370370
{}

services/common/src/tests/mocks/dataMocks.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -929,21 +929,39 @@ export const MINE_NO = "BLAH6666";
929929
export const MINESPACE_USERS: IMinespaceUser[] = [
930930
{
931931
user_id: 1,
932-
email_or_username: "user1@bceid",
933-
keycloak_guid: "keycloak-guid-1",
932+
bceid_username: "user1@bceid",
934933
mines: [MINE_NAME_LIST.mines[0].mine_guid, MINE_NAME_LIST.mines[1].mine_guid,],
934+
sub: "sub-guid-string@bceidboth",
935+
email: "user1@email.com",
936+
given_name: "Ursula",
937+
family_name: "Underwood",
938+
display_name: "Ursula Underwood",
939+
identity_provider: "bceidboth",
940+
last_logged_in: "2025-10-31 22:39:29.200932+00"
935941
},
936942
{
937943
user_id: 2,
938-
email_or_username: "user2@example.com",
939-
keycloak_guid: "",
944+
bceid_username: "user2@bceid",
940945
mines: [MINE_NAME_LIST.mines[0].mine_guid,],
946+
sub: "",
947+
email: "",
948+
given_name: "",
949+
family_name: "",
950+
display_name: "",
951+
identity_provider: "",
952+
last_logged_in: ""
941953
},
942954
{
943955
user_id: 3,
944-
email_or_username: "user3@bceid",
945-
keycloak_guid: "keycloak-guid-3",
956+
bceid_username: "user3@bceid",
946957
mines: [MINE_NAME_LIST.mines[2].mine_guid,],
958+
sub: "",
959+
email: "",
960+
given_name: "",
961+
family_name: "",
962+
display_name: "",
963+
identity_provider: "",
964+
last_logged_in: ""
947965
},
948966
];
949967

services/core-api/app/api/activity/models/activity_notification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def create(cls, notification_recipient, notification_document, commit=False):
148148
@classmethod
149149
def create_many(cls, mine_guid, activity_type, document, idempotency_key=None, commit=True, recipients=ActivityRecipients.all_users, renotify_period_minutes=-1):
150150
MinespaceUserMineTable = table(MinespaceUserMine.__tablename__, column('mine_guid'), column('user_id'))
151-
MinespaceUserTable = table(MinespaceUser.__tablename__, column('email_or_username'), column('user_id'))
151+
MinespaceUserTable = table(MinespaceUser.__tablename__, column('bceid_username'), column('user_id'))
152152
SubscriptionTable = table(Subscription.__tablename__, column('mine_guid'), column('user_name'))
153153

154154
users = []

0 commit comments

Comments
 (0)