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
|
// access key
|
||||||
AccessKey string `json:"accessKey,omitempty"`
|
AccessKey string `json:"accessKey,omitempty"`
|
||||||
|
|
||||||
|
// has policy
|
||||||
|
HasPolicy bool `json:"hasPolicy,omitempty"`
|
||||||
|
|
||||||
// member of
|
// member of
|
||||||
MemberOf []string `json:"memberOf"`
|
MemberOf []string `json:"memberOf"`
|
||||||
|
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ const UserDetails = ({ classes, match }: IUserDetailsProps) => {
|
|||||||
const [changeUserPasswordModalOpen, setChangeUserPasswordModalOpen] =
|
const [changeUserPasswordModalOpen, setChangeUserPasswordModalOpen] =
|
||||||
useState<boolean>(false);
|
useState<boolean>(false);
|
||||||
const [deleteOpen, setDeleteOpen] = useState<boolean>(false);
|
const [deleteOpen, setDeleteOpen] = useState<boolean>(false);
|
||||||
|
const [hasPolicy, setHasPolicy] = useState<boolean>(false);
|
||||||
|
|
||||||
const userName = match.params["userName"];
|
const userName = match.params["userName"];
|
||||||
|
|
||||||
@@ -188,6 +189,7 @@ const UserDetails = ({ classes, match }: IUserDetailsProps) => {
|
|||||||
}
|
}
|
||||||
setCurrentPolicies(currentPolicies);
|
setCurrentPolicies(currentPolicies);
|
||||||
setEnabled(res.status === "enabled");
|
setEnabled(res.status === "enabled");
|
||||||
|
setHasPolicy(res.hasPolicy)
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
})
|
})
|
||||||
.catch((err: ErrorResponseHandler) => {
|
.catch((err: ErrorResponseHandler) => {
|
||||||
@@ -382,7 +384,7 @@ const UserDetails = ({ classes, match }: IUserDetailsProps) => {
|
|||||||
/>
|
/>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel index={1} value={curTab}>
|
<TabPanel index={1} value={curTab}>
|
||||||
<UserServiceAccountsPanel user={userName} classes={classes} />
|
<UserServiceAccountsPanel user={userName} classes={classes} hasPolicy={hasPolicy} />
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel index={2} value={curTab}>
|
<TabPanel index={2} value={curTab}>
|
||||||
<div className={classes.actionsTray}>
|
<div className={classes.actionsTray}>
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ interface IUserServiceAccountsProps {
|
|||||||
classes: any;
|
classes: any;
|
||||||
user: string;
|
user: string;
|
||||||
setErrorSnackMessage: typeof setErrorSnackMessage;
|
setErrorSnackMessage: typeof setErrorSnackMessage;
|
||||||
|
hasPolicy: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = (theme: Theme) =>
|
const styles = (theme: Theme) =>
|
||||||
@@ -53,6 +54,7 @@ const UserServiceAccountsPanel = ({
|
|||||||
classes,
|
classes,
|
||||||
user,
|
user,
|
||||||
setErrorSnackMessage,
|
setErrorSnackMessage,
|
||||||
|
hasPolicy,
|
||||||
}: IUserServiceAccountsProps) => {
|
}: IUserServiceAccountsProps) => {
|
||||||
const [records, setRecords] = useState<string[]>([]);
|
const [records, setRecords] = useState<string[]>([]);
|
||||||
const [loading, setLoading] = useState<boolean>(false);
|
const [loading, setLoading] = useState<boolean>(false);
|
||||||
@@ -75,7 +77,6 @@ const UserServiceAccountsPanel = ({
|
|||||||
.invoke("GET", `/api/v1/user/${user}/service-accounts`)
|
.invoke("GET", `/api/v1/user/${user}/service-accounts`)
|
||||||
.then((res: string[]) => {
|
.then((res: string[]) => {
|
||||||
const serviceAccounts = res.sort(stringSort);
|
const serviceAccounts = res.sort(stringSort);
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setRecords(serviceAccounts);
|
setRecords(serviceAccounts);
|
||||||
})
|
})
|
||||||
@@ -169,6 +170,7 @@ const UserServiceAccountsPanel = ({
|
|||||||
setAddScreenOpen(true);
|
setAddScreenOpen(true);
|
||||||
setSelectedServiceAccount(null);
|
setSelectedServiceAccount(null);
|
||||||
}}
|
}}
|
||||||
|
disabled={!hasPolicy}
|
||||||
>
|
>
|
||||||
Create service account
|
Create service account
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -281,11 +281,35 @@ func getUserInfoResponse(session *models.Principal, params admin_api.GetUserInfo
|
|||||||
return nil, prepareError(err)
|
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{
|
userInformation := &models.User{
|
||||||
AccessKey: params.Name,
|
AccessKey: params.Name,
|
||||||
MemberOf: user.MemberOf,
|
MemberOf: user.MemberOf,
|
||||||
Policy: strings.Split(user.PolicyName, ","),
|
Policy: policies,
|
||||||
Status: string(user.Status),
|
Status: string(user.Status),
|
||||||
|
HasPolicy: hasPolicy,
|
||||||
}
|
}
|
||||||
|
|
||||||
return userInformation, nil
|
return userInformation, nil
|
||||||
|
|||||||
@@ -5454,6 +5454,9 @@ func init() {
|
|||||||
"accessKey": {
|
"accessKey": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"hasPolicy": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"memberOf": {
|
"memberOf": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
@@ -11049,6 +11052,9 @@ func init() {
|
|||||||
"accessKey": {
|
"accessKey": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"hasPolicy": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"memberOf": {
|
"memberOf": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": {
|
"items": {
|
||||||
|
|||||||
@@ -2485,6 +2485,9 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
status:
|
status:
|
||||||
type: string
|
type: string
|
||||||
|
hasPolicy:
|
||||||
|
type: boolean
|
||||||
|
|
||||||
listUsersResponse:
|
listUsersResponse:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|||||||
Reference in New Issue
Block a user