admin-groups-edit.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. v-icon(size='80', color='grey lighten-2') people
  7. .admin-header-title
  8. .headline.blue--text.text--darken-2 Edit Group
  9. .subheading.grey--text {{name}}
  10. v-spacer
  11. v-btn(color='indigo', large, outline, to='/groups')
  12. v-icon arrow_back
  13. v-dialog(v-model='deleteGroupDialog', max-width='500', v-if='!group.isSystem')
  14. v-btn(color='red', large, outline, slot='activator')
  15. v-icon(color='red') delete
  16. v-card
  17. .dialog-header.is-red Delete Group?
  18. v-card-text Are you sure you want to delete group #[strong {{ name }}]? All users will be unassigned from this group.
  19. v-card-actions
  20. v-spacer
  21. v-btn(flat, @click='deleteGroupDialog = false') Cancel
  22. v-btn(color='red', dark, @click='deleteGroup') Delete
  23. v-btn(color='primary', large, depressed, @click='updateGroup')
  24. v-icon(left) check
  25. span Update Group
  26. v-card.mt-3
  27. v-tabs(v-model='tab', :color='$vuetify.dark ? "primary" : "grey lighten-4"', fixed-tabs, :slider-color='$vuetify.dark ? "white" : "primary"', show-arrows)
  28. v-tab(key='properties') Properties
  29. v-tab(key='permissions') Permissions
  30. v-tab(key='rules') Page Rules
  31. v-tab(key='users') Users
  32. v-tab-item(key='properties', :transition='false', :reverse-transition='false')
  33. v-card
  34. v-card-text
  35. v-text-field(
  36. outline
  37. background-color='grey lighten-3'
  38. v-model='name'
  39. label='Group Name'
  40. counter='255'
  41. prepend-icon='people'
  42. )
  43. v-divider
  44. .caption.mt-3.grey--text ID: {{group.id}}
  45. v-tab-item(key='permissions', :transition='false', :reverse-transition='false')
  46. v-container.pa-3(fluid, grid-list-md)
  47. v-layout(row, wrap)
  48. v-flex(xs12, md6, lg4, v-for='pmGroup in permissions')
  49. v-card.md2.grey(flat, :class='$vuetify.dark ? "darken-4" : "lighten-5"')
  50. v-subheader {{pmGroup.category}}
  51. v-card-text.pt-0
  52. template(v-for='(pm, idx) in pmGroup.items')
  53. v-checkbox.pt-0(
  54. :key='pm.permission'
  55. :label='pm.permission'
  56. :hint='pm.hint'
  57. persistent-hint
  58. color='primary'
  59. v-model='group.permissions'
  60. :value='pm.permission'
  61. :append-icon='pm.warning ? "warning" : null',
  62. :disabled='(group.isSystem && pm.restrictedForSystem) || group.id === 1 || pm.disabled'
  63. )
  64. v-divider.mt-3(v-if='idx < pmGroup.items.length - 1')
  65. v-tab-item(key='rules', :transition='false', :reverse-transition='false')
  66. v-card
  67. v-card-title.pb-0
  68. v-spacer
  69. v-btn(flat, outline)
  70. v-icon(left) arrow_drop_down
  71. | Load Preset
  72. v-btn(flat, outline)
  73. v-icon(left) vertical_align_bottom
  74. | Import Rules
  75. .pa-3.pl-4
  76. criterias
  77. v-tab-item(key='users', :transition='false', :reverse-transition='false')
  78. v-card
  79. v-card-title.pb-0
  80. v-spacer
  81. v-btn(color='primary', outline, flat, @click='searchUserDialog = true')
  82. v-icon(left) assignment_ind
  83. | Assign User
  84. v-data-table(
  85. :items='group.users',
  86. :headers='headers',
  87. :search='search',
  88. :pagination.sync='pagination',
  89. :rows-per-page-items='[15]'
  90. hide-actions
  91. )
  92. template(slot='items', slot-scope='props')
  93. tr(:active='props.selected')
  94. td.text-xs-right {{ props.item.id }}
  95. td {{ props.item.name }}
  96. td {{ props.item.email }}
  97. td
  98. v-menu(bottom, right, min-width='200')
  99. v-btn(icon, slot='activator'): v-icon.grey--text.text--darken-1 more_horiz
  100. v-list
  101. v-list-tile(@click='unassignUser(props.item.id)')
  102. v-list-tile-action: v-icon(color='orange') highlight_off
  103. v-list-tile-content
  104. v-list-tile-title Unassign
  105. template(slot='no-data')
  106. v-alert.ma-3(icon='warning', :value='true', outline) No users to display.
  107. .text-xs-center.py-2(v-if='users.length > 15')
  108. v-pagination(v-model='pagination.page', :length='pages')
  109. user-search(v-model='searchUserDialog', @select='assignUser')
  110. </template>
  111. <script>
  112. import _ from 'lodash'
  113. import Criterias from '../common/criterias.vue'
  114. import UserSearch from '../common/user-search.vue'
  115. import groupQuery from 'gql/admin/groups/groups-query-single.gql'
  116. import assignUserMutation from 'gql/admin/groups/groups-mutation-assign.gql'
  117. import deleteGroupMutation from 'gql/admin/groups/groups-mutation-delete.gql'
  118. import unassignUserMutation from 'gql/admin/groups/groups-mutation-unassign.gql'
  119. import updateGroupMutation from 'gql/admin/groups/groups-mutation-update.gql'
  120. export default {
  121. components: {
  122. Criterias,
  123. UserSearch
  124. },
  125. data() {
  126. return {
  127. group: {
  128. id: 0,
  129. name: '',
  130. isSystem: false,
  131. permissions: [],
  132. pageRules: [],
  133. users: []
  134. },
  135. name: '',
  136. deleteGroupDialog: false,
  137. searchUserDialog: false,
  138. pagination: {},
  139. permissions: [
  140. {
  141. category: 'Content',
  142. items: [
  143. {
  144. permission: 'read:pages',
  145. hint: 'Can view pages, as specified in the Page Rules',
  146. warning: false,
  147. restrictedForSystem: false,
  148. disabled: false
  149. },
  150. {
  151. permission: 'write:pages',
  152. hint: 'Can view and create new pages, as specified in the Page Rules',
  153. warning: false,
  154. restrictedForSystem: false,
  155. disabled: false
  156. },
  157. {
  158. permission: 'manage:pages',
  159. hint: 'Can view, create, edit and move existing pages as specified in the Page Rules',
  160. warning: false,
  161. restrictedForSystem: false,
  162. disabled: false
  163. },
  164. {
  165. permission: 'delete:pages',
  166. hint: 'Can delete existing pages, as specified in the Page Rules',
  167. warning: false,
  168. restrictedForSystem: false,
  169. disabled: false
  170. },
  171. {
  172. permission: 'write:assets',
  173. hint: 'Can upload assets (such as images and files), as specified in the Page Rules',
  174. warning: false,
  175. restrictedForSystem: false,
  176. disabled: false
  177. },
  178. {
  179. permission: 'read:comments',
  180. hint: 'Can view comments, as specified in the Page Rules',
  181. warning: false,
  182. restrictedForSystem: false,
  183. disabled: false
  184. },
  185. {
  186. permission: 'write:comments',
  187. hint: 'Can post new comments, as specified in the Page Rules',
  188. warning: false,
  189. restrictedForSystem: false,
  190. disabled: false
  191. }
  192. ]
  193. },
  194. {
  195. category: 'Users',
  196. items: [
  197. {
  198. permission: 'write:users',
  199. hint: 'Can create or authorize new users, but not modify existing ones',
  200. warning: false,
  201. restrictedForSystem: true,
  202. disabled: false
  203. },
  204. {
  205. permission: 'manage:users',
  206. hint: 'Can manage all users (but not users with administrative permissions)',
  207. warning: false,
  208. restrictedForSystem: true,
  209. disabled: false
  210. },
  211. {
  212. permission: 'write:groups',
  213. hint: 'Can manage groups and assign CONTENT permissions / page rules',
  214. warning: false,
  215. restrictedForSystem: true,
  216. disabled: false
  217. },
  218. {
  219. permission: 'manage:groups',
  220. hint: 'Can manage groups and assign ANY permissions (but not manage:system) / page rules',
  221. warning: true,
  222. restrictedForSystem: true,
  223. disabled: false
  224. }
  225. ]
  226. },
  227. {
  228. category: 'Administration',
  229. items: [
  230. {
  231. permission: 'manage:navigation',
  232. hint: 'Can manage the site navigation',
  233. warning: false,
  234. restrictedForSystem: true,
  235. disabled: false
  236. },
  237. {
  238. permission: 'manage:theme',
  239. hint: 'Can manage and modify themes',
  240. warning: false,
  241. restrictedForSystem: true,
  242. disabled: false
  243. },
  244. {
  245. permission: 'manage:api',
  246. hint: 'Can generate and revoke API keys',
  247. warning: true,
  248. restrictedForSystem: true,
  249. disabled: false
  250. },
  251. {
  252. permission: 'manage:system',
  253. hint: 'Can manage and access everything. Root administrator.',
  254. warning: true,
  255. restrictedForSystem: true,
  256. disabled: true
  257. }
  258. ]
  259. }
  260. ],
  261. users: [],
  262. headers: [
  263. { text: 'ID', value: 'id', width: 50, align: 'right' },
  264. { text: 'Name', value: 'name' },
  265. { text: 'Email', value: 'email' },
  266. { text: '', value: 'actions', sortable: false, width: 50 }
  267. ],
  268. search: '',
  269. tab: '1'
  270. }
  271. },
  272. computed: {
  273. pages () {
  274. if (this.pagination.rowsPerPage == null || this.pagination.totalItems == null) {
  275. return 0
  276. }
  277. return Math.ceil(this.pagination.totalItems / this.pagination.rowsPerPage)
  278. }
  279. },
  280. watch: {
  281. group(newValue, oldValue) {
  282. this.name = newValue.name
  283. }
  284. },
  285. methods: {
  286. async updateGroup() {
  287. try {
  288. await this.$apollo.mutate({
  289. mutation: updateGroupMutation,
  290. variables: {
  291. id: this.group.id,
  292. name: this.name
  293. },
  294. watchLoading (isLoading) {
  295. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-update')
  296. }
  297. })
  298. this.$store.commit('showNotification', {
  299. style: 'success',
  300. message: `Group changes have been saved.`,
  301. icon: 'check'
  302. })
  303. } catch (err) {
  304. this.$store.commit('showNotification', {
  305. style: 'red',
  306. message: err.message,
  307. icon: 'warning'
  308. })
  309. }
  310. },
  311. async deleteGroup() {
  312. this.deleteGroupDialog = false
  313. try {
  314. await this.$apollo.mutate({
  315. mutation: deleteGroupMutation,
  316. variables: {
  317. id: this.group.id
  318. },
  319. watchLoading (isLoading) {
  320. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-delete')
  321. }
  322. })
  323. this.$store.commit('showNotification', {
  324. style: 'success',
  325. message: `Group ${this.group.name} has been deleted.`,
  326. icon: 'delete'
  327. })
  328. this.$router.replace('/groups')
  329. } catch (err) {
  330. this.$store.commit('showNotification', {
  331. style: 'red',
  332. message: err.message,
  333. icon: 'warning'
  334. })
  335. }
  336. },
  337. async assignUser(id) {
  338. try {
  339. await this.$apollo.mutate({
  340. mutation: assignUserMutation,
  341. variables: {
  342. groupId: this.group.id,
  343. userId: id
  344. },
  345. watchLoading (isLoading) {
  346. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-assign')
  347. }
  348. })
  349. this.$store.commit('showNotification', {
  350. style: 'success',
  351. message: `User has been assigned to ${this.group.name}.`,
  352. icon: 'assignment_ind'
  353. })
  354. this.$apollo.queries.group.refetch()
  355. } catch (err) {
  356. this.$store.commit('showNotification', {
  357. style: 'red',
  358. message: err.message,
  359. icon: 'warning'
  360. })
  361. }
  362. },
  363. async unassignUser(id) {
  364. try {
  365. await this.$apollo.mutate({
  366. mutation: unassignUserMutation,
  367. variables: {
  368. groupId: this.group.id,
  369. userId: id
  370. },
  371. watchLoading (isLoading) {
  372. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-unassign')
  373. }
  374. })
  375. this.$store.commit('showNotification', {
  376. style: 'success',
  377. message: `User has been unassigned from ${this.group.name}.`,
  378. icon: 'assignment_ind'
  379. })
  380. this.$apollo.queries.group.refetch()
  381. } catch (err) {
  382. this.$store.commit('showNotification', {
  383. style: 'red',
  384. message: err.message,
  385. icon: 'warning'
  386. })
  387. }
  388. }
  389. },
  390. apollo: {
  391. group: {
  392. query: groupQuery,
  393. variables() {
  394. return {
  395. id: _.toSafeInteger(this.$route.params.id)
  396. }
  397. },
  398. fetchPolicy: 'network-only',
  399. update: (data) => data.groups.single,
  400. watchLoading (isLoading) {
  401. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-refresh')
  402. }
  403. }
  404. }
  405. }
  406. </script>
  407. <style lang='scss'>
  408. </style>