@live-change/access-control-service
Advanced tools
Comparing version 0.8.125 to 0.8.126
@@ -58,2 +58,6 @@ import App from '@live-change/framework' | ||
type: Date | ||
}, | ||
autoGrantRequests: { | ||
type: Number, | ||
default: 0 | ||
} | ||
@@ -60,0 +64,0 @@ }, |
{ | ||
"name": "@live-change/access-control-service", | ||
"version": "0.8.125", | ||
"version": "0.8.126", | ||
"description": "", | ||
@@ -24,6 +24,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"@live-change/framework": "^0.8.125" | ||
"@live-change/framework": "^0.8.126" | ||
}, | ||
"gitHead": "d7d1cdd1d9d670e3eb065bf56fcdbc67e4d97dea", | ||
"gitHead": "2aa34c0589d115aeaa573bd2cae09bb43a66d162", | ||
"type": "module" | ||
} |
@@ -6,3 +6,3 @@ import App from '@live-change/framework' | ||
import { Access, AccessRequest, rolesArrayType } from './model.js' | ||
import { PublicAccess, Access, AccessRequest, rolesArrayType } from './model.js' | ||
import accessModule from './access.js' | ||
@@ -24,2 +24,64 @@ const access = accessModule(definition) | ||
definition.action({ | ||
name: 'requestAccess', | ||
properties: { | ||
objectType: { | ||
type: String, | ||
validation: ['nonEmpty'] | ||
}, | ||
object: { | ||
type: String, | ||
validation: ['nonEmpty'] | ||
}, | ||
roles: rolesArrayType | ||
}, | ||
queuedBy: ['objectType', 'object'], | ||
waitForEvents: true, | ||
access: (params, { client, context, visibilityTest }) => | ||
visibilityTest || access.clientCanInvite(client, params), | ||
async execute({ objectType, object, roles }, { client, service }, emit) { | ||
const publicAccess = await PublicAccess.get(App.encodeIdentifier([objectType, object])) | ||
const [sessionOrUserType, sessionOrUser] = | ||
client.user ? ['user_User', client.user] : ['session_Session', client.session] | ||
if(!publicAccess.availableRoles) throw 'notAuthorized' | ||
for(const requestedRole of roles) { | ||
if(!publicAccess.availableRoles.includes(requestedRole)) throw 'notAuthorized' | ||
} | ||
const request = App.encodeIdentifier([ sessionOrUserType, sessionOrUser, objectType, object ]) | ||
const requestData = await AccessRequest.get(request) | ||
if(requestData) throw 'already_requested' | ||
if(publicAccess.autoGrantRequests) { | ||
emit({ | ||
type: 'accessRequestAccepted', | ||
objectType, object, sessionOrUserType, sessionOrUser, roles, | ||
autoAccept: true | ||
}) | ||
emit({ | ||
type: 'objectOwnedPublicAccessUpdated', | ||
identifiers: { | ||
objectType, object | ||
}, | ||
data: { | ||
autoGrantRequests: publicAccess.autoGrantRequests - 1 | ||
}, | ||
}) | ||
} else { | ||
emit({ | ||
type: 'sessionOrUserAndObjectOwnedAccessRequestSet', | ||
data: { | ||
roles | ||
}, | ||
identifiers: { | ||
sessionOrUserType, sessionOrUser, | ||
objectType, object, | ||
roles | ||
} | ||
}) | ||
} | ||
} | ||
}) | ||
definition.action({ | ||
name: 'acceptAccessRequest', | ||
@@ -26,0 +88,0 @@ waitForEvents: true, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47493
1288