From 3cf20fdeb4661004451520fccf9afaeefca71edc Mon Sep 17 00:00:00 2001 From: Cesar Celis Hernandez Date: Mon, 2 Dec 2024 17:05:25 -0500 Subject: [PATCH] To allow spaces in policy --- api/admin_policies.go | 3 --- api/errors.go | 5 ----- integration/policy_test.go | 2 +- .../src/screens/Console/Policies/AddPolicyScreen.tsx | 11 ++++------- 4 files changed, 5 insertions(+), 16 deletions(-) diff --git a/api/admin_policies.go b/api/admin_policies.go index f8ca2d01bc..7d163e97eb 100644 --- a/api/admin_policies.go +++ b/api/admin_policies.go @@ -550,9 +550,6 @@ func getAddPolicyResponse(session *models.Principal, params policyApi.AddPolicyP if params.Body == nil { return nil, ErrorWithContext(ctx, ErrPolicyBodyNotInRequest) } - if strings.Contains(*params.Body.Name, " ") { - return nil, ErrorWithContext(ctx, ErrPolicyNameContainsSpace) - } mAdmin, err := NewMinioAdminClient(params.HTTPRequest.Context(), session) if err != nil { return nil, ErrorWithContext(ctx, err) diff --git a/api/errors.go b/api/errors.go index 1977b543e0..a5b097c4ce 100644 --- a/api/errors.go +++ b/api/errors.go @@ -43,7 +43,6 @@ 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") @@ -161,10 +160,6 @@ func ErrorWithContext(ctx context.Context, err ...interface{}) *CodedAPIError { errorCode = 400 errorMessage = ErrPolicyBodyNotInRequest.Error() } - if errors.Is(err1, ErrPolicyNameContainsSpace) { - errorCode = 400 - errorMessage = ErrPolicyNameContainsSpace.Error() - } // console invalid session errors if errors.Is(err1, ErrInvalidSession) { errorCode = 401 diff --git a/integration/policy_test.go b/integration/policy_test.go index 62cdf2a1bd..9a9a655921 100644 --- a/integration/policy_test.go +++ b/integration/policy_test.go @@ -176,7 +176,7 @@ func Test_AddPolicyAPI(t *testing.T) { ] }`), }, - expectedStatus: 400, + expectedStatus: 201, // Changed the expected status from 400 to 201, as spaces are now allowed in policy names. expectedError: nil, }, { diff --git a/web-app/src/screens/Console/Policies/AddPolicyScreen.tsx b/web-app/src/screens/Console/Policies/AddPolicyScreen.tsx index c988ed3355..d15fa47f2b 100644 --- a/web-app/src/screens/Console/Policies/AddPolicyScreen.tsx +++ b/web-app/src/screens/Console/Policies/AddPolicyScreen.tsx @@ -52,7 +52,7 @@ const AddPolicyScreen = () => { setAddLoading(true); api.policies .addPolicy({ - name: policyName, + name: policyName.trim(), policy: policyDefinition, }) .then((res) => { @@ -79,15 +79,12 @@ const AddPolicyScreen = () => { }; const validatePolicyname = (policyName: string) => { - if (policyName.indexOf(" ") !== -1) { - return "Policy name cannot contain spaces"; + if (policyName.trim() === "") { + return "Policy name cannot be empty"; } else return ""; }; - const validSave = - policyName.trim() !== "" && - policyName.indexOf(" ") === -1 && - policyDefinition.trim() !== ""; + const validSave = policyName.trim() !== "" && policyDefinition.trim() !== ""; useEffect(() => { dispatch(setHelpName("add_policy"));