storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/buckets/Policy.js (about)

     1  /*
     2   * MinIO Cloud Storage (C) 2018 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  import { READ_ONLY, WRITE_ONLY, READ_WRITE, NONE } from '../constants'
    18  
    19  import React from "react"
    20  import { connect } from "react-redux"
    21  import classnames from "classnames"
    22  import * as actionsBuckets from "./actions"
    23  import * as actionsAlert from "../alert/actions"
    24  import web from "../web"
    25  
    26  export class Policy extends React.Component {
    27    removePolicy(e) {
    28      e.preventDefault()
    29      const {currentBucket, prefix, fetchPolicies, showAlert} = this.props
    30      web.
    31        SetBucketPolicy({
    32          bucketName: currentBucket,
    33          prefix: prefix,
    34          policy: 'none'
    35        })
    36        .then(() => {
    37          fetchPolicies(currentBucket)
    38        })
    39        .catch(e => showAlert('danger', e.message))
    40    }
    41  
    42    render() {
    43      const {policy, prefix} = this.props
    44      let newPrefix = prefix
    45      if (newPrefix === '')
    46        newPrefix = '*'
    47  
    48      if (policy === NONE) {
    49        return <noscript />
    50      } else {
    51        return (
    52          <div className="pmb-list">
    53            <div className="pmbl-item">
    54              { newPrefix }
    55            </div>
    56            <div className="pmbl-item">
    57              <select className="form-control"
    58                disabled
    59                value={ policy }>
    60                <option value={ READ_ONLY }>
    61                  Read Only
    62                </option>
    63                <option value={ WRITE_ONLY }>
    64                  Write Only
    65                </option>
    66                <option value={ READ_WRITE }>
    67                  Read and Write
    68                </option>
    69              </select>
    70            </div>
    71            <div className="pmbl-item">
    72              <button className="btn btn-block btn-danger" onClick={ this.removePolicy.bind(this) }>
    73                Remove
    74              </button>
    75            </div>
    76          </div>
    77        )
    78      }
    79    }
    80  }
    81  
    82  const mapStateToProps = state => {
    83    return {
    84      currentBucket: state.buckets.currentBucket
    85    }
    86  }
    87  
    88  const mapDispatchToProps = dispatch => {
    89    return {
    90      fetchPolicies: bucket => dispatch(actionsBuckets.fetchPolicies(bucket)),
    91      showAlert: (type, message) =>
    92        dispatch(actionsAlert.set({ type: type, message: message }))
    93    }
    94  }
    95  
    96  export default connect(mapStateToProps, mapDispatchToProps)(Policy)