singleActions.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import { mapGetters } from 'vuex'
  2. import i18n from '@/locales'
  3. import {
  4. getSetPublicAction,
  5. } from '@/utils/common/tableActions'
  6. export default {
  7. computed: mapGetters(['isAdminMode', 'l3PermissionEnable']),
  8. created () {
  9. this.singleActions = [
  10. {
  11. label: i18n.t('system.text_152'),
  12. permission: 'policies_update',
  13. action: obj => {
  14. this.$router.push({
  15. path: '/policy/update',
  16. query: {
  17. policyName: obj.type,
  18. id: obj.id,
  19. },
  20. })
  21. },
  22. meta: (obj) => {
  23. const ret = {
  24. validate: true,
  25. }
  26. const ownerDomain = this.$store.getters.isAdminMode || obj.domain_id === this.$store.getters.userInfo.projectDomainId
  27. if (!ownerDomain) {
  28. ret.validate = false
  29. return ret
  30. }
  31. if (obj.is_system) {
  32. ret.validate = false
  33. ret.tooltip = this.$t('policy.tooltip.system_policy')
  34. return ret
  35. }
  36. return ret
  37. },
  38. },
  39. {
  40. label: i18n.t('system.text_153'),
  41. actions: obj => {
  42. return [
  43. {
  44. label: i18n.t('system.text_225'),
  45. permission: 'policies_update',
  46. action: () => {
  47. this.createDialog('DisableDialog', {
  48. title: i18n.t('system.text_342', [i18n.t('dictionary.policy')]),
  49. name: this.$t('dictionary.policy'),
  50. columns: this.columns,
  51. data: [obj],
  52. ok: async () => {
  53. try {
  54. const response = await this.onManager('performAction', {
  55. id: obj.id,
  56. managerArgs: {
  57. action: 'enable',
  58. },
  59. })
  60. return response
  61. } catch (error) {
  62. throw error
  63. }
  64. },
  65. })
  66. },
  67. meta: () => {
  68. return {
  69. validate: !obj.enabled && this.isOwnerPublic(obj),
  70. }
  71. },
  72. },
  73. {
  74. label: i18n.t('system.text_226'),
  75. permission: 'policies_update',
  76. action: () => {
  77. this.createDialog('DisableDialog', {
  78. alert: i18n.t('system.text_434'),
  79. title: i18n.t('system.text_341', [i18n.t('dictionary.policy')]),
  80. name: this.$t('dictionary.policy'),
  81. columns: this.columns,
  82. data: [obj],
  83. ok: async () => {
  84. try {
  85. const response = await this.onManager('performAction', {
  86. id: obj.id,
  87. managerArgs: {
  88. action: 'disable',
  89. },
  90. })
  91. return response
  92. } catch (error) {
  93. throw error
  94. }
  95. },
  96. })
  97. },
  98. meta: () => {
  99. return {
  100. validate: obj.enabled && this.isOwnerPublic(obj),
  101. }
  102. },
  103. },
  104. {
  105. label: this.$t('table.action.clone'),
  106. permission: 'policies_create',
  107. action: () => {
  108. this.createDialog('PolicyCloneDialog', {
  109. data: [obj],
  110. columns: this.columns,
  111. success: () => {
  112. this.refresh()
  113. },
  114. })
  115. },
  116. },
  117. // {
  118. // label: i18n.t('system.text_435'),
  119. // action: () => {
  120. // this.onManager('performAction', {
  121. // id: obj.id,
  122. // managerArgs: {
  123. // action: 'public',
  124. // },
  125. // })
  126. // },
  127. // meta: () => {
  128. // const ret = {
  129. // validate: false,
  130. // }
  131. // if (!this.isAdminMode || !this.l3PermissionEnable) {
  132. // return ret
  133. // }
  134. // if (obj.is_system) {
  135. // ret.tooltip = this.$t('policy.tooltip.system_policy')
  136. // return ret
  137. // }
  138. // ret.validate = !obj.is_public && this.isOwnerPublic(obj)
  139. // return ret
  140. // },
  141. // },
  142. // {
  143. // label: i18n.t('system.text_436'),
  144. // action: () => {
  145. // this.onManager('performAction', {
  146. // id: obj.id,
  147. // managerArgs: {
  148. // action: 'private',
  149. // },
  150. // })
  151. // },
  152. // meta: () => {
  153. // const ret = {
  154. // validate: false,
  155. // }
  156. // if (!this.isAdminMode || !this.l3PermissionEnable) {
  157. // return ret
  158. // }
  159. // if (obj.is_system) {
  160. // ret.tooltip = this.$t('policy.tooltip.system_policy')
  161. // return ret
  162. // }
  163. // ret.validate = obj.is_public && this.isOwnerPublic(obj)
  164. // return ret
  165. // },
  166. // },
  167. getSetPublicAction(this, {
  168. name: this.$t('res.policy'),
  169. scope: 'domain',
  170. resource: 'policies',
  171. apiVersion: 'v1',
  172. noCandidateDomains: true,
  173. }, {
  174. meta: row => {
  175. const ret = {
  176. validate: false,
  177. }
  178. if (obj.is_system) {
  179. ret.tooltip = this.$t('policy.tooltip.system_policy')
  180. return ret
  181. }
  182. },
  183. }),
  184. {
  185. label: i18n.t('system.text_129'),
  186. permission: 'policies_delete',
  187. action: () => {
  188. this.createDialog('DeleteResDialog', {
  189. vm: this,
  190. data: [obj],
  191. columns: this.columns,
  192. title: i18n.t('system.text_129'),
  193. onManager: this.onManager,
  194. name: this.$t('dictionary.policy'),
  195. })
  196. },
  197. meta: () => this.$getDeleteResult(obj),
  198. },
  199. ]
  200. },
  201. },
  202. ]
  203. },
  204. }