From 123fbd8317fc7878828a0f85c0f3d80200fb94c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Wed, 2 Dec 2020 16:49:51 +0100 Subject: [PATCH] IsAdmin + IsConnected. --- internal/http/auth/auth.go | 4 ++-- internal/session/manager.go | 10 +++++----- internal/session/session.go | 4 ++-- internal/types/session.go | 4 ++-- internal/websocket/handler/screen.go | 2 +- internal/websocket/handler/session.go | 4 ++-- internal/websocket/handler/system.go | 2 +- internal/websocket/manager.go | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/internal/http/auth/auth.go b/internal/http/auth/auth.go index 077f8518..e1cbd356 100644 --- a/internal/http/auth/auth.go +++ b/internal/http/auth/auth.go @@ -26,7 +26,7 @@ func GetSession(r *http.Request) types.Session { func AdminsOnly(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session := GetSession(r) - if !session.Admin() { + if !session.IsAdmin() { utils.HttpForbidden(w) } else { next.ServeHTTP(w, r) @@ -48,7 +48,7 @@ func HostsOnly(next http.Handler) http.Handler { func HostsOrAdminsOnly(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { session := GetSession(r) - if !session.IsHost() && !session.Admin() { + if !session.IsHost() && !session.IsAdmin() { utils.HttpForbidden(w, "Only host can do this.") } else { next.ServeHTTP(w, r) diff --git a/internal/session/manager.go b/internal/session/manager.go index c133872d..9b50de84 100644 --- a/internal/session/manager.go +++ b/internal/session/manager.go @@ -87,7 +87,7 @@ func (manager *SessionManagerCtx) Delete(id string) error { delete(manager.members, id) - if session.Connected() { + if session.IsConnected() { return session.Disconnect("member deleted") } @@ -137,7 +137,7 @@ func (manager *SessionManagerCtx) Admins() []types.Session { var sessions []types.Session for _, session := range manager.members { - if !session.Connected() || !session.Admin() { + if !session.IsConnected() || !session.IsAdmin() { continue } @@ -153,7 +153,7 @@ func (manager *SessionManagerCtx) Members() []types.Session { var sessions []types.Session for _, session := range manager.members { - if !session.Connected() { + if !session.IsConnected() { continue } @@ -168,7 +168,7 @@ func (manager *SessionManagerCtx) Broadcast(v interface{}, exclude interface{}) defer manager.membersMu.Unlock() for id, session := range manager.members { - if !session.Connected() { + if !session.IsConnected() { continue } @@ -189,7 +189,7 @@ func (manager *SessionManagerCtx) AdminBroadcast(v interface{}, exclude interfac defer manager.membersMu.Unlock() for id, session := range manager.members { - if !session.Connected() || !session.Admin() { + if !session.IsConnected() || !session.IsAdmin() { continue } diff --git a/internal/session/session.go b/internal/session/session.go index 972af4dc..8da9c08b 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -27,7 +27,7 @@ func (session *SessionCtx) Name() string { return session.profile.Name } -func (session *SessionCtx) Admin() bool { +func (session *SessionCtx) IsAdmin() bool { return session.profile.IsAdmin } @@ -39,7 +39,7 @@ func (session *SessionCtx) VerifySecret(secret string) bool { return session.profile.Secret == secret } -func (session *SessionCtx) Connected() bool { +func (session *SessionCtx) IsConnected() bool { // TODO: Refactor. return session.websocket_connected// && session.webrtc_connected } diff --git a/internal/types/session.go b/internal/types/session.go index 0233d2c9..0415b23e 100644 --- a/internal/types/session.go +++ b/internal/types/session.go @@ -16,9 +16,9 @@ type MemberProfile struct { type Session interface { ID() string Name() string - Admin() bool + IsAdmin() bool IsHost() bool - Connected() bool + IsConnected() bool VerifySecret(secret string) bool SetWebSocketPeer(websocket_peer WebSocketPeer) SetWebSocketConnected(connected bool) diff --git a/internal/websocket/handler/screen.go b/internal/websocket/handler/screen.go index 0b9680cb..1927ed42 100644 --- a/internal/websocket/handler/screen.go +++ b/internal/websocket/handler/screen.go @@ -7,7 +7,7 @@ import ( ) func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.ScreenSize) error { - if !session.Admin() { + if !session.IsAdmin() { h.logger.Debug().Msg("user not admin") return nil } diff --git a/internal/websocket/handler/session.go b/internal/websocket/handler/session.go index 49b64384..83ee1679 100644 --- a/internal/websocket/handler/session.go +++ b/internal/websocket/handler/session.go @@ -11,7 +11,7 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error { return err } - if session.Admin() { + if session.IsAdmin() { if err := h.systemAdmin(session); err != nil { return err } @@ -23,7 +23,7 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error { Event: event.MEMBER_CONNECTED, ID: session.ID(), Name: session.Name(), - IsAdmin: session.Admin(), + IsAdmin: session.IsAdmin(), }, nil) return nil diff --git a/internal/websocket/handler/system.go b/internal/websocket/handler/system.go index 57876a16..fe373a5e 100644 --- a/internal/websocket/handler/system.go +++ b/internal/websocket/handler/system.go @@ -28,7 +28,7 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error { members[session.ID()] = message.MemberData{ ID: session.ID(), Name: session.Name(), - IsAdmin: session.Admin(), + IsAdmin: session.IsAdmin(), } } diff --git a/internal/websocket/manager.go b/internal/websocket/manager.go index 1d263dc7..0e81a5a4 100644 --- a/internal/websocket/manager.go +++ b/internal/websocket/manager.go @@ -135,7 +135,7 @@ func (ws *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Request) e return connection.Close() } - if session.Connected() { + if session.IsConnected() { // TODO: Refactor if err = connection.WriteJSON( message.SystemDisconnect{