Skip to content

Commit

Permalink
Show username in user role dropdown
Browse files Browse the repository at this point in the history
The options in the dropdown for selecting a user in the
access policy tab would show the user role
(aka the thing actually being selected) instead of
the user information like in the input field.
This fixes that.

Also adds some sensible fallbacks in case someone
decides to have users without names.
  • Loading branch information
Arnei committed Dec 19, 2024
1 parent 487ce13 commit 4c5edf0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
31 changes: 18 additions & 13 deletions src/components/shared/modals/ResourceDetailsAccessPolicyTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,6 @@ export const AccessPolicyTable = <T extends AccessPolicyTabFormikProps>({

const user = useAppSelector(state => getUserInformation(state));

const createPolicyLabel = (policy: TransformedAcl) => {
console.log(policy.user)
if (policy.user) {
if (policy.user.email !== undefined && policy.user.email !== "") {
return policy.user.name + " <" + policy.user.email + ">"
}
return policy.user.name
} else {
return policy.role
}
}

const createPolicy = (role: string, withUser: boolean): TransformedAcl => {
let user = withUser ? {username: "", name: "", email: ""} : undefined

Expand Down Expand Up @@ -769,4 +757,21 @@ export const TemplateSelector = <T extends TemplateSelectorProps>({
</div>
</div>
)
}
}

export const createPolicyLabel = (policy: TransformedAcl) => {
if (policy.user) {
if (policy.user.email !== undefined && policy.user.email !== "") {
return policy.user.name + " <" + policy.user.email + ">"
}
if (policy.user.name) {
return policy.user.name
}
if (policy.user.username) {
return policy.user.username
}
return policy.role
} else {
return policy.role
}
}
10 changes: 9 additions & 1 deletion src/utils/dropDownUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TFunction } from "i18next";
import { DropDownType } from './../components/shared/DropDown';
import { isJson } from "./utils";
import { createPolicyLabel } from "../components/shared/modals/ResourceDetailsAccessPolicyTab";
/*
* this file contains functions, which are needed for the searchable drop-down selections
*/
Expand Down Expand Up @@ -85,13 +86,20 @@ export const formatDropDownOptions = (
label: item.name,
});
}
} else if (type === "captureAgent" || type === "aclRole") {
} else if (type === "captureAgent") {
for (const item of unformattedOptions) {
formattedOptions.push({
value: item.name,
label: item.name,
});
}
} else if (type === "aclRole") {
for (const item of unformattedOptions) {
formattedOptions.push({
value: item.name,
label: createPolicyLabel(item) ? createPolicyLabel(item) : item.name,
});
}
} else if (type === "workflow") {
for (const item of unformattedOptions) {
formattedOptions.push({
Expand Down

0 comments on commit 4c5edf0

Please sign in to comment.