IsAdmin + IsConnected.

This commit is contained in:
Miroslav Šedivý 2020-12-02 16:49:51 +01:00
parent 25fec63455
commit 123fbd8317
8 changed files with 16 additions and 16 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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
}

View File

@ -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)

View File

@ -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
}

View File

@ -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

View File

@ -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(),
}
}

View File

@ -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{