Skip to content

Commit

Permalink
staff permission data structure change(id, name)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinesh-aot committed Jan 29, 2025
1 parent a261c50 commit d5ba3d6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
13 changes: 9 additions & 4 deletions compliance-api/src/compliance_api/schemas/staff_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ class Meta(AutoSchemaBase.Meta): # pylint: disable=too-few-public-methods
include_fk = True

position = fields.Nested(KeyValueSchema, dump_only=True)
permission = fields.Str(
metadata={"description": "The permission level of the user in the app"}
)
# permission = fields.Str(
# metadata={"description": "The permission level of the user in the app"}
# )
permission = fields.Raw()
name = fields.Method("get_full_name")

def get_full_name(self, obj): # pylint: disable=no-self-use
Expand All @@ -52,7 +53,11 @@ def nullify_nested(
if data.get("supervisor_id") is None:
data["supervisor"] = None
if data.get("permission") in [p.name for p in PermissionEnum]:
data["permission"] = getattr(PermissionEnum, data.get("permission")).name
# data["permission"] = getattr(PermissionEnum, data.get("permission")).value
data["permission"] = {
"id": getattr(PermissionEnum, data.get("permission")).name,
"name": getattr(PermissionEnum, data.get("permission")).value
}
return data


Expand Down
14 changes: 11 additions & 3 deletions compliance-api/src/compliance_api/services/staff_user.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""Service for user management."""

from compliance_api.exceptions import ResourceExistsError, ResourceNotFoundError, UnprocessableEntityError
from compliance_api.exceptions import (
ResourceExistsError,
ResourceNotFoundError,
UnprocessableEntityError,
)
from compliance_api.models.db import session_scope
from compliance_api.models.staff_user import StaffUser as StaffUserModel
from compliance_api.utils.constant import AUTH_APP
Expand Down Expand Up @@ -109,7 +113,7 @@ def _create_staff_user_object(user_data: dict, auth_user: dict):
"deputy_director_id": user_data.get("deputy_director_id"),
"supervisor_id": user_data.get("supervisor_id", None),
"auth_user_guid": auth_user.get("username", None),
"is_active": auth_user.get("is_active")
"is_active": auth_user.get("is_active"),
}


Expand All @@ -129,7 +133,11 @@ def _set_permission_level_in_compliance_user_obj(
"""Set the permission level in compliance user."""
if auth_user and auth_user.get("groups", None):
sorted_groups = sorted(auth_user.get("groups", None), key=_get_level)
if sorted_groups[-1] and sorted_groups[-1]["name"]:
if (
sorted_groups[-1]
and sorted_groups[-1]["name"]
and sorted_groups[-1]["name"] in [p.name for p in PermissionEnum]
):
setattr(compliance_user, "permission", sorted_groups[-1]["name"])
return compliance_user

Expand Down
1 change: 1 addition & 0 deletions compliance-web/src/components/App/Staff/StaffForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const StaffForm: React.FC<StaffFormProps> = ({
authUsersList,
staffUsersList,
}) => {
console.log(existingStaff)

Check failure on line 25 in compliance-web/src/components/App/Staff/StaffForm.tsx

View workflow job for this annotation

GitHub Actions / linting (18.x)

Unexpected console statement
return (
<>
<ControlledAutoComplete
Expand Down
2 changes: 1 addition & 1 deletion compliance-web/src/components/App/Staff/StaffModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const StaffModal: React.FC<StaffModalProps> = ({ onSubmit, staff }) => {
undefined,
position: staff.position || undefined,
permission:
permissionsList?.find((item) => item.id === staff.permission) ||
permissionsList?.find((item) => item.id === staff.permission?.id) ||
undefined,
deputyDirector:
staffUsersList?.find(
Expand Down
2 changes: 1 addition & 1 deletion compliance-web/src/models/Staff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface StaffUser {
position_id?: number;
deputy_director_id?: number;
supervisor_id?: number;
permission?: string;
permission?: Permission;
position?: Position;
deputy_director?: StaffUser;
supervisor?: StaffUser;
Expand Down
8 changes: 3 additions & 5 deletions compliance-web/src/routes/_authenticated/admin/staff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function Staff() {
);
setPermissionList(
[
...new Set(staffUsersList?.map((staff) => staff.permission ?? "")),
...new Set(staffUsersList.map((staff) => staff.permission?.name)),
].filter(Boolean)
);
}, [staffUsersList]);
Expand Down Expand Up @@ -187,7 +187,7 @@ export function Staff() {
},
},
{
accessorKey: "permission",
accessorFn: (row) => row.permission?.name,
header: "Permission Level",
filterVariant: "multi-select",
filterSelectOptions: permissionList,
Expand Down Expand Up @@ -223,7 +223,6 @@ export function Staff() {
},
filterVariant: "multi-select",
filterSelectOptions: ["Active", "Inactive"],
filterValue: ["Active"],
Filter: ({ header, column }) => {
return (
<TableFilter
Expand Down Expand Up @@ -251,8 +250,7 @@ export function Staff() {
id: "name",
desc: false,
},
],
columnFilters: [{ id: "Status", value: ["Active"] }],
]
}}
state={{
isLoading: isLoading,
Expand Down

0 comments on commit d5ba3d6

Please sign in to comment.