Skip to content

Commit

Permalink
Adapt field permissions in 'Identity settings'
Browse files Browse the repository at this point in the history
Field permissions have been provided to the
fields of the 'Identity settings' section.

This has been implemented by defining a
new endpoint in the `rpc.ts` file. The
data has been retrieved from a custom hook
that is used in the `ActiveUsersTabs`,
`StageUsersTabs`, and `PreservedUsersTabs`
components.

Finally, the `user` data in the `UserSettings`
components has been replaced by the new
`userData` from the API call.

Signed-off-by: Carla Martinez <[email protected]>
  • Loading branch information
carma12 committed Jul 17, 2023
1 parent cb766e3 commit 22d94cf
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 21 deletions.
12 changes: 10 additions & 2 deletions src/components/UserSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,17 @@ import UsersEmployeeInfo from "src/components/UsersSections/UsersEmployeeInfo";
import UsersAttributesSMB from "src/components/UsersSections/UsersAttributesSMB";

export interface PropsToUserSettings {
user: User;
user: User; // TODO: Replace with `userData` in all subsections
onUserChange: (user: User) => void;
metadata: Metadata;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
userData: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
pwPolicyData: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
krbPolicyData: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
certData: any;
from: "active-users" | "stage-users" | "preserved-users";
}

Expand Down Expand Up @@ -169,7 +177,7 @@ const UserSettings = (props: PropsToUserSettings) => {
text="Identity settings"
/>
<UsersIdentity
user={props.user}
user={props.userData}
onUserChange={props.onUserChange}
metadata={props.metadata}
/>
Expand Down
49 changes: 49 additions & 0 deletions src/hooks/useUserSettingsData.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// RPC
import {
Command,
useGetObjectMetadataQuery,
useGetUsersFullDataQuery,
} from "src/services/rpc";

const useUserSettingsData = (userId: string) => {
// [API call] Metadata
const metadataQuery = useGetObjectMetadataQuery();
const metadata = metadataQuery.data || {};
const metadataLoading = metadataQuery.isLoading;

// [API call] Users data
const userShowCommand: Command = {
method: "user_show",
params: [userId, { all: true, rights: true }],
};

const pwpolicyShowCommand: Command = {
method: "pwpolicy_show",
params: [[], { user: userId[0], all: true, rights: true }],
};

const krbtpolicyShowCommand: Command = {
method: "krbtpolicy_show",
params: [userId, { all: true, rights: true }],
};

const certFindCommand: Command = {
method: "cert_find",
params: [[], { user: userId[0], sizelimit: 0, all: true }],
};

const batchPayload: Command[] = [
userShowCommand,
pwpolicyShowCommand,
krbtpolicyShowCommand,
certFindCommand,
];

const batchQuery = useGetUsersFullDataQuery(batchPayload);
const batchResponse = batchQuery.data || {};
const isBatchLoading = batchQuery.isLoading;

return { metadata, metadataLoading, batchResponse, isBatchLoading };
};

export default useUserSettingsData;
16 changes: 10 additions & 6 deletions src/pages/ActiveUsers/ActiveUsersTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import UserMemberOf from "./UserMemberOf";
// Layouts
import BreadcrumbLayout from "src/components/layouts/BreadcrumbLayout";
import DataSpinner from "src/components/layouts/DataSpinner";
// RPC client
import { useGetObjectMetadataQuery } from "src/services/rpc";
// Hooks
import useUserSettingsData from "src/hooks/useUserSettingsData";

const ActiveUsersTabs = () => {
// Get location (React Router DOM) and get state data
Expand All @@ -33,9 +33,9 @@ const ActiveUsersTabs = () => {

const [user, setUser] = useState<User>(userData);

const metadataQuery = useGetObjectMetadataQuery();
const metadata = metadataQuery.data || {};
const metadataLoading = metadataQuery.isLoading;
// Make API calls needed for user Settings' data
const { metadata, metadataLoading, batchResponse, isBatchLoading } =
useUserSettingsData(userData.uid);

// Tab
const [activeTabKey, setActiveTabKey] = useState(0);
Expand All @@ -56,7 +56,7 @@ const ActiveUsersTabs = () => {
},
];

if (metadataLoading) {
if (metadataLoading || isBatchLoading) {
return <DataSpinner />;
}

Expand Down Expand Up @@ -91,6 +91,10 @@ const ActiveUsersTabs = () => {
<UserSettings
user={user}
metadata={metadata}
userData={batchResponse[0].result}
pwPolicyData={batchResponse[1].result}
krbPolicyData={batchResponse[2].result}
certData={batchResponse[3].result}
onUserChange={setUser}
from="active-users"
/>
Expand Down
16 changes: 10 additions & 6 deletions src/pages/PreservedUsers/PreservedUsersTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import UserSettings from "src/components/UserSettings";
// Layouts
import BreadcrumbLayout from "src/components/layouts/BreadcrumbLayout";
import DataSpinner from "src/components/layouts/DataSpinner";
// RPC client
import { useGetObjectMetadataQuery } from "src/services/rpc";
// Hooks
import useUserSettingsData from "src/hooks/useUserSettingsData";

const PreservedUsersTabs = () => {
// Get location (React Router DOM) and get state data
Expand All @@ -32,9 +32,9 @@ const PreservedUsersTabs = () => {

const [user, setUser] = useState<User>(userData);

const metadataQuery = useGetObjectMetadataQuery();
const metadata = metadataQuery.data || {};
const metadataLoading = metadataQuery.isLoading;
// Make API calls needed for user Settings' data
const { metadata, metadataLoading, batchResponse, isBatchLoading } =
useUserSettingsData(userData.uid);

// Tab
const [activeTabKey, setActiveTabKey] = useState(0);
Expand All @@ -55,7 +55,7 @@ const PreservedUsersTabs = () => {
},
];

if (metadataLoading) {
if (metadataLoading || isBatchLoading) {
return <DataSpinner />;
}

Expand Down Expand Up @@ -90,6 +90,10 @@ const PreservedUsersTabs = () => {
<UserSettings
user={user}
metadata={metadata}
userData={batchResponse[0].result}
pwPolicyData={batchResponse[1].result}
krbPolicyData={batchResponse[2].result}
certData={batchResponse[3].result}
onUserChange={setUser}
from="preserved-users"
/>
Expand Down
16 changes: 10 additions & 6 deletions src/pages/StageUsers/StageUsersTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import UserSettings from "src/components/UserSettings";
// Layouts
import BreadcrumbLayout from "src/components/layouts/BreadcrumbLayout";
import DataSpinner from "src/components/layouts/DataSpinner";
// RPC client
import { useGetObjectMetadataQuery } from "src/services/rpc";
// Hooks
import useUserSettingsData from "src/hooks/useUserSettingsData";

const StageUsersTabs = () => {
// Get location (React Router DOM) and get state data
Expand All @@ -32,9 +32,9 @@ const StageUsersTabs = () => {

const [user, setUser] = useState<User>(userData);

const metadataQuery = useGetObjectMetadataQuery();
const metadata = metadataQuery.data || {};
const metadataLoading = metadataQuery.isLoading;
// Make API calls needed for user Settings' data
const { metadata, metadataLoading, batchResponse, isBatchLoading } =
useUserSettingsData(userData.uid);

// Tab
const [activeTabKey, setActiveTabKey] = useState(0);
Expand All @@ -55,7 +55,7 @@ const StageUsersTabs = () => {
},
];

if (metadataLoading) {
if (metadataLoading || isBatchLoading) {
return <DataSpinner />;
}

Expand Down Expand Up @@ -90,6 +90,10 @@ const StageUsersTabs = () => {
<UserSettings
user={user}
metadata={metadata}
userData={batchResponse[0].result}
pwPolicyData={batchResponse[1].result}
krbPolicyData={batchResponse[2].result}
certData={batchResponse[3].result}
onUserChange={setUser}
from="stage-users"
/>
Expand Down
24 changes: 23 additions & 1 deletion src/services/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ export interface ShowRPCResponse {
result: Record<string, unknown>;
}

export interface BatchResult {
result: Record<string, unknown>;
count: number;
truncated: boolean;
summary: string;
}

export interface BatchResponse {
result: {
results: BatchResult[];
};
}

// 'FindRPCResponse' type
// - Has 'result' > 'result' structure
export interface FindRPCResponse {
Expand Down Expand Up @@ -117,7 +130,7 @@ export const getBatchCommand = (commandData: Command[], apiVersion: string) => {
export const api = createApi({
reducerPath: "api",
baseQuery: fetchBaseQuery({ baseUrl: "/" }), // TODO: Global settings!
tagTypes: ["ObjectMetadata"],
tagTypes: ["ObjectMetadata", "FullUserData"],
endpoints: (build) => ({
simpleCommand: build.query<FindRPCResponse, Command | void>({
query: (payloadData: Command) => getCommand(payloadData),
Expand Down Expand Up @@ -217,6 +230,14 @@ export const api = createApi({
response.result,
providesTags: ["ObjectMetadata"],
}),
getUsersFullData: build.query<BatchResult[], Command[]>({
query: (payloadData: Command[], apiVersion?: string) => {
return getBatchCommand(payloadData, apiVersion || API_VERSION_BACKUP);
},
transformResponse: (response: BatchResponse): BatchResult[] =>
response.result.results,
providesTags: ["FullUserData"],
}),
}),
});

Expand All @@ -227,4 +248,5 @@ export const {
useBatchMutCommandMutation,
useGettingUserDataQuery,
useGetObjectMetadataQuery,
useGetUsersFullDataQuery,
} = api;

0 comments on commit 22d94cf

Please sign in to comment.