From d1971b9a4d43eb51c605bf1c6769b748f32136bd Mon Sep 17 00:00:00 2001 From: poornas Date: Wed, 10 May 2017 09:52:31 -0700 Subject: [PATCH] Prevent duplicate policy rows from being created (#4276) --- browser/README.md | 2 +- browser/app/js/components/PolicyInput.js | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/browser/README.md b/browser/README.md index 647147fdf..9a65c4eb2 100644 --- a/browser/README.md +++ b/browser/README.md @@ -27,7 +27,7 @@ go get github.com/elazarl/go-bindata-assetfs/... yarn release ``` -This generates ui-assets.go in the current direcotry. Now do `make` in the parent directory to build the minio binary with the newly generated ``ui-assets.go`` +This generates ui-assets.go in the current directory. Now do `make` in the parent directory to build the minio binary with the newly generated ``ui-assets.go`` ### Run Minio Browser with live reload diff --git a/browser/app/js/components/PolicyInput.js b/browser/app/js/components/PolicyInput.js index 9353bde41..8508fc0c4 100644 --- a/browser/app/js/components/PolicyInput.js +++ b/browser/app/js/components/PolicyInput.js @@ -7,6 +7,7 @@ import * as actions from '../actions' class PolicyInput extends Component { componentDidMount() { const {web, dispatch} = this.props + this.prefix.focus() web.ListAllBucketPolicies({ bucketName: this.props.currentBucket }).then(res => { @@ -27,8 +28,23 @@ class PolicyInput extends Component { handlePolicySubmit(e) { e.preventDefault() - const {web, dispatch} = this.props + const {web, dispatch, currentBucket} = this.props + let prefix = currentBucket + '/' + this.prefix.value + let policy = this.policy.value + + if (!prefix.endsWith('*')) prefix = prefix + '*' + + let prefixAlreadyExists = this.props.policies.some(elem => prefix === elem.prefix) + + if (prefixAlreadyExists) { + dispatch(actions.showAlert({ + type: 'danger', + message: "Policy for this prefix already exists." + })) + return + } + web.SetBucketPolicy({ bucketName: this.props.currentBucket, prefix: this.prefix.value, @@ -36,8 +52,7 @@ class PolicyInput extends Component { }) .then(() => { dispatch(actions.setPolicies([{ - policy: this.policy.value, - prefix: this.prefix.value + '*', + policy, prefix }, ...this.props.policies])) this.prefix.value = '' })