Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: CE-501 Admin page #852

Merged
merged 23 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
568810b
chore: update 0.6.9 main (#821)
afwilcox Dec 12, 2024
f4d5997
fix: Map Search Filters / Officers (#817)
nayr974 Dec 12, 2024
2bbb8d0
feat: CE-501 admin page
Scarlett-Truong Dec 16, 2024
5efa651
Merge branch 'main' into release/0.6.10
afwilcox Dec 16, 2024
b3f146d
fix: fix bad merge
afwilcox Dec 16, 2024
f03f7fb
chore: CE-1274 (#827)
nayr974 Dec 17, 2024
71ea769
fix: CE-1291 zone at a glance-enforcement not correct (#819)
Scarlett-Truong Dec 17, 2024
cf77894
feat: CE-1082-Add-attachment-summary-to-PDF-exports (#828)
dk-bcps Dec 17, 2024
20d3d46
Merge branch 'release/0.6.10' into CE-501
Scarlett-Truong Dec 17, 2024
ef2c4ae
Merge branch 'release/0.6.12' into CE-501
Scarlett-Truong Dec 23, 2024
e53761a
edit user, add new user ui
Scarlett-Truong Dec 25, 2024
adeb0a2
edit user func
Scarlett-Truong Jan 2, 2025
af937d6
add user, deactivate user func
Scarlett-Truong Jan 6, 2025
fdf8143
Merge branch 'release/0.6.12' into CE-501
Scarlett-Truong Jan 6, 2025
12a9ce2
Merge branch 'release/0.6.12' into CE-501
afwilcox Jan 6, 2025
b4b0f9b
fix misc bugs
Scarlett-Truong Jan 7, 2025
ce6f9ae
Merge branch 'CE-501' of https://github.com/bcgov/nr-compliance-enfor…
Scarlett-Truong Jan 7, 2025
0dc92e2
Merge branch 'release/0.6.12' into CE-501
Scarlett-Truong Jan 7, 2025
c99e5a5
Merge branch 'release/0.6.12' into CE-501
Scarlett-Truong Jan 7, 2025
20dcacf
remove unused imports
Scarlett-Truong Jan 7, 2025
5c62490
Merge branch 'release/0.6.12' into CE-501
Scarlett-Truong Jan 7, 2025
9bec378
fix sonarcloud
Scarlett-Truong Jan 7, 2025
78eaec4
fix: Update person repository mock
afwilcox Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions backend/src/external_api/css/css.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ExternalApiService } from "../external-api-service";
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
import { get } from "../../helpers/axios-api";
import { ConfigurationService } from "../../v1/configuration/configuration.service";
import { CssUser } from "src/types/css/cssUser";

@Injectable()
export class CssService implements ExternalApiService {
Expand Down Expand Up @@ -64,6 +65,24 @@ export class CssService implements ExternalApiService {
}
};

getUserIdirByEmail = async (email: string): Promise<CssUser[]> => {
try {
const apiToken = await this.authenticate();
const url = `${this.baseUri}/api/v1/${this.env}/idir/users?email=${email}`;
const config: AxiosRequestConfig = {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiToken}`,
},
};
const response = await get(apiToken, url, config);
return response?.data.data;
} catch (error) {
this.logger.error(`exception: unable to get user by email: ${email} - error: ${error}`);
throw new Error(`exception: unable to get user by email: ${email} - error: ${error}`);
}
};

getUserRoles = async (userIdir): Promise<{ name: string; composite: string }[]> => {
try {
const apiToken = await this.authenticate();
Expand Down
11 changes: 11 additions & 0 deletions backend/src/types/css/cssUser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export interface CssUser {
username: string;
firstName: string;
lastName: string;
email: string;
attributes: {
idir_user_guid: string[];
idir_username: string[];
display_name: string[];
};
}
7 changes: 7 additions & 0 deletions backend/src/types/models/general/team-update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface TeamUpdate {
userIdir: string;
adminIdirUsername: string;
agencyCode: string;
teamCode: string | null;
roles: Array<{ name: string }>;
}
26 changes: 26 additions & 0 deletions backend/src/types/models/people/officer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export interface NewOfficer {
user_id: string;
create_user_id: string;
create_utc_timestamp: Date;
update_user_id: string;
update_utc_timestamp: Date;
auth_user_guid: string;
office_guid: string | null;
team_code: string | null;
person_guid: {
first_name: string;
middle_name_1: null;
middle_name_2: null;
last_name: string;
create_user_id: string;
create_utc_timestamp: Date;
update_user_id: string;
updateTimestamp: Date;
};
roles: {
user_roles: Array<{ name: string | undefined }>;
user_idir: string; //Example : fohe4m5pn8clhkxmlho33sn1r7vr7m67@idir
};
coms_enrolled_ind: boolean;
deactivate_ind: boolean;
}
14 changes: 14 additions & 0 deletions backend/src/v1/case_file/case_file.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ import { ConfigurationService } from "../configuration/configuration.service";
import { Configuration } from "../configuration/entities/configuration.entity";
import { Person } from "../person/entities/person.entity";
import { LinkedComplaintXrefService } from "../linked_complaint_xref/linked_complaint_xref.service";
import { TeamService } from "../team/team.service";
import { OfficerTeamXrefService } from "../officer_team_xref/officer_team_xref.service";
import { Team } from "../team/entities/team.entity";
import { OfficerTeamXref } from "../officer_team_xref/entities/officer_team_xref.entity";

describe("Testing: Case File Service", () => {
let service: CaseFileService;
Expand Down Expand Up @@ -208,6 +212,14 @@ describe("Testing: Case File Service", () => {
provide: getRepositoryToken(Person),
useValue: {},
},
{
provide: getRepositoryToken(Team),
useValue: {},
},
{
provide: getRepositoryToken(OfficerTeamXref),
useValue: {},
},
ComplaintUpdatesService,
CaseFileService,
ComplaintService,
Expand All @@ -221,6 +233,8 @@ describe("Testing: Case File Service", () => {
PersonComplaintXrefService,
AttractantHwcrXrefService,
CompMthdRecvCdAgcyCdXrefService,
TeamService,
OfficerTeamXrefService,
{
provide: REQUEST,
useValue: {
Expand Down
24 changes: 24 additions & 0 deletions backend/src/v1/complaint/complaint.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ import { Person } from "../person/entities/person.entity";
import { Configuration } from "../configuration/entities/configuration.entity";
import { LinkedComplaintXrefService } from "../linked_complaint_xref/linked_complaint_xref.service";
import { LinkedComplaintXref } from "../linked_complaint_xref/entities/linked_complaint_xref.entity";
import { TeamService } from "../team/team.service";
import { Team } from "../team/entities/team.entity";
import { OfficerTeamXrefService } from "../officer_team_xref/officer_team_xref.service";
import { OfficerTeamXref } from "../officer_team_xref/entities/officer_team_xref.entity";

describe("Testing: Complaint Service", () => {
let service: ComplaintService;
Expand Down Expand Up @@ -117,6 +121,14 @@ describe("Testing: Complaint Service", () => {
provide: getRepositoryToken(LinkedComplaintXref),
useValue: {},
},
{
provide: getRepositoryToken(Team),
useValue: {},
},
{
provide: getRepositoryToken(OfficerTeamXref),
useValue: {},
},
ComplaintUpdatesService,
ComplaintService,
PersonComplaintXrefService,
Expand All @@ -129,6 +141,8 @@ describe("Testing: Complaint Service", () => {
AttractantHwcrXrefService,
CodeTableService,
CompMthdRecvCdAgcyCdXrefService,
TeamService,
OfficerTeamXrefService,
{
provide: getRepositoryToken(Complaint),
useFactory: MockComplaintsRepositoryV2,
Expand Down Expand Up @@ -410,6 +424,14 @@ describe("Testing: Complaint Service", () => {
provide: getRepositoryToken(LinkedComplaintXref),
useValue: {},
},
{
provide: getRepositoryToken(Team),
useValue: {},
},
{
provide: getRepositoryToken(OfficerTeamXref),
useValue: {},
},
ComplaintUpdatesService,
ComplaintService,
PersonComplaintXrefService,
Expand All @@ -422,6 +444,8 @@ describe("Testing: Complaint Service", () => {
AttractantHwcrXrefService,
CodeTableService,
CompMthdRecvCdAgcyCdXrefService,
TeamService,
OfficerTeamXrefService,
{
provide: getRepositoryToken(Complaint),
useFactory: MockUpdateComplaintsRepository,
Expand Down
14 changes: 14 additions & 0 deletions backend/src/v1/document/document.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ import { CssService } from "../../external_api/css/css.service";
import { Person } from "../person/entities/person.entity";
import { LinkedComplaintXref } from "../linked_complaint_xref/entities/linked_complaint_xref.entity";
import { LinkedComplaintXrefService } from "../linked_complaint_xref/linked_complaint_xref.service";
import { Team } from "../team/entities/team.entity";
import { OfficerTeamXref } from "../officer_team_xref/entities/officer_team_xref.entity";
import { TeamService } from "../team/team.service";
import { OfficerTeamXrefService } from "../officer_team_xref/officer_team_xref.service";

describe("DocumentController", () => {
let controller: DocumentController;
Expand Down Expand Up @@ -206,6 +210,14 @@ describe("DocumentController", () => {
provide: getRepositoryToken(LinkedComplaintXref),
useValue: {},
},
{
provide: getRepositoryToken(Team),
useValue: {},
},
{
provide: getRepositoryToken(OfficerTeamXref),
useValue: {},
},
ComplaintUpdatesService,
ComplaintService,
CodeTableService,
Expand All @@ -217,6 +229,8 @@ describe("DocumentController", () => {
PersonService,
AttractantHwcrXrefService,
CompMthdRecvCdAgcyCdXrefService,
TeamService,
OfficerTeamXrefService,
{
provide: REQUEST,
useValue: {
Expand Down
14 changes: 14 additions & 0 deletions backend/src/v1/document/document.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ import { CssService } from "../../external_api/css/css.service";
import { Person } from "../person/entities/person.entity";
import { LinkedComplaintXrefService } from "../linked_complaint_xref/linked_complaint_xref.service";
import { LinkedComplaintXref } from "../linked_complaint_xref/entities/linked_complaint_xref.entity";
import { Team } from "../team/entities/team.entity";
import { OfficerTeamXref } from "../officer_team_xref/entities/officer_team_xref.entity";
import { TeamService } from "../team/team.service";
import { OfficerTeamXrefService } from "../officer_team_xref/officer_team_xref.service";

describe("DocumentService", () => {
let service: DocumentService;
Expand Down Expand Up @@ -205,6 +209,14 @@ describe("DocumentService", () => {
provide: getRepositoryToken(LinkedComplaintXref),
useValue: {},
},
{
provide: getRepositoryToken(Team),
useValue: {},
},
{
provide: getRepositoryToken(OfficerTeamXref),
useValue: {},
},
ComplaintUpdatesService,
ComplaintService,
CodeTableService,
Expand All @@ -216,6 +228,8 @@ describe("DocumentService", () => {
PersonService,
AttractantHwcrXrefService,
CompMthdRecvCdAgcyCdXrefService,
TeamService,
OfficerTeamXrefService,
{
provide: REQUEST,
useValue: {
Expand Down
3 changes: 3 additions & 0 deletions backend/src/v1/officer/dto/create-officer.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ export class CreateOfficerDto extends PickType(OfficerDto, [
"user_id",
"person_guid",
"office_guid",
"auth_user_guid",
"create_user_id",
"create_utc_timestamp",
"update_user_id",
"update_utc_timestamp",
"coms_enrolled_ind",
"deactivate_ind",
] as const) {}
12 changes: 12 additions & 0 deletions backend/src/v1/officer/dto/officer.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,16 @@ export class OfficerDto {
description: "The keycloak guid for the officer",
})
auth_user_guid: UUID;

@ApiProperty({
example: "true",
description: "An indicator to determine if the officer has access to COMS",
})
coms_enrolled_ind: boolean;

@ApiProperty({
example: "false",
description: "An indicator to determine if the officer has been deactivated",
})
deactivate_ind: boolean;
}
4 changes: 3 additions & 1 deletion backend/src/v1/officer/dto/update-officer.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { PartialType } from "@nestjs/swagger";
import { CreateOfficerDto } from "./create-officer.dto";

export class UpdateOfficerDto extends PartialType(CreateOfficerDto) {}
export class UpdateOfficerDto extends PartialType(CreateOfficerDto) {
user_roles?: string[];
}
7 changes: 7 additions & 0 deletions backend/src/v1/officer/entities/officer.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ export class Officer {
@Column()
coms_enrolled_ind: boolean;

@ApiProperty({
example: false,
description: "Indicates whether an officer has been deactivated",
})
@Column()
deactivate_ind: boolean;

user_roles: string[];
@AfterLoad()
updateUserRoles() {
Expand Down
14 changes: 14 additions & 0 deletions backend/src/v1/officer/officer.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { dataSourceMockFactory } from "../../../test/mocks/datasource";
import { CssService } from "../../external_api/css/css.service";
import { ConfigurationService } from "../configuration/configuration.service";
import { Configuration } from "../configuration/entities/configuration.entity";
import { Team } from "../team/entities/team.entity";
import { TeamService } from "../team/team.service";
import { OfficerTeamXrefService } from "../officer_team_xref/officer_team_xref.service";
import { OfficerTeamXref } from "../officer_team_xref/entities/officer_team_xref.entity";

describe("OfficerController", () => {
let controller: OfficerController;
Expand All @@ -35,6 +39,16 @@ describe("OfficerController", () => {
provide: getRepositoryToken(Office),
useValue: {},
},
TeamService,
{
provide: getRepositoryToken(Team),
useValue: {},
},
OfficerTeamXrefService,
{
provide: getRepositoryToken(OfficerTeamXref),
useValue: {},
},
{
provide: DataSource,
useFactory: dataSourceMockFactory,
Expand Down
10 changes: 8 additions & 2 deletions backend/src/v1/officer/officer.controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards, Put } from "@nestjs/common";
import { OfficerService } from "./officer.service";
import { CreateOfficerDto } from "./dto/create-officer.dto";
import { UpdateOfficerDto } from "./dto/update-officer.dto";
import { Roles } from "../../auth/decorators/roles.decorator";
import { Role } from "../../enum/role.enum";
Expand All @@ -9,6 +8,7 @@ import { ApiTags } from "@nestjs/swagger";
import { UUID } from "crypto";
import { User } from "../../auth/decorators/user.decorator";
import { Token } from "../../auth/decorators/token.decorator";
import { NewOfficer } from "../../types/models/people/officer";

@ApiTags("officer")
@UseGuards(JwtRoleGuard)
Expand All @@ -21,7 +21,7 @@ export class OfficerController {

@Post()
@Roles(Role.COS_OFFICER)
create(@Body() createOfficerDto: CreateOfficerDto) {
create(@Body() createOfficerDto: NewOfficer) {
return this.officerService.create(createOfficerDto);
}

Expand Down Expand Up @@ -61,6 +61,12 @@ export class OfficerController {
return this.officerService.findByPersonGuid(person_guid);
}

@Get("/find-by-email/:email")
@Roles(Role.TEMPORARY_TEST_ADMIN)
findUserByEmail(@Param("email") email: string) {
return this.officerService.findByCssEmail(email);
}

@Patch(":id")
@Roles(Role.COS_OFFICER, Role.CEEB, Role.TEMPORARY_TEST_ADMIN)
update(@Param("id") id: UUID, @Body() updateOfficerDto: UpdateOfficerDto) {
Expand Down
10 changes: 8 additions & 2 deletions backend/src/v1/officer/officer.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ import { TypeOrmModule } from "@nestjs/typeorm";
import { Officer } from "./entities/officer.entity";
import { Person } from "../person/entities/person.entity";
import { Office } from "../office/entities/office.entity";
import { CssModule } from "src/external_api/css/css.module";
import { CssModule } from "../../external_api/css/css.module";
import { TeamService } from "../team/team.service";
import { Team } from "../team/entities/team.entity";
import { OfficerTeamXref } from "../officer_team_xref/entities/officer_team_xref.entity";
import { OfficerTeamXrefService } from "../officer_team_xref/officer_team_xref.service";

@Module({
imports: [
TypeOrmModule.forFeature([Officer]),
TypeOrmModule.forFeature([Person]),
TypeOrmModule.forFeature([Office]),
TypeOrmModule.forFeature([Team]),
TypeOrmModule.forFeature([OfficerTeamXref]),
CssModule,
],
controllers: [OfficerController],
providers: [OfficerService, PersonService, OfficeService],
providers: [OfficerService, PersonService, OfficeService, TeamService, OfficerTeamXrefService],
exports: [OfficerService],
})
export class OfficerModule {}
Loading
Loading