You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

271 lines
8.4 KiB

  1. <template lang='pug'>
  2. v-container(fluid, grid-list-lg)
  3. v-layout(row wrap)
  4. v-flex(xs12)
  5. .admin-header
  6. img(src='/_assets/svg/icon-social-group.svg', alt='Edit Group', style='width: 80px;')
  7. .admin-header-title
  8. .headline.blue--text.text--darken-2 Edit Group
  9. .subtitle-1.grey--text {{group.name}}
  10. v-spacer
  11. v-btn(color='grey', icon, outlined, to='/groups')
  12. v-icon mdi-arrow-left
  13. v-dialog(v-model='deleteGroupDialog', max-width='500', v-if='!group.isSystem')
  14. template(v-slot:activator='{ on }')
  15. v-btn.ml-3(color='red', icon, outlined, v-on='on')
  16. v-icon(color='red') mdi-trash-can-outline
  17. v-card
  18. .dialog-header.is-red Delete Group?
  19. v-card-text.pa-4 Are you sure you want to delete group #[strong {{ group.name }}]? All users will be unassigned from this group.
  20. v-card-actions
  21. v-spacer
  22. v-btn(text, @click='deleteGroupDialog = false') Cancel
  23. v-btn(color='red', dark, @click='deleteGroup') Delete
  24. v-btn.ml-3(color='success', large, depressed, @click='updateGroup')
  25. v-icon(left) mdi-check
  26. span Update Group
  27. v-card.mt-3
  28. v-tabs.grad-tabs(v-model='tab', :color='$vuetify.theme.dark ? `blue` : `primary`', fixed-tabs, show-arrows, icons-and-text)
  29. v-tab(key='settings')
  30. span Settings
  31. v-icon mdi-cog-box
  32. v-tab(key='permissions')
  33. span Permissions
  34. v-icon mdi-lock-pattern
  35. v-tab(key='rules')
  36. span Page Rules
  37. v-icon mdi-file-lock
  38. v-tab(key='users')
  39. span Users
  40. v-icon mdi-account-group
  41. v-tab-item(key='settings', :transition='false', :reverse-transition='false')
  42. v-card(flat)
  43. template(v-if='group.id <= 2')
  44. v-card-text
  45. v-alert.radius-7.mb-0(
  46. color='orange darken-2'
  47. :class='$vuetify.theme.dark ? "grey darken-4" : "orange lighten-5"'
  48. outlined
  49. :value='true'
  50. icon='mdi-lock-outline'
  51. ) This is a system group and its settings cannot be modified.
  52. v-divider
  53. v-card-text
  54. v-text-field(
  55. outlined
  56. v-model='group.name'
  57. label='Group Name'
  58. hide-details
  59. prepend-icon='mdi-account-group'
  60. style='max-width: 600px;'
  61. :disabled='group.id <= 2'
  62. )
  63. template(v-if='group.id !== 2')
  64. v-divider
  65. v-card-text
  66. v-text-field(
  67. outlined
  68. v-model='group.redirectOnLogin'
  69. label='Redirect on Login'
  70. persistent-hint
  71. hint='The path / URL where the user will be redirected upon successful login.'
  72. prepend-icon='mdi-arrow-top-left-thick'
  73. append-icon='mdi-folder-search'
  74. @click:append='selectPage'
  75. style='max-width: 850px;'
  76. :counter='255'
  77. )
  78. v-tab-item(key='permissions', :transition='false', :reverse-transition='false')
  79. group-permissions(v-model='group', @refresh='refresh')
  80. v-tab-item(key='rules', :transition='false', :reverse-transition='false')
  81. group-rules(v-model='group', @refresh='refresh')
  82. v-tab-item(key='users', :transition='false', :reverse-transition='false')
  83. group-users(v-model='group', @refresh='refresh')
  84. v-card-chin
  85. v-spacer
  86. .caption.grey--text.pr-2 Group ID #[strong {{group.id}}]
  87. page-selector(mode='select', v-model='selectPageModal', :open-handler='selectPageHandle', path='home', :locale='currentLang')
  88. </template>
  89. <script>
  90. import _ from 'lodash'
  91. import gql from 'graphql-tag'
  92. import GroupPermissions from './admin-groups-edit-permissions.vue'
  93. import GroupRules from './admin-groups-edit-rules.vue'
  94. import GroupUsers from './admin-groups-edit-users.vue'
  95. /* global siteConfig */
  96. export default {
  97. components: {
  98. GroupPermissions,
  99. GroupRules,
  100. GroupUsers
  101. },
  102. data() {
  103. return {
  104. group: {
  105. id: 0,
  106. name: '',
  107. isSystem: false,
  108. permissions: [],
  109. pageRules: [],
  110. users: [],
  111. redirectOnLogin: '/'
  112. },
  113. deleteGroupDialog: false,
  114. tab: null,
  115. selectPageModal: false,
  116. currentLang: siteConfig.lang
  117. }
  118. },
  119. methods: {
  120. selectPage () {
  121. this.selectPageModal = true
  122. },
  123. selectPageHandle ({ path, locale }) {
  124. this.group.redirectOnLogin = `/${locale}/${path}`
  125. },
  126. async updateGroup() {
  127. try {
  128. await this.$apollo.mutate({
  129. mutation: gql`
  130. mutation (
  131. $id: Int!
  132. $name: String!
  133. $redirectOnLogin: String!
  134. $permissions: [String]!
  135. $pageRules: [PageRuleInput]!
  136. ) {
  137. groups {
  138. update(
  139. id: $id
  140. name: $name
  141. redirectOnLogin: $redirectOnLogin
  142. permissions: $permissions
  143. pageRules: $pageRules
  144. ) {
  145. responseResult {
  146. succeeded
  147. errorCode
  148. slug
  149. message
  150. }
  151. }
  152. }
  153. }
  154. `,
  155. variables: {
  156. id: this.group.id,
  157. name: this.group.name,
  158. redirectOnLogin: this.group.redirectOnLogin,
  159. permissions: this.group.permissions,
  160. pageRules: this.group.pageRules
  161. },
  162. watchLoading (isLoading) {
  163. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-update')
  164. }
  165. })
  166. this.$store.commit('showNotification', {
  167. style: 'success',
  168. message: `Group changes have been saved.`,
  169. icon: 'check'
  170. })
  171. } catch (err) {
  172. this.$store.commit('pushGraphError', err)
  173. }
  174. },
  175. async deleteGroup() {
  176. this.deleteGroupDialog = false
  177. try {
  178. await this.$apollo.mutate({
  179. mutation: gql`
  180. mutation ($id: Int!) {
  181. groups {
  182. delete(id: $id) {
  183. responseResult {
  184. succeeded
  185. errorCode
  186. slug
  187. message
  188. }
  189. }
  190. }
  191. }
  192. `,
  193. variables: {
  194. id: this.group.id
  195. },
  196. watchLoading (isLoading) {
  197. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-delete')
  198. }
  199. })
  200. this.$store.commit('showNotification', {
  201. style: 'success',
  202. message: `Group ${this.group.name} has been deleted.`,
  203. icon: 'delete'
  204. })
  205. this.$router.replace('/groups')
  206. } catch (err) {
  207. this.$store.commit('pushGraphError', err)
  208. }
  209. },
  210. async refresh() {
  211. return this.$apollo.queries.group.refetch()
  212. }
  213. },
  214. apollo: {
  215. group: {
  216. query: gql`
  217. query ($id: Int!) {
  218. groups {
  219. single(id: $id) {
  220. id
  221. name
  222. redirectOnLogin
  223. isSystem
  224. permissions
  225. pageRules {
  226. id
  227. path
  228. roles
  229. match
  230. deny
  231. locales
  232. }
  233. users {
  234. id
  235. name
  236. email
  237. }
  238. createdAt
  239. updatedAt
  240. }
  241. }
  242. }
  243. `,
  244. variables() {
  245. return {
  246. id: _.toSafeInteger(this.$route.params.id)
  247. }
  248. },
  249. fetchPolicy: 'network-only',
  250. update: (data) => _.cloneDeep(data.groups.single),
  251. watchLoading (isLoading) {
  252. this.$store.commit(`loading${isLoading ? 'Start' : 'Stop'}`, 'admin-groups-refresh')
  253. }
  254. }
  255. }
  256. }
  257. </script>
  258. <style lang='scss'>
  259. </style>