| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225 |
- <template>
- <base-dialog @cancel="cancelDialog">
- <div slot="header">{{$t('storage.text_238')}}</div>
- <div slot="body">
- <a-form
- :form="form.fc">
- <a-form-item :label="$t('storage.text_239')" v-bind="formItemLayout">
- <a-radio-group v-decorator="decorators.Effect">
- <a-radio-button value="Allow">{{$t('storage.text_217')}}</a-radio-button>
- </a-radio-group>
- </a-form-item>
- <a-form-item :label="$t('storage.text_240')" v-bind="formItemLayout" required>
- <a-row>
- <a-col :span="11" class="mr-1">
- <a-form-item class="mb-0">
- <a-select v-decorator="decorators.PrincipalType" @change="handleTypeChange">
- <a-select-option value="root">{{$t('storage.text_241')}}</a-select-option>
- <a-select-option value="child">{{$t('storage.text_242')}}</a-select-option>
- </a-select>
- </a-form-item>
- </a-col>
- <a-col :span="12">
- <a-form-item class="mb-0">
- <a-input v-if="isRoot" v-decorator="[
- 'PrincipalId',
- {
- rules: [{ required: true, message: $t('storage.text_243_1') }, { validator: this.validateRootId }]
- },
- ]" :placeholder="$t('storage.text_243_1')" />
- <base-select
- v-else
- v-decorator="decorators.PrincipalId"
- class="w-100"
- :remote="true"
- needParams
- resource="cloudusers"
- version="v1"
- idKey="external_id"
- :params="principalParams"
- :select-props="{ placeholder: $t('storage.text_243'), allowClear: true, mode: 'multiple' }" />
- </a-form-item>
- </a-col>
- </a-row>
- </a-form-item>
- <a-form-item :label="$t('storage.text_244')" v-bind="formItemLayout">
- <a-radio-group v-decorator="decorators.resource" @change="handleResourceTypeChange">
- <a-radio value="entirebucket">{{$t('storage.text_245')}}</a-radio>
- <a-radio value="designatedResource">{{$t('storage.text_246')}}</a-radio>
- </a-radio-group>
- </a-form-item>
- <a-form-item :label="$t('storage.text_247')" v-bind="formItemLayout">
- <div class="d-flex">
- <div>
- {{ params.bucketData.name }}/
- </div>
- <div class="flex-grow-1">
- <a-textarea :disabled="isEntirebucket" v-decorator="decorators.ResourcePath" :placeholder="$t('storage.text_250')" :auto-size="{ minRows: 3, maxRows: 5 }" />
- </div>
- </div>
- </a-form-item>
- <a-form-item :label="$t('storage.text_251')" v-bind="formItemLayout">
- <a-radio-group v-decorator="decorators.CannedAction">
- <a-radio-button value="Read">{{$t('storage.text_252')}}</a-radio-button>
- <a-radio-button value="ReadWrite">{{$t('storage.text_253')}}</a-radio-button>
- <a-radio-button value="FullControl">{{$t('storage.text_254')}}</a-radio-button>
- </a-radio-group>
- </a-form-item>
- </a-form>
- </div>
- <div slot="footer">
- <a-button type="primary" @click="handleConfirm" :loading="loading">{{ $t('dialog.ok') }}</a-button>
- <a-button @click="cancelDialog">{{ $t('dialog.cancel') }}</a-button>
- </div>
- </base-dialog>
- </template>
- <script>
- import { mapGetters } from 'vuex'
- import DialogMixin from '@/mixins/dialog'
- import WindowsMixin from '@/mixins/windows'
- export default {
- name: 'CreatePolicyDialog',
- mixins: [DialogMixin, WindowsMixin],
- data () {
- return {
- loading: false,
- type: 'child',
- resourceType: 'entirebucket',
- form: {
- fc: this.$form.createForm(this),
- },
- decorators: {
- Effect: [
- 'Effect',
- {
- initialValue: 'Allow',
- },
- ],
- PrincipalType: [
- 'PrincipalType',
- {
- initialValue: 'child',
- },
- ],
- PrincipalId: [
- 'PrincipalId',
- {
- rules: [
- { required: true, message: this.$t('storage.text_255') },
- ],
- },
- ],
- resource: [
- 'resource',
- {
- initialValue: 'entirebucket',
- },
- ],
- ResourcePath: [
- 'ResourcePath',
- {
- initialValue: '*',
- rules: [
- { required: true, message: this.$t('storage.text_256') },
- ],
- },
- ],
- CannedAction: [
- 'CannedAction',
- {
- initialValue: 'Read',
- },
- ],
- },
- formItemLayout: {
- wrapperCol: {
- span: 20,
- },
- labelCol: {
- span: 4,
- },
- },
- principalParams: {
- scope: this.$store.getters.scope,
- show_fail_reason: true,
- details: true,
- cloudaccount: this.params.bucketData.account_id,
- limit: 20,
- },
- }
- },
- computed: {
- ...mapGetters(['isAdminMode', 'scope', 'userInfo']),
- isRoot () {
- return this.type === 'root'
- },
- isEntirebucket () {
- return this.resourceType === 'entirebucket'
- },
- },
- methods: {
- handleTypeChange (value) {
- this.type = value
- this.form.fc.resetFields(['PrincipalId'])
- },
- handleResourceTypeChange (e) {
- if (e.target.value === 'entirebucket') {
- this.form.fc.setFieldsValue({ ResourcePath: '*' })
- } else {
- this.form.fc.setFieldsValue({ ResourcePath: '' })
- }
- this.resourceType = e.target.value
- },
- genData (data) {
- const { Effect, CannedAction } = data
- const ret = {
- Effect,
- CannedAction,
- }
- if (data.PrincipalType === 'child') {
- ret.PrincipalId = data.PrincipalId.map(item => {
- return ':' + item
- })
- } else {
- ret.PrincipalId = data.PrincipalId + ':'
- }
- ret.ResourcePath = data.ResourcePath.trim().split('\n')
- ret.ResourcePath = ret.ResourcePath.map(item => '/' + item)
- return ret
- },
- doCreate (data) {
- return new this.$Manager('buckets').performAction({
- id: this.params.bucketID,
- action: 'set-policy',
- data: data,
- })
- },
- async handleConfirm () {
- this.loading = true
- try {
- const values = await this.form.fc.validateFields()
- const data = this.genData(values)
- await this.doCreate(data)
- this.loading = false
- this.cancelDialog()
- this.params.refresh()
- } catch (error) {
- this.loading = false
- }
- },
- validateRootId (rule, value, callback) {
- if (!value) {
- callback()
- return
- }
- if (/^[0-9]*$/.test(value)) {
- callback()
- } else {
- callback(new Error(this.$t('storage.number_validate')))
- }
- },
- },
- }
- </script>
|