generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: CE-976 Admin screen for CEEB (#605)
Co-authored-by: Barrett Falk <[email protected]> Co-authored-by: gregorylavery <[email protected]> Co-authored-by: Mike <[email protected]> Co-authored-by: dmitri-korin-bcps <[email protected]> Co-authored-by: Mike Sears <[email protected]>
- Loading branch information
1 parent
1cac931
commit b072e01
Showing
57 changed files
with
1,907 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const hasRole = (req, role: string) => { | ||
const userroles = req.user.client_roles; | ||
const hasRole = userroles?.includes(role); | ||
return hasRole; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
export enum Role { | ||
COS_OFFICER = "COS Officer", | ||
COS_ADMIN = "COS Admin", | ||
COS_ADMINISTRATOR = "COS Administrator", | ||
CEEB = "CEEB", | ||
CEEB_COMPLIANCE_COORDINATOR = "CEEB Compliance Coordinator", | ||
CEEB_SECTION_HEAD = "CEEB Section Head", | ||
TEMPORARY_TEST_ADMIN = "TEMPORARY_TEST_ADMIN", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Module } from "@nestjs/common"; | ||
import { CssService } from "./css.service"; | ||
import { ConfigurationModule } from "../../v1/configuration/configuration.module"; | ||
|
||
@Module({ | ||
imports: [ConfigurationModule], | ||
providers: [CssService], | ||
exports: [CssService], | ||
}) | ||
export class CssModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { getRepositoryToken } from "@nestjs/typeorm"; | ||
import { ConfigurationService } from "../../v1/configuration/configuration.service"; | ||
import { Configuration } from "../../v1/configuration/entities/configuration.entity"; | ||
import { CssService } from "./css.service"; | ||
|
||
describe("CssService", () => { | ||
let service: CssService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
CssService, | ||
ConfigurationService, | ||
{ | ||
provide: getRepositoryToken(Configuration), | ||
useValue: {}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
service = module.get<CssService>(CssService); | ||
}); | ||
|
||
it("should be defined", () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import { Inject, Injectable, Logger } from "@nestjs/common"; | ||
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"; | ||
|
||
@Injectable() | ||
export class CssService implements ExternalApiService { | ||
private readonly logger = new Logger(CssService.name); | ||
|
||
readonly authApi: string; | ||
readonly baseUri: string; | ||
readonly clientId: string; | ||
readonly clientSecret: string; | ||
readonly grantType: string; | ||
readonly env: string; | ||
|
||
@Inject(ConfigurationService) | ||
readonly configService: ConfigurationService; | ||
|
||
constructor() { | ||
this.authApi = process.env.CSS_TOKEN_URL; | ||
this.baseUri = process.env.CSS_URL; | ||
this.clientId = process.env.CSS_CLIENT_ID; | ||
this.clientSecret = process.env.CSS_CLIENT_SECRET; | ||
this.grantType = "client_credentials"; | ||
this.env = process.env.ENVIRONMENT; | ||
} | ||
|
||
authenticate = async (): Promise<string> => { | ||
const response: AxiosResponse = await axios.post( | ||
this.authApi, | ||
{ | ||
client_id: this.clientId, | ||
client_secret: this.clientSecret, | ||
grant_type: this.grantType, | ||
}, | ||
{ | ||
headers: { | ||
"Content-Type": "application/x-www-form-urlencoded", | ||
}, | ||
}, | ||
); | ||
return response?.data?.access_token; | ||
}; | ||
|
||
getUserIdirByName = async (firstName, lastName): Promise<AxiosResponse> => { | ||
try { | ||
const apiToken = await this.authenticate(); | ||
const url = `${this.baseUri}/api/v1/${this.env}/idir/users?firstName=${firstName}&lastName=${lastName}`; | ||
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: ${firstName} ${lastName} - error: ${error}`); | ||
throw new Error(`exception: unable to get user: ${firstName} ${lastName} - error: ${error}`); | ||
} | ||
}; | ||
|
||
getUserRoles = async (userIdir): Promise<{ name: string; composite: string }[]> => { | ||
try { | ||
const apiToken = await this.authenticate(); | ||
const url = `${this.baseUri}/api/v1/integrations/4794/${this.env}/users/${userIdir}/roles`; | ||
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's roles ${userIdir} - error: ${error}`); | ||
throw new Error(`exception: unable to get user's roles ${userIdir} - error: ${error}`); | ||
} | ||
}; | ||
|
||
updateUserRole = async (userIdir, userRoles): Promise<{ name: string; composite: string }[]> => { | ||
try { | ||
const apiToken = await this.authenticate(); | ||
const url = `${this.baseUri}/api/v1/integrations/4794/${this.env}/users/${userIdir}/roles`; | ||
const config: AxiosRequestConfig = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${apiToken}`, | ||
}, | ||
}; | ||
const response = await axios.post(url, userRoles, config); | ||
return response?.data.data; | ||
} catch (error) { | ||
this.logger.error(`exception: unable to update user's roles ${userIdir} - error: ${error}`); | ||
throw new Error(`exception: unable to update user's roles ${userIdir} - error: ${error}`); | ||
} | ||
}; | ||
|
||
deleteUserRole = async (userIdir, roleName): Promise<AxiosResponse> => { | ||
try { | ||
const apiToken = await this.authenticate(); | ||
const url = `${this.baseUri}/api/v1/integrations/4794/${this.env}/users/${userIdir}/roles/${roleName}`; | ||
const config: AxiosRequestConfig = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${apiToken}`, | ||
}, | ||
}; | ||
const response = await axios.delete(url, config); | ||
return response?.data.data; | ||
} catch (error) { | ||
this.logger.error(`exception: unable to delete user's role ${userIdir} - error: ${error}`); | ||
throw new Error(`exception: unable to delete user's role ${userIdir} - error: ${error}`); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { BaseCodeTable } from "./code-table"; | ||
|
||
export interface TeamType extends BaseCodeTable { | ||
team: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.