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.

323 lines
12 KiB

  1. <template lang="pug">
  2. v-card
  3. v-card-text(v-if='group.id === 1')
  4. v-alert.radius-7(
  5. :class='$vuetify.theme.dark ? "grey darken-4" : "orange lighten-5"'
  6. color='orange darken-2'
  7. outlined
  8. icon='mdi-lock-outline'
  9. ) This group has access to everything.
  10. template(v-else)
  11. v-card-title(:class='$vuetify.theme.dark ? `grey darken-3-d5` : ``')
  12. v-alert.radius-7.caption(
  13. :class='$vuetify.theme.dark ? `grey darken-3-d3` : `grey lighten-4`'
  14. color='grey'
  15. outlined
  16. icon='mdi-information'
  17. ) You must enable global content permissions (under Permissions tab) for page rules to have any effect.
  18. v-spacer
  19. v-btn.mx-2(depressed, color='primary', @click='addRule')
  20. v-icon(left) mdi-plus
  21. | Add Rule
  22. v-menu(
  23. right
  24. offset-y
  25. nudge-left='115'
  26. )
  27. template(v-slot:activator='{ on }')
  28. v-btn.is-icon(v-on='on', outlined, color='primary')
  29. v-icon mdi-dots-horizontal
  30. v-list(dense)
  31. v-list-item(@click='comingSoon')
  32. v-list-item-avatar
  33. v-icon mdi-application-import
  34. v-list-item-title Load Preset
  35. v-divider
  36. v-list-item(@click='comingSoon')
  37. v-list-item-avatar
  38. v-icon mdi-application-export
  39. v-list-item-title Save As Preset
  40. v-divider
  41. v-list-item(@click='comingSoon')
  42. v-list-item-avatar
  43. v-icon mdi-cloud-upload
  44. v-list-item-title Import Rules
  45. v-divider
  46. v-list-item(@click='comingSoon')
  47. v-list-item-avatar
  48. v-icon mdi-cloud-download
  49. v-list-item-title Export Rules
  50. v-card-text(:class='$vuetify.theme.dark ? `grey darken-4-l5` : `white`')
  51. .rules
  52. .caption(v-if='group.pageRules.length === 0')
  53. em(:class='$vuetify.theme.dark ? `grey--text` : `blue-grey--text`') This group has no page rules yet.
  54. .rule(v-for='rule of group.pageRules', :key='rule.id')
  55. v-btn.ma-0.radius-4.rule-deny-btn(
  56. solo
  57. :color='rule.deny ? "red" : "green"'
  58. dark
  59. @click='rule.deny = !rule.deny'
  60. height='48'
  61. )
  62. v-icon(v-if='rule.deny') mdi-cancel
  63. v-icon(v-else) mdi-check-circle
  64. //- Roles
  65. v-select.ml-1(
  66. solo
  67. :items='roles'
  68. v-model='rule.roles'
  69. placeholder='Select Role(s)...'
  70. hide-details
  71. multiple
  72. chips
  73. deletable-chips
  74. small-chips
  75. style='flex: 0 1 440px;'
  76. :menu-props='{ "maxHeight": 500 }'
  77. clearable
  78. dense
  79. )
  80. template(slot='selection', slot-scope='{ item, index }')
  81. v-chip.white--text.ml-0(v-if='index <= 1', small, label, :color='rule.deny ? `red` : `green`').caption {{ item.value }}
  82. v-chip.white--text.ml-0(v-if='index === 2', small, label, :color='rule.deny ? `red lighten-2` : `green lighten-2`').caption + {{ rule.roles.length - 2 }} more
  83. template(slot='item', slot-scope='props')
  84. v-list-item-action(style='min-width: 30px;')
  85. v-checkbox(
  86. v-model='props.attrs.inputValue'
  87. hide-details
  88. color='primary'
  89. )
  90. v-icon.mr-2(:color='rule.deny ? `red` : `green`') {{props.item.icon}}
  91. v-list-item-content
  92. v-list-item-title.body-2 {{props.item.text}}
  93. v-chip.mr-2.grey--text(label, small, :color='$vuetify.theme.dark ? `grey darken-4` : `grey lighten-4`').caption {{props.item.value}}
  94. //- Match
  95. v-select.ml-1.mr-1(
  96. solo
  97. :items='matches'
  98. v-model='rule.match'
  99. placeholder='Match...'
  100. hide-details
  101. style='flex: 0 1 250px;'
  102. dense
  103. )
  104. template(slot='selection', slot-scope='{ item, index }')
  105. .body-2 {{item.text}}
  106. template(slot='item', slot-scope='data')
  107. v-list-item-avatar
  108. v-avatar.white--text.radius-4(color='blue', size='30', tile) {{ data.item.icon }}
  109. v-list-item-content
  110. v-list-item-title(v-html='data.item.text')
  111. //- Locales
  112. v-select.mr-1(
  113. :background-color='$vuetify.theme.dark ? `grey darken-3-d5` : `blue-grey lighten-5`'
  114. solo
  115. :items='locales'
  116. v-model='rule.locales'
  117. placeholder='Any Locale'
  118. multiple
  119. hide-details
  120. dense
  121. :menu-props='{ "minWidth": 250 }'
  122. style='flex: 0 1 150px;'
  123. )
  124. template(slot='selection', slot-scope='{ item, index }')
  125. v-chip.white--text.ml-0(v-if='rule.locales.length === 1', small, label, :color='rule.deny ? `red` : `green`').caption {{ item.value.toUpperCase() }}
  126. v-chip.white--text.ml-0(v-else-if='index === 0', small, label, :color='rule.deny ? `red` : `green`').caption {{ rule.locales.length }} locales
  127. v-list-item(slot='prepend-item', @click='rule.locales = []')
  128. v-list-item-action(style='min-width: 30px;')
  129. v-checkbox(
  130. :input-value='rule.locales.length === 0'
  131. hide-details
  132. color='primary'
  133. readonly
  134. )
  135. v-icon.mr-2(:color='rule.deny ? `red` : `green`') mdi-earth
  136. v-list-item-content
  137. v-list-item-title.body-2 Any Locale
  138. v-divider(slot='prepend-item')
  139. template(slot='item', slot-scope='props')
  140. v-list-item-action(style='min-width: 30px;')
  141. v-checkbox(
  142. v-model='props.attrs.inputValue'
  143. hide-details
  144. color='primary'
  145. )
  146. v-icon.mr-2(:color='rule.deny ? `red` : `green`') mdi-web
  147. v-list-item-content
  148. v-list-item-title.body-2 {{props.item.text}}
  149. v-chip.mr-2.grey--text(label, small, :color='$vuetify.theme.dark ? `grey darken-4` : `grey lighten-4`').caption {{props.item.value.toUpperCase()}}
  150. //- Path
  151. v-text-field(
  152. solo
  153. v-model='rule.path'
  154. label='Path'
  155. :prefix='rule.match !== `END` ? `/` : null'
  156. :placeholder='rule.match === `REGEX` ? `Regular Expression` : `Path`'
  157. :suffix='rule.match === `REGEX` ? `/` : null'
  158. hide-details
  159. :color='$vuetify.theme.dark ? `grey` : `blue-grey`'
  160. )
  161. v-btn.ml-2.mt-1(icon, @click='removeRule(rule.id)', small)
  162. v-icon(:color='$vuetify.theme.dark ? `grey` : `blue-grey`') mdi-close
  163. v-divider.mt-3
  164. .overline.py-3 Rules Order
  165. .body-2.pl-3 Rules are applied in order of path specificity. A more precise path will always override a less defined path.
  166. .body-2.pl-5 For example, #[span.teal--text /geography/countries] will override #[span.teal--text /geography].
  167. .body-2.pl-3.pt-2 When 2 rules have the same specificity, the priority is given from lowest to highest as follows:
  168. .body-2.pl-3.pt-1
  169. ul
  170. li
  171. strong Path Starts With...
  172. em.caption.pl-1 (lowest)
  173. li
  174. strong Path Ends With...
  175. li
  176. strong Path Matches Regex...
  177. li
  178. strong Path Is Exactly...
  179. em.caption.pl-1 (highest)
  180. .body-2.pl-3.pt-2 When 2 rules have the same path specificity AND the same match type, #[strong.red--text DENY] will always override an #[strong.green--text ALLOW] rule.
  181. v-divider.mt-3
  182. .overline.py-3 Regular Expressions
  183. span Expressions that are deemed unsafe or could result in exponential time processing will be rejected upon saving.
  184. </template>
  185. <script>
  186. import _ from 'lodash'
  187. import nanoid from 'nanoid/non-secure/generate'
  188. export default {
  189. props: {
  190. value: {
  191. type: Object,
  192. default: () => ({})
  193. }
  194. },
  195. data() {
  196. return {
  197. roles: [
  198. { text: 'Read Pages', value: 'read:pages', icon: 'mdi-file-document-box-search-outline' },
  199. { text: 'Create Pages', value: 'write:pages', icon: 'mdi-file-document-box-plus-outline' },
  200. { text: 'Edit + Move Pages', value: 'manage:pages', icon: 'mdi-file-document-edit-outline' },
  201. { text: 'Delete Pages', value: 'delete:pages', icon: 'mdi-file-document-box-remove-outline' },
  202. { text: 'View Pages Source', value: 'read:source', icon: 'mdi-code-tags' },
  203. { text: 'View Pages History', value: 'read:history', icon: 'mdi-history' },
  204. { text: 'Read / Use Assets', value: 'read:assets', icon: 'mdi-image-search-outline' },
  205. { text: 'Upload Assets', value: 'write:assets', icon: 'mdi-image-plus' },
  206. { text: 'Edit + Delete Assets', value: 'manage:assets', icon: 'mdi-image-size-select-large' },
  207. { text: 'Read Comments', value: 'read:comments', icon: 'mdi-comment-search-outline' },
  208. { text: 'Create Comments', value: 'write:comments', icon: 'mdi-comment-plus-outline' },
  209. { text: 'Edit + Delete Comments', value: 'manage:comments', icon: 'mdi-comment-remove-outline' }
  210. ],
  211. matches: [
  212. { text: 'Path Starts With...', value: 'START', icon: '/...' },
  213. { text: 'Path is Exactly...', value: 'EXACT', icon: '=' },
  214. { text: 'Path Ends With...', value: 'END', icon: '.../' },
  215. { text: 'Path Matches Regex...', value: 'REGEX', icon: '$.*' }
  216. ],
  217. locales: [
  218. { text: 'English', value: 'en' }
  219. ]
  220. }
  221. },
  222. computed: {
  223. group: {
  224. get() { return this.value },
  225. set(val) { this.$set('input', val) }
  226. }
  227. },
  228. methods: {
  229. addRule(group) {
  230. this.group.pageRules.push({
  231. id: nanoid('1234567890abcdef', 10),
  232. path: '',
  233. roles: [],
  234. match: 'START',
  235. deny: false,
  236. locales: []
  237. })
  238. },
  239. removeRule(rule) {
  240. this.group.pageRules.splice(_.findIndex(this.group.pageRules, ['id', rule.id]), 1)
  241. },
  242. comingSoon() {
  243. this.$store.commit('showNotification', {
  244. style: 'indigo',
  245. message: `Coming soon...`,
  246. icon: 'directions_boat'
  247. })
  248. },
  249. dude (stuff) {
  250. console.info(stuff)
  251. }
  252. }
  253. }
  254. </script>
  255. <style lang="scss">
  256. .rules {
  257. background-color: mc('blue-grey', '50');
  258. border-radius: 4px;
  259. padding: 1rem;
  260. position: relative;
  261. @at-root .v-application.theme--dark & {
  262. background-color: mc('grey', '800');
  263. }
  264. }
  265. .rule {
  266. display: flex;
  267. background-color: mc('blue-grey', '100');
  268. border-radius: 4px;
  269. padding: .5rem;
  270. &-enter-active, &-leave-active {
  271. transition: all .5s ease;
  272. }
  273. &-enter, &-leave-to {
  274. opacity: 0;
  275. }
  276. @at-root .v-application.theme--dark & {
  277. background-color: mc('grey', '700');
  278. }
  279. & + .rule {
  280. margin-top: .5rem;
  281. position: relative;
  282. &::before {
  283. content: '+';
  284. position: absolute;
  285. width: 2rem;
  286. height: 2rem;
  287. border-radius: 50%;
  288. display: flex;
  289. justify-content: center;
  290. align-items: center;
  291. font-weight: 600;
  292. color: mc('blue-grey', '700');
  293. font-size: 1.25rem;
  294. background-color: mc('blue-grey', '50');
  295. left: -2rem;
  296. top: -1.3rem;
  297. @at-root .v-application.theme--dark & {
  298. background-color: mc('grey', '800');
  299. color: mc('grey', '600');
  300. }
  301. }
  302. }
  303. .input-group + * {
  304. margin-left: .5rem;
  305. }
  306. }
  307. </style>