mirror of
https://github.com/koush/scrypted.git
synced 2026-02-03 06:03:27 +00:00
sdk: AccessControls
This commit is contained in:
4
sdk/package-lock.json
generated
4
sdk/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/sdk",
|
||||
"version": "0.5.55",
|
||||
"version": "0.5.57",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/sdk",
|
||||
"version": "0.5.55",
|
||||
"version": "0.5.57",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@babel/preset-typescript": "^7.27.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@scrypted/sdk",
|
||||
"version": "0.5.55",
|
||||
"version": "0.5.57",
|
||||
"description": "",
|
||||
"main": "dist/src/index.js",
|
||||
"exports": {
|
||||
|
||||
100
sdk/src/acl.ts
100
sdk/src/acl.ts
@@ -1,4 +1,4 @@
|
||||
import { ScryptedDeviceAccessControl, ScryptedInterface, ScryptedInterfaceDescriptors, ScryptedUserAccessControl } from ".";
|
||||
import { EventDetails, ScryptedDeviceAccessControl, ScryptedInterface, ScryptedInterfaceDescriptors, ScryptedUserAccessControl } from ".";
|
||||
|
||||
export function addAccessControlsForInterface(id: string, ...scryptedInterfaces: ScryptedInterface[]): ScryptedDeviceAccessControl {
|
||||
const methods = scryptedInterfaces.map(scryptedInterface => ScryptedInterfaceDescriptors[scryptedInterface]?.methods || []).flat();
|
||||
@@ -20,3 +20,101 @@ export function mergeDeviceAccessControls(accessControls: ScryptedUserAccessCont
|
||||
accessControls.devicesAccessControls.push(...dacls);
|
||||
return accessControls;
|
||||
}
|
||||
|
||||
export class AccessControls {
|
||||
constructor(public acl: ScryptedUserAccessControl) {
|
||||
}
|
||||
|
||||
deny(reason: string = 'User does not have permission') {
|
||||
throw new Error(reason);
|
||||
}
|
||||
|
||||
shouldRejectDevice(id: string) {
|
||||
if (this.acl.devicesAccessControls === null)
|
||||
return false;
|
||||
|
||||
if (!this.acl.devicesAccessControls)
|
||||
return true;
|
||||
|
||||
const dacls = this.acl.devicesAccessControls.filter(dacl => dacl.id === id);
|
||||
return !dacls.length;
|
||||
}
|
||||
|
||||
shouldRejectProperty(id: string, property: string) {
|
||||
if (this.acl.devicesAccessControls === null)
|
||||
return false;
|
||||
|
||||
if (!this.acl.devicesAccessControls)
|
||||
return true;
|
||||
|
||||
const dacls = this.acl.devicesAccessControls.filter(dacl => dacl.id === id);
|
||||
|
||||
for (const dacl of dacls) {
|
||||
if (!dacl.properties || dacl.properties.includes(property))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
shouldRejectEvent(id: string, eventDetails: EventDetails) {
|
||||
if (this.acl.devicesAccessControls === null)
|
||||
return false;
|
||||
|
||||
if (!this.acl.devicesAccessControls)
|
||||
return true;
|
||||
|
||||
const dacls = this.acl.devicesAccessControls.filter(dacl => dacl.id === id);
|
||||
|
||||
const { property } = eventDetails;
|
||||
if (property) {
|
||||
for (const dacl of dacls) {
|
||||
if (!dacl.properties || dacl.properties.includes(property))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const { eventInterface } = eventDetails;
|
||||
|
||||
for (const dacl of dacls) {
|
||||
if (!dacl.interfaces || dacl.interfaces.includes(eventInterface!))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
shouldRejectInterface(id: string, scryptedInterface: ScryptedInterface) {
|
||||
if (this.acl.devicesAccessControls === null)
|
||||
return false;
|
||||
|
||||
if (!this.acl.devicesAccessControls)
|
||||
return true;
|
||||
|
||||
const dacls = this.acl.devicesAccessControls.filter(dacl => dacl.id === id);
|
||||
|
||||
for (const dacl of dacls) {
|
||||
if (!dacl.interfaces || dacl.interfaces.includes(scryptedInterface))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
shouldRejectMethod(id: string, method: string) {
|
||||
if (this.acl.devicesAccessControls === null)
|
||||
return false;
|
||||
|
||||
if (!this.acl.devicesAccessControls)
|
||||
return true;
|
||||
|
||||
const dacls = this.acl.devicesAccessControls.filter(dacl => dacl.id === id);
|
||||
|
||||
for (const dacl of dacls) {
|
||||
if (!dacl.methods || dacl.methods.includes(method))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
4
sdk/types/package-lock.json
generated
4
sdk/types/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@scrypted/types",
|
||||
"version": "0.5.52",
|
||||
"version": "0.5.53",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@scrypted/types",
|
||||
"version": "0.5.52",
|
||||
"version": "0.5.53",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"openai": "^6.1.0"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@scrypted/types",
|
||||
"version": "0.5.52",
|
||||
"version": "0.5.53",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"author": "",
|
||||
|
||||
@@ -1131,7 +1131,7 @@ class TamperState(TypedDict):
|
||||
pass
|
||||
|
||||
|
||||
TYPES_VERSION = "0.5.52"
|
||||
TYPES_VERSION = "0.5.53"
|
||||
|
||||
|
||||
class AirPurifier:
|
||||
|
||||
Reference in New Issue
Block a user