diff --git a/src/backend/src/modules/selfhosted/SelfhostedService.js b/src/backend/src/modules/selfhosted/SelfhostedService.js index ad7553a7d..3707e082d 100644 --- a/src/backend/src/modules/selfhosted/SelfhostedService.js +++ b/src/backend/src/modules/selfhosted/SelfhostedService.js @@ -16,7 +16,10 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +const { Actor } = require("../../services/auth/Actor"); const BaseService = require("../../services/BaseService"); +const { DB_WRITE } = require("../../services/database/consts"); +const { Context } = require("../../util/context"); class SelfhostedService extends BaseService { static description = ` @@ -24,6 +27,47 @@ class SelfhostedService extends BaseService { ` async _init () { + this._register_commands(this.services.get('commands')); + } + + _register_commands (commands) { + const db = this.services.get('database').get(DB_WRITE, 'selfhosted'); + commands.registerCommands('app', [ + { + id: 'godmode-on', + description: 'Toggle godmode for an app', + handler: async (args, log) => { + const svc_su = this.services.get('su'); + await await svc_su.sudo(async () => { + const [app_uid] = args; + const es_app = await this.services.get('es:app'); + const app = await es_app.read(app_uid); + if ( ! app ) { + throw new Error(`App ${app_uid} not found`); + } + await db.write('UPDATE apps SET godmode = 1 WHERE uid = ?', [app_uid]); + }); + } + } + ]); + commands.registerCommands('app', [ + { + id: 'godmode-off', + description: 'Toggle godmode for an app', + handler: async (args, log) => { + const svc_su = this.services.get('su'); + await await svc_su.sudo(async () => { + const [app_uid] = args; + const es_app = await this.services.get('es:app'); + const app = await es_app.read(app_uid); + if ( ! app ) { + throw new Error(`App ${app_uid} not found`); + } + await db.write('UPDATE apps SET godmode = 0 WHERE uid = ?', [app_uid]); + }); + } + } + ]); } }