Policies.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <div>
  3. <a-alert banner v-if="!isSupport">
  4. <template #message>
  5. <p>{{$t('storage.text_148')}}</p>
  6. <p>{{$t('storage.text_258')}}</p>
  7. </template>
  8. </a-alert>
  9. <page-list
  10. v-else
  11. :list="list"
  12. :showSearchbox="false"
  13. :columns="columns"
  14. :group-actions="groupActions"
  15. :single-actions="singleActions" />
  16. </div>
  17. </template>
  18. <script>
  19. import WindowsMixin from '@/mixins/windows'
  20. import ListMixin from '@/mixins/list'
  21. import { HYPERVISORS_MAP } from '@/constants'
  22. export default {
  23. name: 'BucketPolicyList',
  24. mixins: [WindowsMixin, ListMixin],
  25. props: {
  26. id: String,
  27. resId: String,
  28. getParams: {
  29. type: [Function, Object],
  30. },
  31. data: {
  32. type: Object,
  33. },
  34. },
  35. data () {
  36. const isSupport = [
  37. HYPERVISORS_MAP.qcloud.provider,
  38. HYPERVISORS_MAP.aliyun.provider,
  39. HYPERVISORS_MAP.aws.provider,
  40. HYPERVISORS_MAP.huawei.provider,
  41. ].includes(this.data.provider)
  42. return {
  43. list: this.$list.createList(this, {
  44. id: 'BucketPolicyList',
  45. resource: 'policy',
  46. ctx: [['buckets', this.resId]],
  47. getParams: this.getParam,
  48. }),
  49. groupActions: [
  50. {
  51. label: this.$t('storage.text_31'),
  52. permission: 'policy_create',
  53. action: () => {
  54. this.createDialog('CreatePolicyDialog', {
  55. title: this.$t('storage.text_259'),
  56. bucketID: this.resId,
  57. onManager: this.onManager,
  58. refresh: this.refresh,
  59. bucketData: this.data,
  60. })
  61. },
  62. meta: () => {
  63. if (this.$store.getters.scope === 'project' && this.data.tenant_id !== this.$store.getters.auth.tenant) {
  64. return {
  65. buttonType: 'primary',
  66. validate: false,
  67. tooltip: this.$t('storage.text_257'),
  68. }
  69. }
  70. return {
  71. buttonType: 'primary',
  72. ...this.$isOwner(this.data),
  73. }
  74. },
  75. },
  76. {
  77. label: this.$t('storage.text_36'),
  78. permission: 'policy_delete',
  79. action: () => {
  80. this.createDialog('DeletePolicyDialog', {
  81. title: this.$t('storage.text_36'),
  82. name: this.$t('storage.text_259'),
  83. data: this.list.selectedItems,
  84. bucketID: this.resId,
  85. columns: this.columns,
  86. refresh: this.refresh,
  87. })
  88. },
  89. meta: () => {
  90. if (this.list.selectedItems.length === 0) return { validate: false }
  91. if (this.$store.getters.scope === 'project' && this.data.tenant_id !== this.$store.getters.auth.tenant) {
  92. return {
  93. validate: false,
  94. tooltip: this.$t('storage.text_257'),
  95. }
  96. }
  97. return this.$isOwner(this.data)
  98. },
  99. },
  100. ],
  101. singleActions: [
  102. {
  103. label: this.$t('storage.text_36'),
  104. permission: 'policy_delete',
  105. action: (row) => {
  106. this.createDialog('DeletePolicyDialog', {
  107. title: this.$t('storage.text_36'),
  108. name: this.$t('storage.text_259'),
  109. data: [row],
  110. bucketID: this.resId,
  111. columns: this.columns,
  112. refresh: this.refresh,
  113. })
  114. },
  115. meta: () => {
  116. if (this.$store.getters.scope === 'project' && this.data.tenant_id !== this.$store.getters.auth.tenant) {
  117. return {
  118. validate: false,
  119. tooltip: this.$t('storage.text_257'),
  120. }
  121. }
  122. return this.$isOwner(this.data)
  123. },
  124. },
  125. ],
  126. columns: [
  127. {
  128. field: 'Effect',
  129. title: this.$t('storage.text_239'),
  130. formatter: ({ row }) => {
  131. const obj = {
  132. Allow: this.$t('storage.text_217'),
  133. Deny: this.$t('storage.text_218'),
  134. }
  135. return obj[row.Effect]
  136. },
  137. },
  138. {
  139. field: 'principal',
  140. title: this.$t('storage.text_260'),
  141. slots: {
  142. default: ({ row }) => {
  143. const principal_id = row.principal_id || []
  144. return principal_id.map(item => {
  145. const item_arr = item.split(':')
  146. if (item_arr[0] === item_arr[1]) return (<div>{this.$t('storage.text_241')}</div>)
  147. return (<div>{this.$t('storage.text_242')}</div>)
  148. })
  149. },
  150. },
  151. },
  152. {
  153. field: 'principal_id',
  154. title: this.$t('storage.text_261'),
  155. slots: {
  156. default: ({ row }) => {
  157. const { principal_id = [], principal_names = {} } = row
  158. return principal_id.map(item => {
  159. const item_arr = item.split(':')
  160. const item_name = principal_names[item] || ''
  161. return (<list-body-cell-wrap hideField copy title={ item_arr[1] } message={ item_arr[1] }>
  162. <span>{ item_arr[1] }{ item_name ? `(${item_name})` : ''}</span>
  163. </list-body-cell-wrap>)
  164. })
  165. },
  166. },
  167. },
  168. {
  169. field: 'resource_path',
  170. title: this.$t('storage.text_262'),
  171. slots: {
  172. default: ({ row }) => {
  173. const resource_path = row.resource_path || []
  174. return resource_path.map(item => {
  175. return (<list-body-cell-wrap hideField copy title={ item } message={ item }>
  176. <span>{ item }</span>
  177. </list-body-cell-wrap>)
  178. })
  179. },
  180. },
  181. },
  182. {
  183. field: 'canned_action',
  184. title: this.$t('storage.text_263'),
  185. formatter: ({ row }) => {
  186. const obj = {
  187. Read: this.$t('storage.text_252'),
  188. ReadWrite: this.$t('storage.text_264'),
  189. FullControl: this.$t('storage.text_254'),
  190. }
  191. return obj[row.canned_action] || this.$t('storage.text_265')
  192. },
  193. },
  194. ],
  195. isSupport,
  196. }
  197. },
  198. created () {
  199. if (this.isSupport) {
  200. this.list.fetchData()
  201. }
  202. },
  203. }
  204. </script>