Skip to content

Commit 34adc54

Browse files
authored
Disabled Save button on Add Policy Screen if policy name contains space (#1937)
1 parent 224e8d4 commit 34adc54

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

portal-ui/src/screens/Console/Policies/AddPolicyScreen.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const AddPolicyScreen = ({
7272
const [policyDefinition, setPolicyDefinition] = useState<string>("");
7373

7474
const addRecord = (event: React.FormEvent) => {
75+
7576
event.preventDefault();
7677
if (addLoading) {
7778
return;
@@ -97,7 +98,13 @@ const AddPolicyScreen = ({
9798
setPolicyDefinition("");
9899
};
99100

100-
const validSave = policyName.trim() !== "";
101+
const validatePolicyname = (policyName: string) => {
102+
if (policyName.indexOf(' ') !== -1){
103+
return "Policy name cannot contain spaces"
104+
} else return ""
105+
}
106+
107+
const validSave = (policyName.trim() !== "" ) && (policyName.indexOf(' ') === -1);
101108

102109
return (
103110
<Fragment>
@@ -126,6 +133,7 @@ const AddPolicyScreen = ({
126133
label="Policy Name"
127134
autoFocus={true}
128135
value={policyName}
136+
error={validatePolicyname(policyName)}
129137
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
130138
setPolicyName(e.target.value);
131139
}}

restapi/admin_policies.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,11 +417,15 @@ func addPolicy(ctx context.Context, client MinioAdmin, name, policy string) (*mo
417417

418418
// getAddPolicyResponse performs addPolicy() and serializes it to the handler's output
419419
func getAddPolicyResponse(session *models.Principal, params policyApi.AddPolicyParams) (*models.Policy, *models.Error) {
420+
420421
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
421422
defer cancel()
422423
if params.Body == nil {
423424
return nil, ErrorWithContext(ctx, ErrPolicyBodyNotInRequest)
424425
}
426+
if strings.Contains(*params.Body.Name, " ") {
427+
return nil, ErrorWithContext(ctx, ErrPolicyNameContainsSpace)
428+
}
425429
mAdmin, err := NewMinioAdminClient(session)
426430
if err != nil {
427431
return nil, ErrorWithContext(ctx, err)

restapi/errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var (
4141
ErrGroupNameNotInRequest = errors.New("error group name not in request")
4242
ErrPolicyNameNotInRequest = errors.New("error policy name not in request")
4343
ErrPolicyBodyNotInRequest = errors.New("error policy body not in request")
44+
ErrPolicyNameContainsSpace = errors.New("error policy name cannot contain spaces")
4445
ErrInvalidEncryptionAlgorithm = errors.New("error invalid encryption algorithm")
4546
ErrSSENotConfigured = errors.New("error server side encryption configuration not found")
4647
ErrBucketLifeCycleNotConfigured = errors.New("error bucket life cycle configuration not found")

0 commit comments

Comments
 (0)