Advanced.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <div>
  3. <template v-if="isCommon">
  4. <a-form-item :label="$t('common_516')" :extra="$t('common_504', [templateLabel])">
  5. <a-input v-decorator="decorators.user_id_attribute" />
  6. </a-form-item>
  7. <a-form-item :label="$t('system.field.username')" :extra="$t('common_505', [templateLabel])">
  8. <a-input v-decorator="decorators.user_name_attribute" />
  9. </a-form-item>
  10. </template>
  11. <a-form-item :label="$t('common_501')">
  12. <a-switch v-decorator="decorators.auto_create_user">{{$t('common_499')}}</a-switch>
  13. <template slot="extra">{{$t('common_513')}}<br />{{$t('common_514')}}</template>
  14. </a-form-item>
  15. <template v-if="fd.auto_create_user">
  16. <a-form-item :label="$t('common_503', [$t('dictionary.domain')])" :extra="$t('system.text_229', [$t('dictionary.domain')])">
  17. <base-select
  18. v-if="isAdmin"
  19. @update:resList="resTargetDomain"
  20. :disabled="!!fc.getFieldValue('project_domain')"
  21. v-decorator="decorators.target_domain"
  22. resource="domains"
  23. filterable
  24. version="v1"
  25. :select-props="{
  26. placeholder: $t('common_656')
  27. }" />
  28. <span v-else>
  29. {{projectDomain}}
  30. </span>
  31. </a-form-item>
  32. <a-collapse accordion v-if="showCollapse">
  33. <a-collapse-panel key="1" :header="$t('system.text_214')">
  34. <a-form-item class="mb-0" :label="$t('system.text_205', [$t('dictionary.project')])">
  35. <a-row :gutter="8">
  36. <a-col :span="10">
  37. <a-form-item :wrapperCol="{ span: 24 }" :extra="$t('common_506', [templateLabel,$t('dictionary.user'),$t('dictionary.project')])">
  38. <base-select
  39. v-decorator="decorators.default_project_id"
  40. resource="projects"
  41. version="v1"
  42. :params="projectParams"
  43. remote
  44. :item.sync="project"
  45. :remote-fn="q => ({ filter: `name.contains(${q})` })"
  46. :select-props="{ placeholder: $t('rules.project') }" />
  47. </a-form-item>
  48. </a-col>
  49. <a-col :span="14" v-if="isCommon">
  50. <template v-if="showProjectInput">
  51. <a-form-item :wrapperCol="{ span: 24 }">
  52. <div class="d-flex align-items-center">
  53. <div class="flex-fill mr-1">
  54. <a-input v-decorator="decorators.project_attribute" :placeholder="$t('common_507', [templateLabel,$t('dictionary.project'),templateLabel.toLocaleLowerCase()])" />
  55. </div>
  56. <a-tooltip placement="right">
  57. <span slot="title">{{$t('common_517', [templateLabel])}}</span>
  58. <icon type="question" />
  59. </a-tooltip>
  60. <a-button type="link" @click="showProjectInput = !showProjectInput">{{$t('common_518', [templateLabel, this.$t('dictionary.project')]) }}</a-button>
  61. </div>
  62. <div slot="extra">
  63. <a-checkbox v-decorator="decorators.auto_create_project">{{$t('common_519')}}</a-checkbox>
  64. <br />{{$t('common_520')}}</div>
  65. </a-form-item>
  66. </template>
  67. <template v-else>
  68. <a-button type="link" @click="showProjectInput = true">{{$t('common_521', [templateLabel, this.$t('dictionary.project')]) }}</a-button>
  69. </template>
  70. </a-col>
  71. </a-row>
  72. </a-form-item>
  73. <a-form-item class="mb-0" :label="$t('system.text_205', [$t('dictionary.role')])">
  74. <a-row :gutter="8">
  75. <a-col :span="10">
  76. <a-form-item :wrapperCol="{ span: 24 }" :extra="$t('common_508', [templateLabel,$t('dictionary.user'),$t('dictionary.role'),$t('dictionary.project')])">
  77. <base-select
  78. v-decorator="decorators.default_role_id"
  79. resource="roles"
  80. version="v1"
  81. :params="roleParams"
  82. remote
  83. :mapper="roleMapper"
  84. :remote-fn="q => ({ filter: `name.contains(${q})` })"
  85. :select-props="{ placeholder: $t('rules.role') }" />
  86. </a-form-item>
  87. </a-col>
  88. <a-col :span="14" v-if="isCommon">
  89. <template v-if="showRoleInput">
  90. <a-form-item :wrapperCol="{ span: 24 }">
  91. <div class="d-flex align-items-center">
  92. <div class="flex-fill mr-1">
  93. <a-input v-decorator="decorators.role_attribute" :placeholder="$t('common_509', [templateLabel,$t('dictionary.role'),templateLabel.toLocaleLowerCase()])" />
  94. </div>
  95. <a-tooltip placement="right">
  96. <span slot="title">{{$t('common_522', [templateLabel])}}</span>
  97. <icon type="question" />
  98. </a-tooltip>
  99. <a-button type="link" @click="showRoleInput = !showRoleInput">{{$t('common_518', [templateLabel, this.$t('dictionary.role')])}}</a-button>
  100. </div>
  101. </a-form-item>
  102. </template>
  103. <template v-else>
  104. <a-button type="link" @click="showRoleInput = true">{{$t('common_521', [templateLabel, this.$t('dictionary.role')])}}</a-button>
  105. </template>
  106. </a-col>
  107. </a-row>
  108. </a-form-item>
  109. <template v-if="isCommon">
  110. <a-form-item :label="$t('scope.text_245')" :extra="$t('common_510', [templateLabel])">
  111. <a-input v-decorator="decorators.user_displayname_attribute" />
  112. </a-form-item>
  113. <a-form-item :label="$t('scope.text_553')" :extra="$t('common_511', [templateLabel])">
  114. <a-input v-decorator="decorators.user_email_attribute" />
  115. </a-form-item>
  116. <a-form-item :label="$t('scope.text_200')" :extra="$t('common_512', [templateLabel])">
  117. <a-input v-decorator="decorators.user_mobile_attribute" />
  118. </a-form-item>
  119. </template>
  120. </a-collapse-panel>
  121. </a-collapse>
  122. </template>
  123. </div>
  124. </template>
  125. <script>
  126. export default {
  127. name: 'IDPEditAdvanced',
  128. props: {
  129. fd: {
  130. type: Object,
  131. required: true,
  132. },
  133. fc: {
  134. type: Object,
  135. required: true,
  136. },
  137. templateData: {
  138. type: Object,
  139. required: true,
  140. },
  141. offsetWrapperCol: {
  142. type: Object,
  143. required: true,
  144. },
  145. isCommon: {
  146. type: Boolean,
  147. required: true,
  148. },
  149. },
  150. data () {
  151. return {
  152. isAdmin: this.$store.getters.isAdminMode,
  153. isDomain: this.$store.getters.isDomainMode,
  154. projectDomain: this.$store.getters.userInfo.projectDomain,
  155. projectDomainId: this.$store.getters.userInfo.projectDomainId,
  156. scope: this.$store.getters.scope,
  157. showProjectInput: false,
  158. showRoleInput: false,
  159. project: {},
  160. decorators: {
  161. auto_create_user: [
  162. 'auto_create_user',
  163. {
  164. valuePropName: 'checked',
  165. },
  166. ],
  167. disable_user_on_import: [
  168. 'disable_user_on_import',
  169. {
  170. initialValue: false,
  171. },
  172. ],
  173. target_domain: [
  174. 'target_domain',
  175. ],
  176. default_project_id: [
  177. 'default_project_id',
  178. ],
  179. role_attribute: [
  180. 'role_attribute',
  181. ],
  182. project_attribute: [
  183. 'project_attribute',
  184. ],
  185. default_role_id: [
  186. 'default_role_id',
  187. ],
  188. auto_create_project: [
  189. 'auto_create_project',
  190. ],
  191. user_displayname_attribute: [
  192. 'user_displayname_attribute',
  193. ],
  194. user_email_attribute: [
  195. 'user_email_attribute',
  196. ],
  197. user_mobile_attribute: [
  198. 'user_mobile_attribute',
  199. ],
  200. user_id_attribute: [
  201. 'user_id_attribute',
  202. {
  203. rules: [
  204. { required: true, message: this.$t('common_607') },
  205. ],
  206. },
  207. ],
  208. user_name_attribute: [
  209. 'user_name_attribute',
  210. {
  211. rules: [
  212. { required: true, message: this.$t('common_608') },
  213. ],
  214. },
  215. ],
  216. },
  217. }
  218. },
  219. computed: {
  220. projectParams () {
  221. return {
  222. limit: 0,
  223. scope: this.scope,
  224. project_domains: this.fd.target_domain,
  225. }
  226. },
  227. roleParams () {
  228. return {
  229. limit: 0,
  230. scope: this.scope,
  231. project_domains: ['default', this.fd.target_domain],
  232. }
  233. },
  234. showCollapse () {
  235. return this.fd.target_domain || this.isDomain
  236. },
  237. templateKey () {
  238. return this.templateData.key
  239. },
  240. templateLabel () {
  241. return this.templateData.label
  242. },
  243. },
  244. watch: {
  245. 'fd.target_domain' (val) {
  246. this.fc.resetFields(['default_project_id', 'project_attribute'])
  247. },
  248. 'fd.template': {
  249. async handler (val) {
  250. const attributeInitialValues = {
  251. cas: {
  252. user_id_attribute: 'cas:user',
  253. user_name_attribute: 'cas:user',
  254. },
  255. oidc: {
  256. user_id_attribute: 'name',
  257. user_name_attribute: 'name',
  258. },
  259. saml: {},
  260. }
  261. let initialValues = {
  262. user_id_attribute: undefined,
  263. user_name_attribute: undefined,
  264. }
  265. if (attributeInitialValues[val]) {
  266. initialValues = {
  267. ...initialValues,
  268. ...attributeInitialValues[val],
  269. }
  270. }
  271. await this.$nextTick()
  272. this.fc.setFieldsValue(initialValues)
  273. },
  274. immediate: true,
  275. },
  276. },
  277. methods: {
  278. roleMapper (list) {
  279. if (list && list.length > 0) {
  280. return list.filter(row => {
  281. if (row.domain_id === 'default') {
  282. return row.is_public
  283. }
  284. return true
  285. })
  286. }
  287. return []
  288. },
  289. resTargetDomain (list) {
  290. const project_domain = this.fc.getFieldValue('project_domain')
  291. console.log(project_domain)
  292. this.fc.setFieldsValue({
  293. target_domain: project_domain,
  294. })
  295. },
  296. },
  297. }
  298. </script>