mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 17:40:46 -04:00
try to block admins from home assistant
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
# general idea:
|
||||||
|
- users will be able to have and set nicknames
|
||||||
|
- a user's nickname will store in the browser cookie system
|
||||||
@@ -4,6 +4,8 @@ const { createConnection, subscribeEntities, callService, Auth } = require('home
|
|||||||
const io = require('../globals/io');
|
const io = require('../globals/io');
|
||||||
const logger = require('../globals/logger').child('homeAssistantService');
|
const logger = require('../globals/logger').child('homeAssistantService');
|
||||||
const { loadConfig } = require('../helpers/configLoader');
|
const { loadConfig } = require('../helpers/configLoader');
|
||||||
|
const { getMode } = require('./modeManager');
|
||||||
|
const { isAdmin } = require('./roleService');
|
||||||
|
|
||||||
// home-assistant-js-websocket expects a global WebSocket in Node.
|
// home-assistant-js-websocket expects a global WebSocket in Node.
|
||||||
if (!global.WebSocket) {
|
if (!global.WebSocket) {
|
||||||
@@ -229,6 +231,10 @@ connect();
|
|||||||
|
|
||||||
io.on('connection', (socket) => {
|
io.on('connection', (socket) => {
|
||||||
socket.on('homeAssistant:toggle', async ({ entityId } = {}, cb = () => {}) => {
|
socket.on('homeAssistant:toggle', async ({ entityId } = {}, cb = () => {}) => {
|
||||||
|
if ((getMode() === 'admin' || getMode() === 'lockdown') && isAdmin(socket) !== true) {
|
||||||
|
return cb({ error: 'Insufficient permissions to control Home Assistant' });
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!entityId) throw new Error('entityId required');
|
if (!entityId) throw new Error('entityId required');
|
||||||
await toggleEntity(entityId);
|
await toggleEntity(entityId);
|
||||||
@@ -239,6 +245,10 @@ io.on('connection', (socket) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on('homeAssistant:setState', async ({ entityId, state } = {}, cb = () => {}) => {
|
socket.on('homeAssistant:setState', async ({ entityId, state } = {}, cb = () => {}) => {
|
||||||
|
if ((getMode() === 'admin' || getMode() === 'lockdown') && isAdmin(socket) !== true) {
|
||||||
|
return cb({ error: 'Insufficient permissions to control Home Assistant' });
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!entityId) throw new Error('entityId required');
|
if (!entityId) throw new Error('entityId required');
|
||||||
await setEntityState(entityId, state);
|
await setEntityState(entityId, state);
|
||||||
|
|||||||
Reference in New Issue
Block a user