@live-change/access-control-service 0.2.31 → 0.2.34
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.
- package/access.js +6 -1
- package/invite.js +109 -23
- package/package.json +3 -3
package/access.js
CHANGED
|
@@ -28,6 +28,11 @@ module.exports = (definition) => {
|
|
|
28
28
|
return true
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
return {
|
|
31
|
+
return {
|
|
32
|
+
clientHasAnyAccess, clientHasAdminAccess,
|
|
33
|
+
clientCanInvite,
|
|
34
|
+
clientCanRequest,
|
|
35
|
+
clientHasAccessRole
|
|
36
|
+
}
|
|
32
37
|
|
|
33
38
|
}
|
package/invite.js
CHANGED
|
@@ -21,25 +21,33 @@ const Session = definition.foreignModel('session', 'Session')
|
|
|
21
21
|
|
|
22
22
|
definition.event({
|
|
23
23
|
name: 'userInvited',
|
|
24
|
-
async execute(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
async execute(params) {
|
|
25
|
+
const { user, objectType, object, fromType, from } = params
|
|
26
|
+
const contactOrUserType = 'user_User'
|
|
27
|
+
const contactOrUser = user
|
|
28
|
+
const data = {
|
|
29
|
+
id: App.encodeIdentifier([ contactOrUserType, contactOrUser, objectType, object ]),
|
|
30
|
+
contactOrUserType, contactOrUser,
|
|
31
|
+
objectType, object, fromType, from
|
|
32
|
+
}
|
|
33
|
+
for(const propertyName in invitationProperties) data[propertyName] = params[propertyName]
|
|
34
|
+
await AccessInvitation.create(data)
|
|
31
35
|
}
|
|
32
36
|
})
|
|
33
37
|
|
|
34
38
|
definition.event({
|
|
35
39
|
name: 'contactInvited',
|
|
36
|
-
async execute(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
async execute(params) {
|
|
41
|
+
const { contactType, contact, objectType, object, fromType, from } = params
|
|
42
|
+
const contactOrUserType = contactType
|
|
43
|
+
const contactOrUser = contact
|
|
44
|
+
const data = {
|
|
45
|
+
id: App.encodeIdentifier([ contactOrUserType, contactOrUser, objectType, object ]),
|
|
46
|
+
contactOrUserType, contactOrUser,
|
|
47
|
+
objectType, object, fromType, from
|
|
48
|
+
}
|
|
49
|
+
for(const propertyName in invitationProperties) data[propertyName] = params[propertyName]
|
|
50
|
+
await AccessInvitation.create(data)
|
|
43
51
|
}
|
|
44
52
|
})
|
|
45
53
|
|
|
@@ -60,6 +68,49 @@ definition.event({
|
|
|
60
68
|
}
|
|
61
69
|
})
|
|
62
70
|
|
|
71
|
+
definition.trigger({
|
|
72
|
+
name: 'contactOrUserOwnedInvitationMoved',
|
|
73
|
+
properties: {
|
|
74
|
+
...contactProperties,
|
|
75
|
+
from: {
|
|
76
|
+
contactOrUserType: {
|
|
77
|
+
type: String
|
|
78
|
+
},
|
|
79
|
+
contactOrUser: {
|
|
80
|
+
type: String
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
to: {
|
|
84
|
+
contactOrUserType: {
|
|
85
|
+
type: String
|
|
86
|
+
},
|
|
87
|
+
contactOrUser: {
|
|
88
|
+
type: String
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
objectType: {
|
|
92
|
+
type: String
|
|
93
|
+
},
|
|
94
|
+
object: {
|
|
95
|
+
type: String
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
async execute({ from, to, objectType, object }, { service }, emit) {
|
|
99
|
+
const invitation = App.encodeIdentifier([from.contactOrUserType, from.contactOrUser, objectType, object])
|
|
100
|
+
const invitationData = await AccessInvitation.get(invitation)
|
|
101
|
+
if(to.contactOrUserType == 'user_User') {
|
|
102
|
+
await service.trigger({
|
|
103
|
+
...invitationData,
|
|
104
|
+
type: 'notify',
|
|
105
|
+
sessionOrUserType: 'user_User',
|
|
106
|
+
sessionOrUser: to.contactOrUser,
|
|
107
|
+
notificationType: 'accessControl_Invitation',
|
|
108
|
+
id: undefined
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
|
|
63
114
|
definition.trigger({
|
|
64
115
|
name: 'inviteWithMessageAuthenticated',
|
|
65
116
|
waitForEvents: true,
|
|
@@ -100,6 +151,34 @@ definition.trigger({
|
|
|
100
151
|
}
|
|
101
152
|
})
|
|
102
153
|
|
|
154
|
+
definition.action({
|
|
155
|
+
name: 'acceptInvitation',
|
|
156
|
+
waitForEvents: true,
|
|
157
|
+
properties: {
|
|
158
|
+
objectType: {
|
|
159
|
+
type: String,
|
|
160
|
+
validation: ['nonEmpty']
|
|
161
|
+
},
|
|
162
|
+
object: {
|
|
163
|
+
type: String,
|
|
164
|
+
validation: ['nonEmpty']
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
async execute({ objectType, object }, {client, service}, emit) {
|
|
168
|
+
if(!client.user) throw 'not_authorized'
|
|
169
|
+
const user = client.user
|
|
170
|
+
const invitation = App.encodeIdentifier(['user_User', user, objectType, object])
|
|
171
|
+
const invitationData = await AccessInvitation.get(invitation)
|
|
172
|
+
console.log("INVITATION", invitation, invitationData)
|
|
173
|
+
if(!invitationData) throw 'not_found'
|
|
174
|
+
const { roles } = invitationData
|
|
175
|
+
emit({
|
|
176
|
+
type: 'userInvitationAccepted',
|
|
177
|
+
user, objectType, object, roles
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
|
|
103
182
|
for(const contactType of config.contactTypes) {
|
|
104
183
|
|
|
105
184
|
const contactTypeUpperCaseName = contactType[0].toUpperCase() + contactType.slice(1)
|
|
@@ -134,9 +213,10 @@ for(const contactType of config.contactTypes) {
|
|
|
134
213
|
access: (params, { client, context, visibilityTest }) =>
|
|
135
214
|
visibilityTest || access.clientCanInvite(client, params),
|
|
136
215
|
async execute(params, { client, service }, emit) {
|
|
216
|
+
const [ fromType, from ] = client.user ? ['user_User', client.user] : ['session_Session', client.session]
|
|
137
217
|
const { [contactTypeName]: contact } = params
|
|
138
218
|
const { objectType, object } = params
|
|
139
|
-
const invitationData = { }
|
|
219
|
+
const invitationData = { fromType, from }
|
|
140
220
|
for(const propertyName in invitationProperties) invitationData[propertyName] = params[propertyName]
|
|
141
221
|
|
|
142
222
|
const contactData = (await service.trigger({
|
|
@@ -144,21 +224,27 @@ for(const contactType of config.contactTypes) {
|
|
|
144
224
|
[contactType]: contact,
|
|
145
225
|
}))[0]
|
|
146
226
|
if(contactData?.user) { // user exists
|
|
147
|
-
|
|
227
|
+
const { user } = contactData
|
|
228
|
+
await service.trigger({
|
|
229
|
+
type: 'notify',
|
|
230
|
+
sessionOrUserType: 'user_User',
|
|
231
|
+
sessionOrUser: user,
|
|
232
|
+
notificationType: 'accessControl_Invitation',
|
|
233
|
+
objectType,
|
|
234
|
+
object,
|
|
235
|
+
...invitationData, id: undefined
|
|
236
|
+
})
|
|
148
237
|
emit({
|
|
149
238
|
type: 'userInvited',
|
|
150
|
-
user
|
|
239
|
+
user,
|
|
151
240
|
objectType, object,
|
|
152
|
-
...invitationData
|
|
241
|
+
...invitationData, id: undefined
|
|
153
242
|
})
|
|
154
243
|
} else {
|
|
155
244
|
// Authenticate with message because we will create account later
|
|
156
245
|
const messageData = {
|
|
157
|
-
fromType: client.user ? 'user_User' : 'session_Session',
|
|
158
|
-
from: client.user ?? client.session,
|
|
159
246
|
objectType, object,
|
|
160
|
-
|
|
161
|
-
message: params.message
|
|
247
|
+
...invitationData, id: undefined
|
|
162
248
|
}
|
|
163
249
|
await service.trigger({
|
|
164
250
|
type: 'authenticateWithMessage',
|
|
@@ -174,7 +260,7 @@ for(const contactType of config.contactTypes) {
|
|
|
174
260
|
contactType: contactTypeName + '_' + contactTypeUName,
|
|
175
261
|
contact,
|
|
176
262
|
objectType, object,
|
|
177
|
-
...invitationData
|
|
263
|
+
...invitationData, id: undefined
|
|
178
264
|
})
|
|
179
265
|
}
|
|
180
266
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/access-control-service",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.34",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"url": "https://www.viamage.com/"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@live-change/framework": "0.6.
|
|
24
|
+
"@live-change/framework": "0.6.5"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "45f52d6c7586d0eaa51b3205c6635a33e32eef6b"
|
|
27
27
|
}
|