GroupEditOverlay.vue 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  1. <template lang="pug">
  2. q-layout(view='hHh lpR fFf', container)
  3. q-header.card-header.q-px-md.q-py-sm
  4. q-icon(name='img:/_assets/icons/fluent-people.svg', left, size='md')
  5. div
  6. span {{t(`admin.groups.edit`)}}
  7. .text-caption {{state.group.name}}
  8. q-space
  9. q-btn-group(push)
  10. q-btn(
  11. push
  12. color='grey-6'
  13. text-color='white'
  14. :aria-label='t(`common.actions.refresh`)'
  15. icon='las la-redo-alt'
  16. @click='refresh'
  17. )
  18. q-tooltip(anchor='center left', self='center right') {{t(`common.actions.refresh`)}}
  19. q-btn(
  20. push
  21. color='white'
  22. text-color='grey-7'
  23. :label='t(`common.actions.close`)'
  24. icon='las la-times'
  25. @click='close'
  26. )
  27. q-btn(
  28. push
  29. color='positive'
  30. text-color='white'
  31. :label='t(`common.actions.save`)'
  32. icon='las la-check'
  33. )
  34. q-drawer.bg-dark-6(:model-value='true', :width='250', dark)
  35. q-list(padding, v-show='!state.isLoading')
  36. template(v-for='sc of sections', :key='`section-` + sc.key')
  37. q-item(
  38. v-if='!(isGuestGroup && sc.excludeGuests)'
  39. clickable
  40. :to='{ params: { section: sc.key } }'
  41. active-class='bg-primary text-white'
  42. :disabled='sc.disabled'
  43. )
  44. q-item-section(side)
  45. q-icon(:name='sc.icon', color='white')
  46. q-item-section {{sc.text}}
  47. q-item-section(side, v-if='sc.usersTotal')
  48. q-badge(color='dark-3', :label='state.usersTotal')
  49. q-item-section(side, v-if='sc.rulesTotal && state.group.rules')
  50. q-badge(color='dark-3', :label='state.group.rules.length')
  51. q-page-container
  52. q-page(v-if='state.isLoading')
  53. //- -----------------------------------------------------------------------
  54. //- OVERVIEW
  55. //- -----------------------------------------------------------------------
  56. q-page(v-else-if='route.params.section === `overview`')
  57. .q-pa-md
  58. .row.q-col-gutter-md
  59. .col-12.col-lg-8
  60. q-card.shadow-1.q-pb-sm
  61. q-card-section
  62. .text-subtitle1 {{t('admin.groups.general')}}
  63. q-item
  64. blueprint-icon(icon='team')
  65. q-item-section
  66. q-item-label {{t(`admin.groups.name`)}}
  67. q-item-label(caption) {{t(`admin.groups.nameHint`)}}
  68. q-item-section
  69. q-input(
  70. outlined
  71. v-model='state.group.name'
  72. dense
  73. :rules='groupNameValidation'
  74. hide-bottom-space
  75. :aria-label='t(`admin.groups.name`)'
  76. :disable='isGuestGroup'
  77. )
  78. q-card.shadow-1.q-pb-sm.q-mt-md(v-if='!isGuestGroup')
  79. q-card-section
  80. .text-subtitle1 {{t('admin.groups.authBehaviors')}}
  81. q-item
  82. blueprint-icon(icon='double-right')
  83. q-item-section
  84. q-item-label {{t(`admin.groups.redirectOnLogin`)}}
  85. q-item-label(caption) {{t(`admin.groups.redirectOnLoginHint`)}}
  86. q-item-section
  87. q-input(
  88. outlined
  89. v-model='state.group.redirectOnLogin'
  90. dense
  91. :aria-label='t(`admin.groups.redirectOnLogin`)'
  92. )
  93. q-separator.q-my-sm(inset)
  94. q-item
  95. blueprint-icon(icon='chevron-right')
  96. q-item-section
  97. q-item-label {{t(`admin.groups.redirectOnFirstLogin`)}}
  98. q-item-label(caption) {{t(`admin.groups.redirectOnFirstLoginHint`)}}
  99. q-item-section
  100. q-input(
  101. outlined
  102. v-model='state.group.redirectOnFirstLogin'
  103. dense
  104. :aria-label='t(`admin.groups.redirectOnLogin`)'
  105. )
  106. q-separator.q-my-sm(inset)
  107. q-item
  108. blueprint-icon(icon='exit')
  109. q-item-section
  110. q-item-label {{t(`admin.groups.redirectOnLogout`)}}
  111. q-item-label(caption) {{t(`admin.groups.redirectOnLogoutHint`)}}
  112. q-item-section
  113. q-input(
  114. outlined
  115. v-model='state.group.redirectOnLogout'
  116. dense
  117. :aria-label='t(`admin.groups.redirectOnLogout`)'
  118. )
  119. .col-12.col-lg-4
  120. q-card.shadow-1.q-pb-sm
  121. q-card-section
  122. .text-subtitle1 {{t('admin.groups.info')}}
  123. q-item
  124. blueprint-icon(icon='team', :hue-rotate='-45')
  125. q-item-section
  126. q-item-label {{t(`common.field.id`)}}
  127. q-item-label: strong {{state.group.id}}
  128. q-separator.q-my-sm(inset)
  129. q-item
  130. blueprint-icon(icon='calendar-plus', :hue-rotate='-45')
  131. q-item-section
  132. q-item-label {{t(`common.field.createdOn`)}}
  133. q-item-label: strong {{humanizeDate(state.group.createdAt)}}
  134. q-separator.q-my-sm(inset)
  135. q-item
  136. blueprint-icon(icon='summertime', :hue-rotate='-45')
  137. q-item-section
  138. q-item-label {{t(`common.field.lastUpdated`)}}
  139. q-item-label: strong {{humanizeDate(state.group.updatedAt)}}
  140. //- -----------------------------------------------------------------------
  141. //- RULES
  142. //- -----------------------------------------------------------------------
  143. q-page(v-else-if='route.params.section === `rules`')
  144. q-toolbar.q-pl-md(
  145. :class='$q.dark.isActive ? `bg-dark-3` : `bg-white`'
  146. )
  147. .text-subtitle1 {{t('admin.groups.rules')}}
  148. q-space
  149. q-btn.acrylic-btn.q-mr-sm(
  150. icon='las la-question-circle'
  151. flat
  152. color='grey'
  153. type='a'
  154. :href='siteStore.docsBase + `/admin/groups#rules`'
  155. target='_blank'
  156. )
  157. q-btn.acrylic-btn.q-mr-sm(
  158. flat
  159. color='indigo'
  160. icon='las la-file-export'
  161. @click='exportRules'
  162. )
  163. q-tooltip {{t('admin.groups.exportRules')}}
  164. q-btn.acrylic-btn.q-mr-sm(
  165. flat
  166. color='indigo'
  167. icon='las la-file-import'
  168. @click='importRules'
  169. )
  170. q-tooltip {{t('admin.groups.importRules')}}
  171. q-btn(
  172. unelevated
  173. color='primary'
  174. icon='las la-plus'
  175. label='New Rule'
  176. @click='newRule'
  177. )
  178. q-separator
  179. .q-pa-md
  180. q-banner(
  181. v-if='!state.group.rules || state.group.rules.length < 1'
  182. rounded
  183. :class='$q.dark.isActive ? `bg-negative text-white` : `bg-grey-4 text-grey-9`'
  184. ) {{t('admin.groups.rulesNone')}}
  185. q-card.shadow-1.q-pb-sm(v-else)
  186. q-card-section
  187. .admin-groups-rule(
  188. v-for='(rule, idx) of state.group.rules'
  189. :key='rule.id'
  190. )
  191. .admin-groups-rule-icon(:class='getRuleModeColor(rule.mode)')
  192. q-icon.cursor-pointer(
  193. :name='getRuleModeIcon(rule.mode)'
  194. color='white'
  195. @click='rule.mode = getNextRuleMode(rule.mode)'
  196. )
  197. .admin-groups-rule-name
  198. .admin-groups-rule-name-text: strong(:class='getRuleModeColor(rule.mode)') {{getRuleModeName(rule.mode)}}
  199. q-separator.q-ml-sm.q-mr-xs(vertical)
  200. input(
  201. type='text'
  202. v-model='rule.name'
  203. placeholder='Rule Name'
  204. )
  205. q-card.admin-groups-rule-card.q-mt-md(flat)
  206. q-card-section.admin-groups-rule-card-permissions(:class='getRuleModeClass(rule.mode)')
  207. q-select.q-mt-xs(
  208. standout
  209. v-model='rule.roles'
  210. emit-value
  211. map-options
  212. dense
  213. :aria-label='t(`admin.groups.ruleSites`)'
  214. :options='rules'
  215. placeholder='Select permissions...'
  216. option-value='permission'
  217. option-label='title'
  218. options-dense
  219. multiple
  220. use-chips
  221. stack-label
  222. )
  223. template(v-slot:selected-item='scope')
  224. q-chip(
  225. square
  226. dense
  227. :tabindex='scope.tabindex'
  228. :color='getRuleModeBgColor(rule.mode)'
  229. text-color='white'
  230. )
  231. span.text-caption {{ scope.opt.title }}
  232. template(v-slot:option='{ itemProps, itemEvents, opt, selected, toggleOption }')
  233. q-item(v-bind='itemProps', v-on='itemEvents')
  234. q-item-section(side)
  235. q-toggle(
  236. :model-value='selected'
  237. @update:model-value='toggleOption(opt)'
  238. color='primary'
  239. checked-icon='las la-check'
  240. unchecked-icon='las la-times'
  241. :aria-label='opt.label'
  242. )
  243. //- q-item-section(side, style='flex-basis: 150px;')
  244. //- q-chip.text-caption(
  245. //- square
  246. //- color='teal'
  247. //- text-color='white'
  248. //- dense
  249. //- ) {{opt.permission}}
  250. q-item-section
  251. q-item-label {{opt.title}}
  252. q-item-label(caption) {{opt.hint}}
  253. q-btn.acrylic-btn.q-ml-md(
  254. flat
  255. icon='las la-trash'
  256. color='negative'
  257. padding='sm sm'
  258. size='md',
  259. @click='deleteRule(rule.id)'
  260. )
  261. q-card-section(horizontal)
  262. q-card-section.admin-groups-rule-card-filters
  263. .text-caption Applies to...
  264. q-select.q-mt-xs(
  265. standout
  266. v-model='rule.sites'
  267. emit-value
  268. map-options
  269. dense
  270. :aria-label='t(`admin.groups.ruleSites`)'
  271. :options='adminStore.sites'
  272. option-value='id'
  273. option-label='title'
  274. multiple
  275. behavior='dialog'
  276. :display-value='t(`admin.groups.selectedSites`, rule.sites.length, { count: rule.sites.length })'
  277. )
  278. template(v-slot:option='{ itemProps, itemEvents, opt, selected, toggleOption }')
  279. q-item(v-bind='itemProps', v-on='itemEvents')
  280. q-item-section
  281. q-item-label {{opt.title}}
  282. q-item-section(side)
  283. q-toggle(
  284. :model-value='selected'
  285. @update:model-value='toggleOption(opt)'
  286. color='primary'
  287. checked-icon='las la-check'
  288. unchecked-icon='las la-times'
  289. :aria-label='opt.label'
  290. )
  291. q-select.q-mt-sm(
  292. standout
  293. v-model='rule.locales'
  294. emit-value
  295. map-options
  296. dense
  297. :aria-label='t(`admin.groups.ruleLocales`)'
  298. :options='adminStore.locales'
  299. option-value='code'
  300. option-label='name'
  301. multiple
  302. behavior='dialog'
  303. :display-value='t(`admin.groups.selectedLocales`, { n: rule.locales.length > 0 ? rule.locales[0].toUpperCase() : rule.locales.length }, rule.locales.length)'
  304. )
  305. template(v-slot:option='{ itemProps, opt, selected, toggleOption }')
  306. q-item(v-bind='itemProps')
  307. q-item-section
  308. q-item-label {{opt.name}}
  309. q-item-section(side)
  310. q-toggle(
  311. :model-value='selected'
  312. @update:model-value='toggleOption(opt)'
  313. color='primary'
  314. checked-icon='las la-check'
  315. unchecked-icon='las la-times'
  316. :aria-label='opt.name'
  317. )
  318. q-card-section.admin-groups-rule-card-pattern
  319. .text-caption Pattern
  320. q-select.q-mt-xs(
  321. standout
  322. v-model='rule.match'
  323. emit-value
  324. map-options
  325. dense
  326. :aria-label='t(`admin.groups.ruleMatch`)'
  327. :options=`[
  328. { label: t('admin.groups.ruleMatchStart'), value: 'START' },
  329. { label: t('admin.groups.ruleMatchEnd'), value: 'END' },
  330. { label: t('admin.groups.ruleMatchRegex'), value: 'REGEX' },
  331. { label: t('admin.groups.ruleMatchTag'), value: 'TAG' },
  332. { label: t('admin.groups.ruleMatchTagAll'), value: 'TAGALL' },
  333. { label: t('admin.groups.ruleMatchExact'), value: 'EXACT' }
  334. ]`
  335. )
  336. q-input.q-mt-sm(
  337. standout
  338. v-model='rule.path'
  339. dense
  340. :prefix='[`START`, `REGEX`, `EXACT`].includes(rule.match) ? `/` : null'
  341. :suffix='rule.match === `REGEX` ? `/` : null'
  342. :aria-label='t(`admin.groups.rulePath`)'
  343. )
  344. //- -----------------------------------------------------------------------
  345. //- PERMISSIONS
  346. //- -----------------------------------------------------------------------
  347. q-page(v-else-if='route.params.section === `permissions`')
  348. .q-pa-md
  349. .row.q-col-gutter-md
  350. .col-12.col-lg-6
  351. q-card.shadow-1.q-pb-sm
  352. .flex.justify-between
  353. q-card-section
  354. .text-subtitle1 {{t(`admin.groups.permissions`)}}
  355. q-card-section
  356. q-btn.acrylic-btn(
  357. icon='las la-question-circle'
  358. flat
  359. color='grey'
  360. type='a'
  361. :href='siteStore.docsBase + `/admin/groups#permissions`'
  362. target='_blank'
  363. )
  364. template(v-for='(perm, idx) of permissions', :key='perm.permission')
  365. q-item(tag='label', v-ripple)
  366. q-item-section.items-center(style='flex: 0 0 40px;')
  367. q-icon(
  368. name='las la-comments'
  369. color='primary'
  370. size='sm'
  371. )
  372. q-item-section
  373. q-item-label {{perm.permission}}
  374. q-item-label(caption) {{perm.hint}}
  375. q-item-section(avatar)
  376. q-toggle(
  377. v-model='state.group.permissions'
  378. :val='perm.permission'
  379. color='primary'
  380. checked-icon='las la-check'
  381. unchecked-icon='las la-times'
  382. :aria-label='t(`admin.general.allowComments`)'
  383. )
  384. q-separator.q-my-sm(inset, v-if='idx < permissions.length - 1')
  385. //- -----------------------------------------------------------------------
  386. //- USERS
  387. //- -----------------------------------------------------------------------
  388. q-page(v-else-if='route.params.section === `users`')
  389. q-toolbar(
  390. :class='$q.dark.isActive ? `bg-dark-3` : `bg-white`'
  391. )
  392. .text-subtitle1 {{t('admin.groups.users')}}
  393. q-space
  394. q-btn.acrylic-btn.q-mr-sm(
  395. icon='las la-question-circle'
  396. flat
  397. color='grey'
  398. type='a'
  399. :href='siteStore.docsBase + `/admin/groups#users`'
  400. target='_blank'
  401. )
  402. q-input.denser.fill-outline.q-mr-sm(
  403. outlined
  404. v-model='state.usersFilter'
  405. :placeholder='t(`admin.groups.filterUsers`)'
  406. dense
  407. )
  408. template(#prepend)
  409. q-icon(name='las la-search')
  410. q-btn.q-mr-sm.acrylic-btn(
  411. icon='las la-redo-alt'
  412. flat
  413. color='secondary'
  414. @click='refreshUsers'
  415. )
  416. q-btn.q-mr-xs(
  417. unelevated
  418. icon='las la-user-plus'
  419. :label='t(`admin.groups.assignUser`)'
  420. color='primary'
  421. @click='assignUser'
  422. )
  423. q-separator
  424. .q-pa-md
  425. q-banner(
  426. v-if='!state.users || state.users.length < 1'
  427. rounded
  428. :class='$q.dark.isActive ? `bg-negative text-white` : `bg-grey-4 text-grey-9`'
  429. ) {{t('admin.groups.usersNone')}}
  430. q-card.shadow-1
  431. q-table(
  432. :rows='state.users'
  433. :columns='usersHeaders'
  434. row-key='id'
  435. flat
  436. hide-header
  437. hide-bottom
  438. :rows-per-page-options='[0]'
  439. :loading='state.isLoadingUsers'
  440. )
  441. template(v-slot:body-cell-id='props')
  442. q-td(:props='props')
  443. q-icon(name='las la-user', color='primary', size='sm')
  444. template(v-slot:body-cell-name='props')
  445. q-td(:props='props')
  446. .flex.items-center
  447. strong {{props.value}}
  448. q-icon.q-ml-sm(
  449. v-if='props.row.isSystem'
  450. name='las la-lock'
  451. color='pink'
  452. )
  453. q-icon.q-ml-sm(
  454. v-if='!props.row.isActive'
  455. name='las la-ban'
  456. color='pink'
  457. )
  458. template(v-slot:body-cell-email='props')
  459. q-td(:props='props')
  460. em {{ props.value }}
  461. template(v-slot:body-cell-date='props')
  462. q-td(:props='props')
  463. i18n-t.text-caption(keypath='admin.users.createdAt', tag='div')
  464. template(#date)
  465. strong {{ humanizeDate(props.value) }}
  466. i18n-t.text-caption(
  467. v-if='props.row.lastLoginAt'
  468. keypath='admin.users.lastLoginAt'
  469. tag='div'
  470. )
  471. template(#date)
  472. strong {{ humanizeDate(props.row.lastLoginAt) }}
  473. template(v-slot:body-cell-edit='props')
  474. q-td(:props='props')
  475. q-btn.acrylic-btn.q-mr-sm(
  476. v-if='!props.row.isSystem'
  477. flat
  478. :to='`/_admin/users/` + props.row.id'
  479. icon='las la-pen'
  480. color='indigo'
  481. :label='t(`common.actions.edit`)'
  482. no-caps
  483. )
  484. q-btn.acrylic-btn(
  485. v-if='!props.row.isSystem'
  486. flat
  487. icon='las la-user-minus'
  488. color='accent'
  489. @click='unassignUser(props.row)'
  490. )
  491. .flex.flex-center.q-mt-md(v-if='usersTotalPages > 1')
  492. q-pagination(
  493. v-model='state.usersPage'
  494. :max='usersTotalPages'
  495. :max-pages='9'
  496. boundary-numbers
  497. direction-links
  498. )
  499. </template>
  500. <script setup>
  501. import gql from 'graphql-tag'
  502. import { DateTime } from 'luxon'
  503. import { v4 as uuid } from 'uuid'
  504. import { cloneDeep, some } from 'lodash-es'
  505. import { fileOpen } from 'browser-fs-access'
  506. import { useI18n } from 'vue-i18n'
  507. import { exportFile, useQuasar } from 'quasar'
  508. import { computed, onMounted, reactive, watch } from 'vue'
  509. import { useRouter, useRoute } from 'vue-router'
  510. import { useAdminStore } from 'src/stores/admin'
  511. import { useSiteStore } from 'src/stores/site'
  512. // QUASAR
  513. const $q = useQuasar()
  514. // STORES
  515. const adminStore = useAdminStore()
  516. const siteStore = useSiteStore()
  517. // ROUTER
  518. const router = useRouter()
  519. const route = useRoute()
  520. // I18N
  521. const { t } = useI18n()
  522. // DATA
  523. const state = reactive({
  524. group: {
  525. rules: []
  526. },
  527. isLoading: false,
  528. users: [],
  529. isLoadingUsers: false,
  530. usersFilter: '',
  531. usersPage: 1,
  532. usersPageSize: 15,
  533. usersTotal: 0
  534. })
  535. const sections = [
  536. { key: 'overview', text: t('admin.groups.overview'), icon: 'las la-users' },
  537. { key: 'rules', text: t('admin.groups.rules'), icon: 'las la-file-invoice', rulesTotal: true },
  538. { key: 'permissions', text: t('admin.groups.permissions'), icon: 'las la-list-alt', excludeGuests: true },
  539. { key: 'users', text: t('admin.groups.users'), icon: 'las la-user', usersTotal: true, excludeGuests: true }
  540. ]
  541. const usersHeaders = [
  542. {
  543. align: 'center',
  544. field: 'id',
  545. name: 'id',
  546. sortable: false,
  547. style: 'width: 20px'
  548. },
  549. {
  550. label: t('common.field.name'),
  551. align: 'left',
  552. field: 'name',
  553. name: 'name',
  554. sortable: true
  555. },
  556. {
  557. label: t('admin.users.email'),
  558. align: 'left',
  559. field: 'email',
  560. name: 'email',
  561. sortable: false
  562. },
  563. {
  564. align: 'left',
  565. field: 'createdAt',
  566. name: 'date',
  567. sortable: false
  568. },
  569. {
  570. label: '',
  571. align: 'right',
  572. field: 'edit',
  573. name: 'edit',
  574. sortable: false,
  575. style: 'width: 250px'
  576. }
  577. ]
  578. const permissions = [
  579. {
  580. permission: 'access:admin',
  581. hint: 'Can access the administration area.',
  582. warning: false,
  583. restrictedForSystem: true,
  584. disabled: false
  585. },
  586. {
  587. permission: 'manage:users',
  588. hint: 'Can create / manage users (but not users with administrative permissions)',
  589. warning: false,
  590. restrictedForSystem: true,
  591. disabled: false
  592. },
  593. {
  594. permission: 'manage:groups',
  595. hint: 'Can create / manage groups and assign permissions (but not manage:system) / page rules',
  596. warning: true,
  597. restrictedForSystem: true,
  598. disabled: false
  599. },
  600. {
  601. permission: 'manage:navigation',
  602. hint: 'Can manage site navigation',
  603. warning: false,
  604. restrictedForSystem: true,
  605. disabled: false
  606. },
  607. {
  608. permission: 'manage:theme',
  609. hint: 'Can modify site theme settings',
  610. warning: false,
  611. restrictedForSystem: true,
  612. disabled: false
  613. },
  614. {
  615. permission: 'manage:sites',
  616. hint: 'Can create / manage sites',
  617. warning: true,
  618. restrictedForSystem: true,
  619. disabled: false
  620. },
  621. {
  622. permission: 'manage:system',
  623. hint: 'Can manage and access everything. Root administrator.',
  624. warning: true,
  625. restrictedForSystem: true,
  626. disabled: true
  627. }
  628. ]
  629. const rules = [
  630. {
  631. permission: 'read:pages',
  632. title: 'Read Pages',
  633. hint: 'Can view and search pages.',
  634. warning: false,
  635. restrictedForSystem: false,
  636. disabled: false
  637. },
  638. {
  639. permission: 'write:pages',
  640. title: 'Write Pages',
  641. hint: 'Can create and edit pages.',
  642. warning: false,
  643. restrictedForSystem: true,
  644. disabled: false
  645. },
  646. {
  647. permission: 'review:pages',
  648. title: 'Review Pages',
  649. hint: 'Can review and approve edits submitted by users.',
  650. warning: false,
  651. restrictedForSystem: true,
  652. disabled: false
  653. },
  654. {
  655. permission: 'manage:pages',
  656. title: 'Manage Pages',
  657. hint: 'Can move existing pages to other locations the user has write access to.',
  658. warning: false,
  659. restrictedForSystem: true,
  660. disabled: false
  661. },
  662. {
  663. permission: 'delete:pages',
  664. title: 'Delete Pages',
  665. hint: 'Can delete existing pages.',
  666. warning: false,
  667. restrictedForSystem: true,
  668. disabled: false
  669. },
  670. {
  671. permission: 'write:styles',
  672. title: 'Use CSS',
  673. hint: 'Can insert CSS styles in pages.',
  674. warning: false,
  675. restrictedForSystem: true,
  676. disabled: false
  677. },
  678. {
  679. permission: 'write:scripts',
  680. title: 'Use JavaScript',
  681. hint: 'Can insert JavaScript in pages.',
  682. warning: false,
  683. restrictedForSystem: true,
  684. disabled: false
  685. },
  686. {
  687. permission: 'read:source',
  688. title: 'View Page Source',
  689. hint: 'Can view pages source.',
  690. warning: false,
  691. restrictedForSystem: false,
  692. disabled: false
  693. },
  694. {
  695. permission: 'read:history',
  696. title: 'View Page History',
  697. hint: 'Can view previous versions of pages.',
  698. warning: false,
  699. restrictedForSystem: false,
  700. disabled: false
  701. },
  702. {
  703. permission: 'read:assets',
  704. title: 'View Assets',
  705. hint: 'Can view / use assets (such as images and files) in pages.',
  706. warning: false,
  707. restrictedForSystem: false,
  708. disabled: false
  709. },
  710. {
  711. permission: 'write:assets',
  712. title: 'Upload Assets',
  713. hint: 'Can upload new assets (such as images and files).',
  714. warning: false,
  715. restrictedForSystem: true,
  716. disabled: false
  717. },
  718. {
  719. permission: 'manage:assets',
  720. title: 'Manage Assets',
  721. hint: 'Can edit and delete existing assets (such as images and files).',
  722. warning: false,
  723. restrictedForSystem: true,
  724. disabled: false
  725. },
  726. {
  727. permission: 'read:comments',
  728. title: 'Read Comments',
  729. hint: 'Can view page comments.',
  730. warning: false,
  731. restrictedForSystem: false,
  732. disabled: false
  733. },
  734. {
  735. permission: 'write:comments',
  736. title: 'Write Comments',
  737. hint: 'Can post new comments on pages.',
  738. warning: false,
  739. restrictedForSystem: false,
  740. disabled: false
  741. },
  742. {
  743. permission: 'manage:comments',
  744. title: 'Manage Comments',
  745. hint: 'Can edit and delete existing page comments.',
  746. warning: false,
  747. restrictedForSystem: true,
  748. disabled: false
  749. }
  750. ]
  751. // VALIDATION RULES
  752. const groupNameValidation = [
  753. val => /^[^<>"]+$/.test(val) || t('admin.groups.nameInvalidChars')
  754. ]
  755. // COMPUTED
  756. const usersTotalPages = computed(() => {
  757. if (state.usersTotal < 1) { return 0 }
  758. return Math.ceil(state.usersTotal / state.usersPageSize)
  759. })
  760. const isGuestGroup = computed(() => {
  761. return adminStore.overlayOpts.id === '10000000-0000-4000-8000-000000000001'
  762. })
  763. // WATCHERS
  764. watch(() => route.params.section, checkRoute)
  765. watch([() => state.usersPage, () => state.usersFilter], refreshUsers)
  766. // METHODS
  767. function close () {
  768. adminStore.$patch({ overlay: '' })
  769. }
  770. function checkRoute () {
  771. if (!route.params.section) {
  772. router.replace({ params: { section: 'overview' } })
  773. } else if (route.params.section === 'users') {
  774. refreshUsers()
  775. }
  776. }
  777. function humanizeDate (val) {
  778. if (!val) { return '---' }
  779. return DateTime.fromISO(val).toLocaleString(DateTime.DATETIME_FULL)
  780. }
  781. function getRuleModeColor (mode) {
  782. return ({
  783. DENY: 'text-negative',
  784. ALLOW: 'text-positive',
  785. FORCEALLOW: 'text-blue'
  786. })[mode]
  787. }
  788. function getRuleModeBgColor (mode) {
  789. return ({
  790. DENY: 'negative',
  791. ALLOW: 'positive',
  792. FORCEALLOW: 'blue'
  793. })[mode]
  794. }
  795. function getRuleModeClass (mode) {
  796. return 'is-' + mode.toLowerCase()
  797. }
  798. function getRuleModeIcon (mode) {
  799. return ({
  800. DENY: 'las la-ban',
  801. ALLOW: 'las la-check',
  802. FORCEALLOW: 'las la-check-double'
  803. })[mode] || 'las la-frog'
  804. }
  805. function getNextRuleMode (mode) {
  806. return ({
  807. DENY: 'FORCEALLOW',
  808. ALLOW: 'DENY',
  809. FORCEALLOW: 'ALLOW'
  810. })[mode] || 'ALLOW'
  811. }
  812. function getRuleModeName (mode) {
  813. switch (mode) {
  814. case 'ALLOW': return t('admin.groups.ruleAllow')
  815. case 'DENY': return t('admin.groups.ruleDeny')
  816. case 'FORCEALLOW': return t('admin.groups.ruleForceAllow')
  817. default: return '???'
  818. }
  819. }
  820. function refresh () {
  821. fetchGroup()
  822. }
  823. async function fetchGroup () {
  824. state.isLoading = true
  825. try {
  826. const resp = await APOLLO_CLIENT.query({
  827. query: gql`
  828. query adminFetchGroup (
  829. $id: UUID!
  830. ) {
  831. groupById(
  832. id: $id
  833. ) {
  834. id
  835. name
  836. redirectOnLogin
  837. redirectOnFirstLogin
  838. redirectOnLogout
  839. isSystem
  840. permissions
  841. rules {
  842. id
  843. name
  844. path
  845. roles
  846. match
  847. mode
  848. locales
  849. sites
  850. }
  851. userCount
  852. createdAt
  853. updatedAt
  854. }
  855. }
  856. `,
  857. variables: {
  858. id: adminStore.overlayOpts.id
  859. },
  860. fetchPolicy: 'network-only'
  861. })
  862. if (resp?.data?.groupById) {
  863. state.group = cloneDeep(resp.data.groupById)
  864. state.usersTotal = state.group.userCount ?? 0
  865. } else {
  866. throw new Error('An unexpected error occured while fetching group details.')
  867. }
  868. } catch (err) {
  869. $q.notify({
  870. type: 'negative',
  871. message: err.message
  872. })
  873. }
  874. state.isLoading = false
  875. }
  876. function newRule () {
  877. state.group.rules.push({
  878. id: uuid(),
  879. name: t('admin.groups.ruleUntitled'),
  880. mode: 'ALLOW',
  881. match: 'START',
  882. roles: [],
  883. path: '',
  884. locales: [],
  885. sites: []
  886. })
  887. }
  888. function deleteRule (id) {
  889. state.group.rules = state.group.rules.filter(r => r.id !== id)
  890. }
  891. function exportRules () {
  892. if (state.group.rules.length < 1) {
  893. return $q.notify({
  894. type: 'negative',
  895. message: t('admin.groups.exportRulesNoneError')
  896. })
  897. }
  898. const rules = state.group.rules.map(({ __typename, ...r }) => r)
  899. exportFile('rules.json', JSON.stringify(rules, null, 2), { mimeType: 'application/json;charset=UTF-8' })
  900. }
  901. async function importRules () {
  902. try {
  903. const blob = await fileOpen({
  904. mimeTypes: ['application/json'],
  905. extensions: ['.json'],
  906. startIn: 'downloads',
  907. excludeAcceptAllOption: true
  908. })
  909. const rulesRaw = await blob.text()
  910. const rules = JSON.parse(rulesRaw)
  911. if (!Array.isArray(rules) || rules.length < 1) {
  912. throw new Error('Invalid Rules Format')
  913. }
  914. $q.dialog({
  915. title: t('admin.groups.importModeTitle'),
  916. message: t('admin.groups.importModeText'),
  917. options: {
  918. model: 'replace',
  919. type: 'radio',
  920. items: [
  921. { label: t('admin.groups.importModeReplace'), value: 'replace' },
  922. { label: t('admin.groups.importModeAdd'), value: 'add' }
  923. ]
  924. },
  925. persistent: true
  926. }).onOk(choice => {
  927. if (choice === 'replace') {
  928. state.group.rules = []
  929. }
  930. state.group.rules = [
  931. ...state.group.rules,
  932. ...rules.map(r => ({
  933. id: uuid(),
  934. name: r.name || t('admin.groups.ruleUntitled'),
  935. mode: ['ALLOW', 'DENY', 'FORCEALLOW'].includes(r.mode) ? r.mode : 'DENY',
  936. match: ['START', 'END', 'REGEX', 'TAG', 'TAGALL', 'EXACT'].includes(r.match) ? r.match : 'START',
  937. roles: r.roles || [],
  938. path: r.path || '',
  939. locales: r.locales.filter(l => some(adminStore.locales, ['code', l])),
  940. sites: r.sites.filter(s => some(adminStore.sites, ['id', s]))
  941. }))
  942. ]
  943. $q.notify({
  944. type: 'positive',
  945. message: t('admin.groups.importSuccess')
  946. })
  947. })
  948. } catch (err) {
  949. $q.notify({
  950. type: 'negative',
  951. message: t('admin.groups.importFailed') + ` [${err.message}]`
  952. })
  953. }
  954. }
  955. async function refreshUsers () {
  956. state.isLoadingUsers = true
  957. try {
  958. const resp = await APOLLO_CLIENT.query({
  959. query: gql`
  960. query adminFetchGroupUsers (
  961. $filter: String
  962. $page: Int
  963. $pageSize: Int
  964. $groupId: UUID!
  965. ) {
  966. groupById (
  967. id: $groupId
  968. ) {
  969. id
  970. userCount
  971. users (
  972. filter: $filter
  973. page: $page
  974. pageSize: $pageSize
  975. ) {
  976. id
  977. name
  978. email
  979. isSystem
  980. isActive
  981. createdAt
  982. lastLoginAt
  983. }
  984. }
  985. }
  986. `,
  987. variables: {
  988. filter: state.usersFilter,
  989. page: state.usersPage,
  990. pageSize: state.usersPageSize,
  991. groupId: adminStore.overlayOpts.id
  992. },
  993. fetchPolicy: 'network-only'
  994. })
  995. if (resp?.data?.groupById?.users) {
  996. state.usersTotal = resp.data.groupById.userCount ?? 0
  997. state.users = cloneDeep(resp.data.groupById.users)
  998. } else {
  999. throw new Error('An unexpected error occured while fetching group users.')
  1000. }
  1001. } catch (err) {
  1002. $q.notify({
  1003. type: 'negative',
  1004. message: err.message
  1005. })
  1006. }
  1007. state.isLoadingUsers = false
  1008. }
  1009. function assignUser () {
  1010. }
  1011. function unassignUser () {
  1012. }
  1013. // MOUNTED
  1014. onMounted(() => {
  1015. checkRoute()
  1016. fetchGroup()
  1017. })
  1018. </script>
  1019. <style lang="scss">
  1020. .admin-groups-rule {
  1021. position: relative;
  1022. padding: 10px 0 24px 40px;
  1023. &-icon {
  1024. position: absolute;
  1025. top: 0;
  1026. left: 0;
  1027. bottom: 0;
  1028. width: 31px;
  1029. &::before {
  1030. position: absolute;
  1031. content: "";
  1032. border-radius: 100%;
  1033. width: 31px;
  1034. height: 31px;
  1035. background-color: currentColor;
  1036. top: 4px;
  1037. }
  1038. &::after {
  1039. position: absolute;
  1040. content: "";
  1041. width: 3px;
  1042. top: 41px;
  1043. bottom: 0;
  1044. left: 14px;
  1045. opacity: .4;
  1046. background-color: currentColor;
  1047. display: block;
  1048. }
  1049. .q-icon {
  1050. position: absolute;
  1051. top: 0;
  1052. left: 0;
  1053. right: 0;
  1054. font-size: 16px;
  1055. height: 38px;
  1056. line-height: 38px;
  1057. width: 100%;
  1058. align-items: center;
  1059. justify-content: center;
  1060. display: flex;
  1061. }
  1062. }
  1063. &-name {
  1064. line-height: 12px;
  1065. display: flex;
  1066. flex-wrap: nowrap;
  1067. padding-top: 4px;
  1068. &-text {
  1069. flex: 0 0;
  1070. white-space: nowrap;
  1071. }
  1072. input {
  1073. font-weight: 700;
  1074. color: $grey-6;
  1075. letter-spacing: 1px;
  1076. font-size: 12px;
  1077. line-height: 12px;
  1078. border: none;
  1079. padding: 0 0 0 5px;
  1080. outline: none;
  1081. flex: 1;
  1082. background-color: transparent;
  1083. &::placeholder {
  1084. color: $grey-5;
  1085. }
  1086. @at-root .body--dark & {
  1087. color: rgba(255,255,255,.7);
  1088. &::placeholder {
  1089. color: rgba(255,255,255,.4);
  1090. }
  1091. }
  1092. }
  1093. }
  1094. &-card {
  1095. background-color: $grey-2 !important;
  1096. @at-root .body--dark & {
  1097. background-color: $dark-6 !important;
  1098. }
  1099. &-permissions {
  1100. background-color: rgba($positive, .1);
  1101. border-bottom: 1px solid rgba($positive, .3);
  1102. display: flex;
  1103. align-items: center;
  1104. .q-select {
  1105. flex-basis: 100%;
  1106. }
  1107. &.is-allow {
  1108. background-color: rgba($positive, .1);
  1109. border-bottom: 1px solid rgba($positive, .3);
  1110. }
  1111. &.is-deny {
  1112. background-color: rgba($negative, .1);
  1113. border-bottom: 1px solid rgba($negative, .3);
  1114. }
  1115. &.is-forceallow {
  1116. background-color: rgba($blue, .1);
  1117. border-bottom: 1px solid rgba($blue, .3);
  1118. }
  1119. }
  1120. &-filters {
  1121. background-color: $grey-3;
  1122. flex-basis: 300px;
  1123. .text-caption:first-child {
  1124. color: $grey-7;
  1125. }
  1126. @at-root .body--dark & {
  1127. background-color: $dark-5;
  1128. }
  1129. }
  1130. &-pattern {
  1131. flex-grow: 1;
  1132. }
  1133. }
  1134. }
  1135. </style>