core: admin note on users

This commit is contained in:
Koushik Dutta
2024-07-27 10:42:55 -07:00
parent 62543bdfcf
commit f944b76c1f
6 changed files with 50 additions and 1199 deletions

View File

@@ -74,7 +74,7 @@
},
"../sdk": {
"name": "@scrypted/sdk",
"version": "0.3.37",
"version": "0.3.45",
"license": "ISC",
"dependencies": {
"@babel/preset-typescript": "^7.18.6",

File diff suppressed because it is too large Load Diff

View File

@@ -41,10 +41,9 @@
},
"dependencies": {
"@scrypted/common": "file:../../common",
"@scrypted/node-pty": "^1.0.5",
"@scrypted/sdk": "file:../../sdk",
"mime": "^3.0.0",
"node-pty-prebuilt-multiarch": "^0.10.1-pre.5",
"node-pty": "^1.0.0",
"router": "^1.3.8",
"typescript": "^5.4.2"
},

View File

@@ -1,5 +1,5 @@
import { ScryptedDeviceBase, ScryptedNativeId, StreamService } from "@scrypted/sdk";
import type { IPty, spawn as ptySpawn } from 'node-pty-prebuilt-multiarch';
import type { IPty, spawn as ptySpawn } from 'node-pty';
import { createAsyncQueue } from '@scrypted/common/src/async-queue'
import { ChildProcess, spawn as childSpawn } from "child_process";

View File

@@ -13,6 +13,12 @@ export class User extends ScryptedDeviceBase implements Settings, ScryptedUser {
defaultValue: true,
type: 'boolean',
},
admin: {
title: 'Administrator',
mapGet: () => '<div style="font-size: .8rem; margin-bottom: 16px; margin-left: 8px;">This user has administrator access.</div>',
type: 'html',
hide: true,
},
interfaces: {
title: 'Interfaces',
description: 'The interfaces this user can access. Admin users can access all interfaces on all devices. Scrypted NVR users should use NVR Permissions to grant access to the NVR and associated cameras.',
@@ -20,16 +26,28 @@ export class User extends ScryptedDeviceBase implements Settings, ScryptedUser {
multiple: true,
defaultValue: [],
},
})
});
async getScryptedUserAccessControl(): Promise<ScryptedUserAccessControl> {
_admin: boolean;
async getAdmin() {
if (this._admin !== undefined)
return this._admin;
const usersService = await sdk.systemManager.getComponent('users');
const users: DBUser[] = await usersService.getAllUsers();
const user = users.find(user => user.username === this.username);
if (!user)
throw new Error("user not found");
this._admin = !!user.admin;
if (this._admin) {
this.storageSettings.settings.defaultAccess.hide = true;
this.storageSettings.settings.interfaces.hide = true;
this.storageSettings.settings.admin.hide = false;
}
return this._admin;
}
if (user.admin)
async getScryptedUserAccessControl(): Promise<ScryptedUserAccessControl> {
if (await this.getAdmin())
return;
const self = sdk.deviceManager.getDeviceState(this.nativeId);
@@ -63,6 +81,8 @@ export class User extends ScryptedDeviceBase implements Settings, ScryptedUser {
}
async getSettings(): Promise<Setting[]> {
await this.getAdmin();
return [
{
key: 'username',

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/server",
"version": "0.115.0",
"version": "0.115.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@scrypted/server",
"version": "0.115.0",
"version": "0.115.1",
"hasInstallScript": true,
"license": "ISC",
"dependencies": {