Skip to content

Commit 74ba469

Browse files
committed
Adjustments from PR feedback
1 parent f620b5c commit 74ba469

File tree

11 files changed

+472
-99
lines changed

11 files changed

+472
-99
lines changed

server/src/main/java/com/objectcomputing/checkins/services/permissions/Permission.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class Permission {
3838
@Schema(description = "A more verbose description of the permission to be displayed on UI")
3939
private String description;
4040

41+
public Permission() {}
42+
4143
public Permission(UUID id, String permission, @Nullable String description) {
4244
this.id = id;
4345
this.permission = permission;
@@ -64,7 +66,7 @@ public String getDescription() {
6466
return Permissions.valueOf(permission).getDescription(); //ignoring the database for now...
6567
}
6668

67-
public void setDescription(String description) {
69+
public void setDescription(@Nullable String description) {
6870
this.description = description;
6971
}
7072

web-ui/src/api/rolepermissions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const getRolePermissionsList = async (cookie) => {
1010
});
1111
};
1212

13-
export const postRolePermissionsList = async (roleData, cookie) => {
13+
export const postRolePermission = async (roleData, cookie) => {
1414
return resolve({
1515
method: "post",
1616
url: rolePermissionsListUrl,
@@ -20,7 +20,7 @@ export const postRolePermissionsList = async (roleData, cookie) => {
2020
});
2121
};
2222

23-
export const deleteRolePermissionsList = async (roleData, cookie) => {
23+
export const deleteRolePermission = async (roleData, cookie) => {
2424
return resolve({
2525
method: "delete",
2626
url: rolePermissionsListUrl,

web-ui/src/api/roles.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ export const getAllUserRoles = async (cookie) => {
1919
});
2020
};
2121

22-
export const getCurrentUserRole = async (memberId, cookie) => {
23-
return resolve({
24-
url: `${roleURL}/${memberId}`,
25-
responseType: "json",
26-
headers: { "X-CSRF-Header": cookie },
27-
});
28-
};
29-
3022
export const removeUserFromRole = async (roleId, memberId, cookie) => {
3123
return resolve({
3224
method: "delete",

web-ui/src/components/menu/Menu.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ const Root = styled('div')(({theme}) => ({
9595
}));
9696

9797
const adminLinks = [
98-
// ["/admin/permissions", "Permissions"],
9998
["/admin/permissions", "Permissions"],
10099
["/admin/roles", "Roles"],
101100
["/admin/users", "Users"],

web-ui/src/context/actions.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ export const ADD_CHECKIN = "@@check-ins/add_checkin";
22
export const ADD_GUILD = "@@check-ins/add_guild";
33
export const ADD_MEMBER_SKILL = "@@check-ins/add_member_skill";
44
export const ADD_SKILL = "@@check-ins/add-skill";
5-
export const ADD_PERMISSION = "@@check-ins/add-permission";
65
export const ADD_TEAM = "@@check-ins/add_team";
76
export const DELETE_MEMBER_PROFILE = "@@check-ins/delete_member_profile";
87
export const DELETE_MEMBER_SKILL = "@@check-ins/delete_member_skill";
98
export const DELETE_SKILL = "@@check-ins/delete-skill";
10-
export const DELETE_PERMISSION = "@@check-ins/delete-permission";
119
export const DELETE_ROLE = "@@check-ins/delete-role";
1210
export const MY_PROFILE_UPDATE = "@@check-ins/update_profile";
1311
export const SET_CSRF = "@@check-ins/update_csrf";
@@ -23,7 +21,6 @@ export const UPDATE_MEMBER_SKILLS = "@@check-ins/update_member_skills";
2321
export const UPDATE_ROLES = "@@check-ins/update_roles";
2422
export const UPDATE_SKILL = "@@check-ins/update_skill";
2523
export const UPDATE_SKILLS = "@@check-ins/update_skills";
26-
export const UPDATE_PERMISSION = "@@check-ins/update-permission";
2724
export const UPDATE_TEAM_MEMBERS = "@@check-ins/update_team_members";
2825
export const UPDATE_TEAMS = "@@check-ins/update_teams";
2926
export const UPDATE_TERMINATED_MEMBERS =

web-ui/src/helpers/checks.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,6 @@
66

77
export const isArrayPresent = (arr) => Array.isArray(arr) && arr.length;
88

9-
/**
10-
* Check for whether unique object is already in an array and return a boolean.
11-
* @param arr - an array
12-
* @returns a boolean
13-
*/
14-
export const isObjectInArray = (arr, obj) => {
15-
return arr.includes(obj);
16-
};
17-
189
/**
1910
* If a parameter is found in an object within an array, return the array with just that object.
2011
* @param arr - an array

web-ui/src/pages/EditPermissionsPage.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import EditPermissionsPageRoles from "./EditPermissionsPageRoles";
55
import { getPermissionsList } from "../api/permissions";
66
import {
77
getRolePermissionsList,
8-
postRolePermissionsList,
9-
deleteRolePermissionsList,
8+
postRolePermission,
9+
deleteRolePermission,
1010
} from "../api/rolepermissions";
1111
import { getMemberRolesList } from "../api/memberroles";
1212
import { isArrayPresent, filterObjectByValOrKey } from "../helpers/checks";
@@ -216,7 +216,7 @@ const EditPermissionsPage = () => {
216216

217217
const changeRolePermission = async (roleId, permissionId) => {
218218
let newSchema = { roleId: roleId, permissionId: permissionId };
219-
let res = await postRolePermissionsList(newSchema, csrf);
219+
let res = await postRolePermission(newSchema, csrf);
220220
let data =
221221
res.payload && res.payload.data && !res.error ? res.payload.data : null;
222222
if (data) {
@@ -241,7 +241,7 @@ const EditPermissionsPage = () => {
241241

242242
const deleteRolePermission = async (roleId, permissionId) => {
243243
let newSchema = { roleId: roleId, permissionId: permissionId };
244-
let res = await deleteRolePermissionsList(newSchema, csrf);
244+
let res = await deleteRolePermission(newSchema, csrf);
245245
let data = !res.error ? "Success" : null;
246246
if (data) {
247247
window.snackDispatch({

web-ui/src/pages/EditSkillsPage.css

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,3 @@
2525
display: flex;
2626
margin-top: 1rem;
2727
}
28-
29-
.edit-permissions {
30-
display: block;
31-
float: left;
32-
position: relative;
33-
width: auto;
34-
margin: 2%;
35-
}

web-ui/src/pages/PermissionsPage.jsx

Lines changed: 41 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import React, { useEffect, useContext, useState } from "react";
33
import { getPermissionsList } from "../api/permissions";
44
import {
55
getRolePermissionsList,
6-
postRolePermissionsList,
7-
deleteRolePermissionsList,
6+
postRolePermission,
7+
deleteRolePermission,
88
} from "../api/rolepermissions";
9-
import { Checkbox } from "@mui/material";
9+
import { Checkbox, FormControl, MenuItem, Select, InputLabel } from "@mui/material";
1010
import { UPDATE_TOAST } from "../context/actions";
1111
import { AppContext } from "../context/AppContext";
1212
import { selectRoles, selectHasPermissionAssignmentPermission } from "../context/selectors";
@@ -101,59 +101,36 @@ const EditPermissionsPage = () => {
101101
setSelectedRole(roles.find((role) => role.id === event.target.value));
102102
};
103103

104-
const addRolePermission = async (roleId, permissionId) => {
105-
let newSchema = { roleId: roleId, permissionId: permissionId };
106-
let res = await postRolePermissionsList(newSchema, csrf);
107-
let data =
108-
res.payload && res.payload.data && !res.error ? res.payload.data : null;
109-
if (data) {
110-
window.snackDispatch({
111-
type: UPDATE_TOAST,
112-
payload: {
113-
severity: "success",
114-
toast: `Permission added to Role`,
115-
},
116-
});
117-
} else {
118-
window.snackDispatch({
119-
type: UPDATE_TOAST,
120-
payload: {
121-
severity: "warning",
122-
toast: `Problem changing permission for that role`,
123-
},
124-
});
125-
}
104+
const addPermissionForRole = async (role, permission) => {
105+
let newSchema = { roleId: role.id, permissionId: permission.id };
106+
let res = await postRolePermission(newSchema, csrf);
107+
const snackPayload = res.error
108+
? { severity: "warning", toast: `Problem adding ${permission.description} to ${role.role}` }
109+
: { severity: "success", toast: `${permission.description} added to ${role.role}` };
110+
window.snackDispatch({
111+
type: UPDATE_TOAST,
112+
payload: snackPayload,
113+
});
126114
};
127115

128-
const deleteRolePermission = async (roleId, permissionId) => {
129-
let newSchema = { roleId: roleId, permissionId: permissionId };
130-
let res = await deleteRolePermissionsList(newSchema, csrf);
131-
let data = !res.error ? "Success" : null;
132-
if (data) {
133-
window.snackDispatch({
134-
type: UPDATE_TOAST,
135-
payload: {
136-
severity: "success",
137-
toast: `Permission removed from Role`,
138-
},
139-
});
140-
} else {
141-
window.snackDispatch({
142-
type: UPDATE_TOAST,
143-
payload: {
144-
severity: "warning",
145-
toast: `Problem deleting permission for that role`,
146-
},
147-
});
148-
}
116+
const deletePermissionForRole = async (role, permission) => {
117+
let newSchema = { roleId: role.id, permissionId: permission.id };
118+
let res = await deleteRolePermission(newSchema, csrf);
119+
const snackPayload = res.error
120+
? { severity: "warning", toast: `Problem deleting ${permission.description} from ${role.role}` }
121+
: { severity: "success", toast: `${permission.description} removed from ${role.role}` };
122+
window.snackDispatch({
123+
type: UPDATE_TOAST,
124+
payload: snackPayload,
125+
});
149126
};
150127

151-
const handleChange = async (event, roleId, permissionId) => {
128+
const handleChange = async (event, role, permission) => {
152129
if (event?.target?.checked) {
153-
await addRolePermission(roleId, permissionId);
130+
await addPermissionForRole(role, permission);
154131
setRefresh(!refresh);
155132
} else {
156-
await deleteRolePermission(roleId, permissionId);
133+
await deletePermissionForRole(role, permission);
157134
setRefresh(!refresh);
158135
}
159136
};
@@ -164,15 +141,20 @@ const EditPermissionsPage = () => {
164141
(
165142
<>
166143
<div>
167-
<label htmlFor="role">Select Role:</label>
168-
<select id="role" value={selectedRole?.id || ''} onChange={handleRoleChange}>
169-
<option value="">-- Please Select --</option>
170-
{roles?.map((role) => (
171-
<option key={role.id} value={role.id}>
172-
{role.role} - {role.description}
173-
</option>
174-
))}
175-
</select>
144+
<FormControl>
145+
<InputLabel id="select-role-label">Select Role</InputLabel>
146+
<Select
147+
labelId="select-role-label"
148+
label="Select Role"
149+
value={selectedRole?.id || ''}
150+
onChange={handleRoleChange}
151+
>
152+
<MenuItem value="">-- Please Select --</MenuItem>
153+
{roles?.map((role) => (
154+
<MenuItem key={role.id} value={role.id}>{role.role} - {role.description}</MenuItem>
155+
))}
156+
</Select>
157+
</FormControl>
176158
</div>
177159

178160
{ selectedRole && rolePermissions && categoriesList?.map((category) => (
@@ -184,7 +166,7 @@ const EditPermissionsPage = () => {
184166
permission={permission.permission}
185167
title={permission.description}
186168
enabled={isPermissionEnabled(rolePermissions, permission)}
187-
onChange={(event) => handleChange(event, selectedRole?.id, permission.id, csrf)} />
169+
onChange={(event) => handleChange(event, selectedRole, permission)} />
188170
))
189171
}
190172
</div>

web-ui/src/pages/PermissionsPage.test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,28 @@ import React from "react";
22
import PermissionsPage from "./PermissionsPage";
33
import { AppContextProvider } from "../context/AppContext";
44

5+
const initialState = {
6+
state: {
7+
userProfile: {
8+
name: "holmes",
9+
role: ["PDL"],
10+
permissions: [{permission:"CAN_ASSIGN_ROLE_PERMISSIONS"}],
11+
imageUrl:
12+
"https://upload.wikimedia.org/wikipedia/commons/7/74/SNL_MrBill_Doll.jpg",
13+
},
14+
memberProfiles: [
15+
{
16+
id: "1234-5434-8765-3458",
17+
name: "holmes",
18+
},
19+
],
20+
index: 0,
21+
},
22+
};
23+
524
it("renders correctly", () => {
625
snapshot(
7-
<AppContextProvider>
26+
<AppContextProvider value={initialState}>
827
<PermissionsPage />
928
</AppContextProvider>
1029
);

0 commit comments

Comments
 (0)