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

Promote from main to preprod #367

Merged
merged 39 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ec9e152
refactor: Add DEFAULT to RoleToServerParksMap, renamed heading "Defau…
am-ons Jun 17, 2024
f7acfa9
fix: Updated snapshot for UTs on users component tests.
am-ons Jun 17, 2024
2f5ee75
refactor: using blaise-api-node-client v1.1.0
am-ons Jun 17, 2024
81618e8
ci: Do not fail CI build if coverage is low. Coverage will be increas…
am-ons Jun 18, 2024
738bf98
refactor: Add whitespace after comma in server parks list.
am-ons Jun 19, 2024
7b45d57
Merge pull request #352 from ONSdigital/feature/BLAIS5-4190-Add-CMA-S…
elthorne Jun 19, 2024
a2d7dbc
BLAIS5-4274 increase unit test coverage in bam (#356)
am-ons Jun 21, 2024
e2cfee2
Feature/blais5 4274 fix merge conflicts preprod and main branches (#360)
am-ons Jun 21, 2024
594bdc3
refactor: organise files into folders, rename existing folders
kristian4res Jun 30, 2024
941d1c6
feat: rework manage users UI; create dynamic user profile page for ea…
kristian4res Jun 30, 2024
3b6390c
refactor: rename utilities into api
kristian4res Jun 30, 2024
1792ef4
refactor: rename utilities into api
kristian4res Jun 30, 2024
e71b2e1
refactor: organise into folders
kristian4res Jun 30, 2024
a7eeb70
refactor: organise into folders, rename folders
kristian4res Jun 30, 2024
1892be1
test: add unit test for new page components and other existing compon…
kristian4res Jun 30, 2024
12606f9
style: yarn lint
kristian4res Jun 30, 2024
0f5a0b8
feat: react router error handling for 404s
kristian4res Jun 30, 2024
caaf2a3
chore: update route for change role
kristian4res Jun 30, 2024
5456035
chore: update route for change password
kristian4res Jun 30, 2024
b0c156c
chore: add extra point
kristian4res Jun 30, 2024
03e46d8
test: update snapshot
kristian4res Jun 30, 2024
4d342df
refactor: remove use of asyncconte and custom hook
kristian4res Jul 2, 2024
f6cf7ec
refactor: rename vars, delete comments, fix links
kristian4res Jul 2, 2024
18a8fd3
feat: add personal details header, make username as a link to user pr…
kristian4res Jul 2, 2024
9211c31
test: fix tests and check updated snapshots
kristian4res Jul 2, 2024
1bf91ab
chore: config
kristian4res Jul 2, 2024
94be54b
test: add vscode debug tool config, add jest test configs
kristian4res Jul 2, 2024
2490e15
test: update tests
kristian4res Jul 3, 2024
fc84aa7
feat: update role and serverparks; test: add backend test for blaiseAPI
kristian4res Jul 3, 2024
732400e
chore: remove unnecessary import
kristian4res Jul 3, 2024
7687e82
Removed reference branch from blaise-api-node-client in package.json
motalm Jul 5, 2024
133f65f
Merge pull request #366 from ONSdigital/BLAIS5-3816
motalm Jul 5, 2024
3b45f5b
fail_ci_if_error set to true
motalm Jul 9, 2024
4223335
fail_ci_if_error to false
motalm Jul 9, 2024
a797fdf
set it back to true again
motalm Jul 9, 2024
1991365
Merge branch 'refs/heads/main' into BLAIS5-4274-extension
lambeb Jul 9, 2024
61527d1
Merged changes from main to branch
lambeb Jul 9, 2024
8206b3b
Put test back in
lambeb Jul 9, 2024
f4447a3
Merge pull request #368 from ONSdigital/BLAIS5-4274-extension
motalm Jul 9, 2024
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
195 changes: 82 additions & 113 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,119 +1,88 @@
{
"ignorePatterns": [
"node_modules/*",
"dist/*",
"build/*"
],
"env": {
"browser": true,
"es2021": true,
"node": true
"ignorePatterns": ["node_modules/*", "dist/*", "build/*"],
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended"
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": ["react", "@typescript-eslint", "import"],
"rules": {
"object-curly-spacing": ["error", "always"],
"no-multiple-empty-lines": [
"error",
{
"max": 1
}
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"react",
"@typescript-eslint",
"import"
"no-trailing-spaces": "error",
"no-mixed-spaces-and-tabs": "error",
"linebreak-style": ["error", "unix"],
"quotes": ["error", "double"],
"semi": ["error", "always"],
"no-undef": "off",
"comma-dangle": ["error", "never"],
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": "off",
"react/react-in-jsx-scope": "off",
"react/require-default-props": "off",
"no-spaced-func": "off",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
],
"rules": {
"object-curly-spacing": ["error", "always"],
"no-multiple-empty-lines": [
"error",
{
"max": 1
}
],
"no-trailing-spaces": "error",
"no-mixed-spaces-and-tabs": "error",
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
"no-undef": "off",
"comma-dangle": [
"error",
"never"
],
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-unused-vars": "off",
"react/react-in-jsx-scope": "off",
"react/require-default-props": "off",
"no-spaced-func": "off",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": true
}
],
"max-len": [
"error",
{
"code": 200
}
],
"@typescript-eslint/no-empty-function": "off",
"indent": [
"error",
4
],
"space-in-parens": [
"error",
"never"
],
"no-multi-spaces": "error",
"comma-spacing": [
"error",
{
"before": false,
"after": true
}
],
"template-curly-spacing": [
"error",
"never"
]
},
"overrides": [
{
"files": [
"*.js"
],
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
"max-len": [
"error",
{
"code": 200
}
],
"settings": {
"react": {
"createClass": "createReactClass", // Regex for Component Factory to use,
// default to "createReactClass"
"pragma": "React", // Pragma to use, default to "React"
"fragment": "Fragment", // Fragment to use (may be a property of <pragma>), default to "Fragment"
"version": "detect", // React version. "detect" automatically picks the version you have installed.
// You can also use `16.0`, `16.3`, etc, if you want to override the detected value.
// default to latest and warns if missing
// It will default to "detect" in the future
"flowVersion": "0.53" // Flow version
}
"@typescript-eslint/no-empty-function": "off",
"indent": ["error", 4],
"space-in-parens": ["error", "never"],
"no-multi-spaces": "error",
"comma-spacing": [
"error",
{
"before": false,
"after": true
}
],
"template-curly-spacing": ["error", "never"]
},
"overrides": [
{
"files": ["*.js"],
"rules": {
"@typescript-eslint/no-var-requires": "off"
}
}
],
"settings": {
"react": {
"createClass": "createReactClass", // Regex for Component Factory to use,
// default to "createReactClass"
"pragma": "React", // Pragma to use, default to "React"
"fragment": "Fragment", // Fragment to use (may be a property of <pragma>), default to "Fragment"
"version": "detect", // React version. "detect" automatically picks the version you have installed.
// You can also use `16.0`, `16.3`, etc, if you want to override the detected value.
// default to latest and warns if missing
// It will default to "detect" in the future
"flowVersion": "0.53" // Flow version
}
}
}
}
2 changes: 1 addition & 1 deletion .github/workflows/test.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage/coverage-final.json
fail_ci_if_error: false
fail_ci_if_error: true
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest: Run all",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "Jest: Run Current Test File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand", "${relativeFile}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
process.env = Object.assign(process.env, {
BLAISE_API_URL: "http://mock",
PROJECT_ID: "mock-project",
SERVER_PARK: "mock-server-park"
SERVER_PARK: "mock-server-park",
MOCK_AUTH_TOKEN: "mock-token"
});

module.exports = {
Expand Down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"start-server": "tsc --project tsconfig.server.json && node ./dist/index.js | pino-pretty -c -t",
"start-react": "react-scripts start",
"build-react": "react-scripts --openssl-legacy-provider build",
"test": "yarn build-react && tsc --project tsconfig.server.json && jest --coverage --watchAll=false",
"rebuild-test": "yarn build-react && tsc --project tsconfig.server.json && jest --coverage --watchAll=false",
"test": "jest --coverage --watchAll=false",
"gcp-build": "yarn build-react && tsc --project tsconfig.server.json",
"lint-fix": "node_modules/.bin/eslint . --fix",
"lint": "yarn eslint .",
Expand All @@ -30,13 +31,8 @@
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^13.5.0",
"@types/express": "^4.17.8",
"@types/jest": "26.0.20",
"@types/node": "^15.12.2",
"@types/react": "^18.2.51",
"@types/react-dom": "^18.2.18",
"axios": "^1.6.1",
"blaise-api-node-client": "https://github.com/ONSdigital/blaise-api-node-client#v1.1.0",
"blaise-api-node-client": "git+https://github.com/ONSdigital/blaise-api-node-client",
"blaise-design-system-react-components": "git+https://github.com/ONSdigital/blaise-design-system-react-components#0.14.0",
"blaise-login-react": "git+https://github.com/ONSdigital/blaise-login-react#1.1.0",
"dotenv": "^10.0.0",
Expand Down Expand Up @@ -65,11 +61,16 @@
"@babel/preset-react": "^7.14.5",
"@babel/preset-typescript": "^7.14.5",
"@types/ejs": "^3.0.5",
"@types/express": "^4.17.8",
"@types/jest": "26.0.20",
"@types/lodash": "^4.14.168",
"@types/multer": "^1.4.5",
"@types/node": "^15.12.2",
"@types/number-to-words": "^1.2.0",
"@types/pino-http": "^5.4.0",
"@types/pino-pretty": "^4.7.1",
"@types/react": "^18.2.51",
"@types/react-dom": "^18.2.18",
"@types/react-router-dom": "^5.3.3",
"@types/supertest": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^6.20.0",
Expand All @@ -78,6 +79,8 @@
"concurrently": "^7.0.0",
"cross-env": "^7.0.2",
"eslint": "^8.0.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.28.0",
"eslint-plugin-react-hooks": "^4.3.0",
"pino-pretty": "^4.7.1",
Expand Down
62 changes: 60 additions & 2 deletions server/BlaiseAPI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import BlaiseApiClient from "blaise-api-node-client";

export default function BlaiseAPIRouter(config: CustomConfig, auth: Auth, blaiseApiClient: BlaiseApiClient): Router {
const router = express.Router();

router.get("/api/roles", auth.Middleware, async function (req: Request, res: Response) {
res.status(200).json(await blaiseApiClient.getUserRoles());
});
Expand All @@ -14,7 +13,66 @@ export default function BlaiseAPIRouter(config: CustomConfig, auth: Auth, blaise
res.status(200).json(await blaiseApiClient.getUsers());
});

router.get("/api/change_password/:user", auth.Middleware, async function (req: Request, res: Response) {
router.patch("/api/users/:user/rolesAndPermissions", auth.Middleware, async function (req: Request, res: Response) {
const { role } = req.body;
const user = req.params.user;
let newServerParks = [""];
let newDefaultServerPark = "";

if (!req.params.user || !req.body.role) {
return res.status(400).json("No user or role provided");
}

const roleServerParksOverride = config.RoleToServerParksMap[role];
if (roleServerParksOverride != null) {
newServerParks = roleServerParksOverride;
newDefaultServerPark = roleServerParksOverride[0];
} else {
const defaultServerPark = config.RoleToServerParksMap["DEFAULT"];
newServerParks = defaultServerPark;
newDefaultServerPark = defaultServerPark[0];
}

try {
await blaiseApiClient.changeUserRole(user, role);
await blaiseApiClient.changeUserServerParks(user, newServerParks, newDefaultServerPark);
const successMessage = `Successfully updated user role and permissions to ${role} for ${user}`;
console.log(successMessage + ` at ${(new Date()).toLocaleTimeString("en-UK")} ${(new Date()).toLocaleDateString("en-UK")}`);
return res.status(200).json({
message: successMessage + " today at " + (new Date()).toLocaleTimeString("en-UK")
});
} catch (error) {
const errorMessage = `Error whilst trying to update user role and permissions to ${role} for ${req.params.user}: ${error}`;
console.error(errorMessage);
return res.status(500).json({
message: errorMessage
});
}
});

router.get("/api/users/:user", auth.Middleware, async function (req: Request, res: Response) {
if (!req.params.user) {
return res.status(400).json("No user provided");
}

try {
const user = await blaiseApiClient.getUser(req.params.user);
const successMessage = `Successfully fetched user details for ${req.params.user}`;
return res.status(200).json({
message: successMessage,
data: user
});
} catch (error) {
const errorMessage = `Error whilst trying to retrieve user ${req.params.user}: ${error}`;
console.error(errorMessage);
return res.status(500).json({
message: errorMessage,
error: error
});
}
});

router.get("/api/change-password/:user", auth.Middleware, async function (req: Request, res: Response) {
let { password } = req.headers;

if (Array.isArray(password)) {
Expand Down
11 changes: 8 additions & 3 deletions server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,19 @@ export default function GetNodeServer(config: CustomConfig, blaiseApi: BlaiseApi
if (!fs.existsSync(indexFilePath)) {
indexFilePath = path.join(__dirname, "../public/index.html");
}

server.get("*", function (_req: Request, res: Response) {
res.render(indexFilePath);
});

server.use(function (err: Error, _req: Request, res: Response) {
console.error(err.stack);
server.use(function (err, _req, res, _next) {
if (err && err.stack) {
console.error(err.stack);
} else {
console.error("An undefined error occurred");
}
res.render("../views/500.html", {});
});

return server;
}
}
Loading
Loading