add locked controls to settings.

This commit is contained in:
Miroslav Šedivý 2023-05-14 22:41:32 +02:00
parent b8fccc4d07
commit cf4e0666fe
4 changed files with 19 additions and 0 deletions

View File

@ -39,6 +39,10 @@ func (h *RoomHandler) controlRequest(w http.ResponseWriter, r *http.Request) err
} }
session, _ := auth.GetSession(r) session, _ := auth.GetSession(r)
if h.sessions.Settings().LockedControls && !session.Profile().IsAdmin {
return utils.HttpForbidden("controls are locked")
}
h.sessions.SetHost(session) h.sessions.SetHost(session)
return utils.HttpSuccess(w) return utils.HttpSuccess(w)

View File

@ -20,6 +20,7 @@ func New(config *config.Session) *SessionManagerCtx {
config: config, config: config,
settings: types.Settings{ settings: types.Settings{
PrivateMode: false, // By default disabled. PrivateMode: false, // By default disabled.
LockedControls: false, // By default disabled.
ImplicitHosting: config.ImplicitHosting, ImplicitHosting: config.ImplicitHosting,
InactiveCursors: config.InactiveCursors, InactiveCursors: config.InactiveCursors,
MercifulReconnect: config.MercifulReconnect, MercifulReconnect: config.MercifulReconnect,
@ -387,6 +388,15 @@ func (manager *SessionManagerCtx) UpdateSettings(new types.Settings) {
} }
} }
// if contols have been locked
if old.LockedControls != new.LockedControls && new.LockedControls {
// if the host is not admin, it must release controls
host, hasHost := manager.GetHost()
if hasHost && !host.Profile().IsAdmin {
manager.ClearHost()
}
}
manager.emmiter.Emit("settings_changed", new, old) manager.emmiter.Emit("settings_changed", new, old)
} }

View File

@ -40,6 +40,10 @@ func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
return ErrIsAlreadyTheHost return ErrIsAlreadyTheHost
} }
if h.sessions.Settings().LockedControls && !session.Profile().IsAdmin {
return ErrIsNotAllowedToHost
}
if !h.sessions.Settings().ImplicitHosting { if !h.sessions.Settings().ImplicitHosting {
// tell session if there is a host // tell session if there is a host
if host, hasHost := h.sessions.GetHost(); hasHost { if host, hasHost := h.sessions.GetHost(); hasHost {

View File

@ -30,6 +30,7 @@ type SessionState struct {
type Settings struct { type Settings struct {
PrivateMode bool `json:"private_mode"` PrivateMode bool `json:"private_mode"`
LockedControls bool `json:"locked_controls"`
ImplicitHosting bool `json:"implicit_hosting"` ImplicitHosting bool `json:"implicit_hosting"`
InactiveCursors bool `json:"inactive_cursors"` InactiveCursors bool `json:"inactive_cursors"`
MercifulReconnect bool `json:"merciful_reconnect"` MercifulReconnect bool `json:"merciful_reconnect"`