@live-change/access-control-frontend 0.1.2 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,79 @@
1
1
  <template>
2
-
2
+ <slot v-if="!authorized" name="blocked" :authorized="authorized" :roles="accessRoles" :accesses="accesses">
3
+ <div class="flex align-items-start p-4 bg-pink-100 border-round border-1 border-pink-300 mb-4">
4
+ <i class="pi pi-times-circle text-pink-900 text-2xl mr-3" />
5
+ <div class="mr-3">
6
+ <div class="text-pink-900 font-medium text-xl mb-3 line-height-1">Not authorized</div>
7
+ <p class="m-0 p-0 text-pink-700">
8
+ You do not have sufficient privileges to use this feature of this object.
9
+ </p>
10
+ </div>
11
+ </div>
12
+ </slot>
13
+ <BlockUI :blocked="notAuthorized">
14
+ <slot :authorized="authorized" :roles="accessRoles" :accesses="accesses"></slot>
15
+ </BlockUI>
16
+ <div v-if="false">
17
+ <h4>Bans</h4>
18
+ <pre>{{ JSON.stringify(bansState, null, ' ') }}</pre>
19
+ <h4>Counters</h4>
20
+ <pre>{{ JSON.stringify(countersState, null, ' ') }}</pre>
21
+ </div>
3
22
  </template>
4
23
 
5
24
  <script setup>
25
+
26
+ import BlockUI from 'primevue/blockui'
27
+
28
+ const { objectType, object, objects, requiredRoles } = defineProps({
29
+ objectType: {
30
+ type: String,
31
+ default: null
32
+ },
33
+ object: {
34
+ type: String,
35
+ default: null
36
+ },
37
+ objects: {
38
+ type: Array,
39
+ default: () => []
40
+ },
41
+ requiredRoles: {
42
+ type: Array,
43
+ default: () => []
44
+ }
45
+ })
46
+
47
+ const allObjects = ((objectType && object) ? [{ objectType, object }] : []).concat(objects || [])
48
+
49
+ import { provide, computed } from 'vue'
50
+ import { live, path } from '@live-change/vue3-ssr'
51
+
52
+ const [ accesses ] = await Promise.all([
53
+ live(
54
+ path().accessControl.myAccessesTo({ objects: allObjects })
55
+ )
56
+ ])
57
+
58
+ const accessRoles = computed(() => {
59
+ const accessesList = accesses.value.slice()
60
+ const firstAccess = accessesList.shift()
61
+ let roles = firstAccess.roles
62
+ for(const access of accessesList) {
63
+ roles = roles.filter(role => access.roles.includes(role))
64
+ }
65
+ })
66
+
67
+ const authorized = computed(() => {
68
+ const roles = accessRoles.value
69
+ for(const requiredRole of requiredRoles) {
70
+ if(!roles.includes(requiredRole)) return false
71
+ }
72
+ return true
73
+ })
74
+
6
75
  </script>
7
76
 
8
77
  <style scoped>
9
78
 
10
- </style>
79
+ </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/access-control-frontend",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
4
4
  "scripts": {
5
5
  "memDev": "lcli memDev --enableSessions --initScript ./init.js --dbAccess",
6
6
  "localDevInit": "rm tmp.db; lcli localDev --enableSessions --initScript ./init.js",
@@ -20,25 +20,22 @@
20
20
  "debug": "node --inspect-brk server"
21
21
  },
22
22
  "dependencies": {
23
- "@live-change/access-control-service": "0.2.37",
24
- "@live-change/cli": "0.6.5",
25
- "@live-change/dao": "0.4.13",
26
- "@live-change/dao-vue3": "0.4.13",
27
- "@live-change/dao-websocket": "0.4.13",
28
- "@live-change/db-admin": "0.5.12",
29
- "@live-change/framework": "0.6.5",
30
- "@live-change/password-authentication-service": "0.2.39",
31
- "@live-change/secret-code-service": "0.2.39",
32
- "@live-change/secret-link-service": "0.2.39",
33
- "@live-change/session-service": "0.2.39",
34
- "@live-change/user-frontend": "^0.1.2",
35
- "@live-change/user-service": "0.2.37",
36
- "@live-change/vue3-components": "0.2.12",
23
+ "@live-change/access-control-service": "0.2.40",
24
+ "@live-change/cli": "0.6.8",
25
+ "@live-change/dao": "0.5.0",
26
+ "@live-change/dao-vue3": "0.5.0",
27
+ "@live-change/dao-websocket": "0.5.0",
28
+ "@live-change/db-admin": "0.5.13",
29
+ "@live-change/framework": "0.6.8",
30
+ "@live-change/password-authentication-service": "0.2.41",
31
+ "@live-change/secret-code-service": "0.2.41",
32
+ "@live-change/secret-link-service": "0.2.41",
33
+ "@live-change/session-service": "0.2.41",
34
+ "@live-change/user-frontend": "^0.1.5",
35
+ "@live-change/user-service": "0.2.41",
36
+ "@live-change/vue3-components": "0.2.14",
37
37
  "@live-change/vue3-ssr": "0.2.14",
38
- "@vitejs/plugin-vue": "^2.3.1",
39
- "@vitejs/plugin-vue-jsx": "^1.3.10",
40
- "@vue/compiler-sfc": "^3.2.33",
41
- "@vueuse/core": "^8.3.1",
38
+ "@vueuse/core": "^9.1.0",
42
39
  "codeceptjs-assert": "^0.0.5",
43
40
  "compression": "^1.7.4",
44
41
  "cross-env": "^7.0.3",
@@ -50,27 +47,22 @@
50
47
  "rollup-plugin-visualizer": "5.6.0",
51
48
  "serialize-javascript": "^6.0.0",
52
49
  "serve-static": "^1.15.0",
53
- "v-shared-element": "3.1.0",
54
- "vite": "^2.9.6",
55
- "vite-plugin-compression": "0.5.1",
56
- "vite-plugin-vue-images": "^0.6.1",
57
- "vue": "^3.2.33",
58
50
  "vue-meta": "^3.0.0-alpha.9",
59
- "vue-router": "^4.0.14",
51
+ "vue-router": "^4.1.3",
60
52
  "vue3-scroll-border": "0.1.2"
61
53
  },
62
54
  "devDependencies": {
63
- "@live-change/codeceptjs-helper": "0.6.5",
64
- "@wdio/selenium-standalone-service": "^7.19.5",
65
- "codeceptjs": "^3.3.1",
55
+ "@live-change/codeceptjs-helper": "0.6.8",
56
+ "@wdio/selenium-standalone-service": "^7.20.8",
57
+ "codeceptjs": "^3.3.4",
66
58
  "generate-password": "1.7.0",
67
- "playwright": "^1.21.1",
59
+ "playwright": "^1.24.2",
68
60
  "random-profile-generator": "^2.3.0",
69
- "txtgen": "^3.0.1",
70
- "webdriverio": "^7.19.5"
61
+ "txtgen": "^3.0.2",
62
+ "webdriverio": "^7.20.9"
71
63
  },
72
64
  "author": "",
73
65
  "license": "ISC",
74
66
  "description": "",
75
- "gitHead": "2263ca7a6c9ead13175e4bafa9fa01c8182b283b"
67
+ "gitHead": "ca3253bac1e9c01143244f5236bd40278a86ebaa"
76
68
  }
package/server/init.js CHANGED
@@ -23,7 +23,7 @@ module.exports = async function(services) {
23
23
  }
24
24
  }
25
25
 
26
- const session = 'GOzz0WylRDklhLCSppS6bwRYUeIQJqzt'
26
+ const session = 'Q6OytlOJ54r0tF1BriDB8bEYoGEUIf+i__'
27
27
 
28
28
  //console.log("MDL", services.passwordAuthentication.models.PasswordAuthentication)
29
29
 
@@ -31,7 +31,7 @@ module.exports = async function(services) {
31
31
  const user2 = await createUser('Test User 2 with very long name!', 'test2@test.com', 'Testy123')
32
32
  const user3 = await createUser('Test User 3', 'test3@test.com', 'Testy123')
33
33
 
34
- await services.user.models.AuthenticatedUser.create({ id: session, session, user: user2.id })
34
+ await services.user.models.AuthenticatedUser.create({ id: session, session, user: user1.id })
35
35
 
36
36
  await services.notification.models.Notification.create({
37
37
  "id": app.generateUid(),
@@ -46,12 +46,12 @@ module.exports = async function(services) {
46
46
  "readState": "new"
47
47
  })
48
48
 
49
- /* await PublicAccess.create({
49
+ await PublicAccess.create({
50
50
  id: App.encodeIdentifier(['example_Example', 'one']),
51
51
  objectType: 'example_Example', object: 'one',
52
52
  userRoles: ['reader'],
53
- sessionRoles: []
54
- })*/
53
+ sessionRoles: ['reader']
54
+ })
55
55
 
56
56
  await Access.create({
57
57
  id: App.encodeIdentifier(['user_User', user1.id, 'example_Example', 'one']),