Disabled Save button on Add Policy Screen if policy name contains space (#1937)
This commit is contained in:
@@ -72,6 +72,7 @@ const AddPolicyScreen = ({
|
||||
const [policyDefinition, setPolicyDefinition] = useState<string>("");
|
||||
|
||||
const addRecord = (event: React.FormEvent) => {
|
||||
|
||||
event.preventDefault();
|
||||
if (addLoading) {
|
||||
return;
|
||||
@@ -97,7 +98,13 @@ const AddPolicyScreen = ({
|
||||
setPolicyDefinition("");
|
||||
};
|
||||
|
||||
const validSave = policyName.trim() !== "";
|
||||
const validatePolicyname = (policyName: string) => {
|
||||
if (policyName.indexOf(' ') !== -1){
|
||||
return "Policy name cannot contain spaces"
|
||||
} else return ""
|
||||
}
|
||||
|
||||
const validSave = (policyName.trim() !== "" ) && (policyName.indexOf(' ') === -1);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
@@ -126,6 +133,7 @@ const AddPolicyScreen = ({
|
||||
label="Policy Name"
|
||||
autoFocus={true}
|
||||
value={policyName}
|
||||
error={validatePolicyname(policyName)}
|
||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setPolicyName(e.target.value);
|
||||
}}
|
||||
|
||||
@@ -417,11 +417,15 @@ func addPolicy(ctx context.Context, client MinioAdmin, name, policy string) (*mo
|
||||
|
||||
// getAddPolicyResponse performs addPolicy() and serializes it to the handler's output
|
||||
func getAddPolicyResponse(session *models.Principal, params policyApi.AddPolicyParams) (*models.Policy, *models.Error) {
|
||||
|
||||
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
|
||||
defer cancel()
|
||||
if params.Body == nil {
|
||||
return nil, ErrorWithContext(ctx, ErrPolicyBodyNotInRequest)
|
||||
}
|
||||
if strings.Contains(*params.Body.Name, " ") {
|
||||
return nil, ErrorWithContext(ctx, ErrPolicyNameContainsSpace)
|
||||
}
|
||||
mAdmin, err := NewMinioAdminClient(session)
|
||||
if err != nil {
|
||||
return nil, ErrorWithContext(ctx, err)
|
||||
|
||||
@@ -41,6 +41,7 @@ var (
|
||||
ErrGroupNameNotInRequest = errors.New("error group name not in request")
|
||||
ErrPolicyNameNotInRequest = errors.New("error policy name not in request")
|
||||
ErrPolicyBodyNotInRequest = errors.New("error policy body not in request")
|
||||
ErrPolicyNameContainsSpace = errors.New("error policy name cannot contain spaces")
|
||||
ErrInvalidEncryptionAlgorithm = errors.New("error invalid encryption algorithm")
|
||||
ErrSSENotConfigured = errors.New("error server side encryption configuration not found")
|
||||
ErrBucketLifeCycleNotConfigured = errors.New("error bucket life cycle configuration not found")
|
||||
|
||||
Reference in New Issue
Block a user