Disable create service account button if no policy (#1006)
* disable button if no policies * merge fix * finding group policies * fixing style Co-authored-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> Co-authored-by: Adam Stafford <adamstafford@Adams-MacBook-Pro.local> Co-authored-by: Alex <33497058+bexsoft@users.noreply.github.com>
This commit is contained in:
@@ -37,6 +37,9 @@ type User struct {
|
||||
// access key
|
||||
AccessKey string `json:"accessKey,omitempty"`
|
||||
|
||||
// has policy
|
||||
HasPolicy bool `json:"hasPolicy,omitempty"`
|
||||
|
||||
// member of
|
||||
MemberOf []string `json:"memberOf"`
|
||||
|
||||
|
||||
@@ -151,6 +151,7 @@ const UserDetails = ({ classes, match }: IUserDetailsProps) => {
|
||||
const [changeUserPasswordModalOpen, setChangeUserPasswordModalOpen] =
|
||||
useState<boolean>(false);
|
||||
const [deleteOpen, setDeleteOpen] = useState<boolean>(false);
|
||||
const [hasPolicy, setHasPolicy] = useState<boolean>(false);
|
||||
|
||||
const userName = match.params["userName"];
|
||||
|
||||
@@ -188,6 +189,7 @@ const UserDetails = ({ classes, match }: IUserDetailsProps) => {
|
||||
}
|
||||
setCurrentPolicies(currentPolicies);
|
||||
setEnabled(res.status === "enabled");
|
||||
setHasPolicy(res.hasPolicy)
|
||||
setLoading(false);
|
||||
})
|
||||
.catch((err: ErrorResponseHandler) => {
|
||||
@@ -382,7 +384,7 @@ const UserDetails = ({ classes, match }: IUserDetailsProps) => {
|
||||
/>
|
||||
</TabPanel>
|
||||
<TabPanel index={1} value={curTab}>
|
||||
<UserServiceAccountsPanel user={userName} classes={classes} />
|
||||
<UserServiceAccountsPanel user={userName} classes={classes} hasPolicy={hasPolicy} />
|
||||
</TabPanel>
|
||||
<TabPanel index={2} value={curTab}>
|
||||
<div className={classes.actionsTray}>
|
||||
|
||||
@@ -38,6 +38,7 @@ interface IUserServiceAccountsProps {
|
||||
classes: any;
|
||||
user: string;
|
||||
setErrorSnackMessage: typeof setErrorSnackMessage;
|
||||
hasPolicy: boolean;
|
||||
}
|
||||
|
||||
const styles = (theme: Theme) =>
|
||||
@@ -53,6 +54,7 @@ const UserServiceAccountsPanel = ({
|
||||
classes,
|
||||
user,
|
||||
setErrorSnackMessage,
|
||||
hasPolicy,
|
||||
}: IUserServiceAccountsProps) => {
|
||||
const [records, setRecords] = useState<string[]>([]);
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
@@ -75,7 +77,6 @@ const UserServiceAccountsPanel = ({
|
||||
.invoke("GET", `/api/v1/user/${user}/service-accounts`)
|
||||
.then((res: string[]) => {
|
||||
const serviceAccounts = res.sort(stringSort);
|
||||
|
||||
setLoading(false);
|
||||
setRecords(serviceAccounts);
|
||||
})
|
||||
@@ -169,6 +170,7 @@ const UserServiceAccountsPanel = ({
|
||||
setAddScreenOpen(true);
|
||||
setSelectedServiceAccount(null);
|
||||
}}
|
||||
disabled={!hasPolicy}
|
||||
>
|
||||
Create service account
|
||||
</Button>
|
||||
|
||||
@@ -281,11 +281,35 @@ func getUserInfoResponse(session *models.Principal, params admin_api.GetUserInfo
|
||||
return nil, prepareError(err)
|
||||
}
|
||||
|
||||
var policies []string
|
||||
if user.PolicyName == "" {
|
||||
policies = []string{}
|
||||
} else {
|
||||
policies = strings.Split(user.PolicyName, ",")
|
||||
}
|
||||
|
||||
hasPolicy := true
|
||||
|
||||
if len(policies) == 0 {
|
||||
hasPolicy = false
|
||||
for i := 0; i < len(user.MemberOf); i++ {
|
||||
group, err := adminClient.getGroupDescription(ctx, user.MemberOf[i])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if group.Policy != "" {
|
||||
hasPolicy = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
userInformation := &models.User{
|
||||
AccessKey: params.Name,
|
||||
MemberOf: user.MemberOf,
|
||||
Policy: strings.Split(user.PolicyName, ","),
|
||||
Policy: policies,
|
||||
Status: string(user.Status),
|
||||
HasPolicy: hasPolicy,
|
||||
}
|
||||
|
||||
return userInformation, nil
|
||||
|
||||
@@ -5454,6 +5454,9 @@ func init() {
|
||||
"accessKey": {
|
||||
"type": "string"
|
||||
},
|
||||
"hasPolicy": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"memberOf": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
@@ -11049,6 +11052,9 @@ func init() {
|
||||
"accessKey": {
|
||||
"type": "string"
|
||||
},
|
||||
"hasPolicy": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"memberOf": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
||||
@@ -2485,6 +2485,9 @@ definitions:
|
||||
type: string
|
||||
status:
|
||||
type: string
|
||||
hasPolicy:
|
||||
type: boolean
|
||||
|
||||
listUsersResponse:
|
||||
type: object
|
||||
properties:
|
||||
|
||||
Reference in New Issue
Block a user