members

package
v2.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package members implements helpers for accessing the currently logged in admin or moderator of an active request.

Index

Constants

View Source
const (
	ActionInviteMember     = "invite"
	ActionChangeDeniedKeys = "change-denied-keys"
	ActionRemoveMember     = "remove-member"
	ActionChangeNotice     = "change-notice"
)

member actions

Variables

This section is empty.

Functions

func CheckAllowed

func CheckAllowed(ctx context.Context, cfg roomdb.RoomConfig, action string) (*roomdb.Member, error)

CheckAllowed retreives the member from the passed context and lookups the current privacy mode from the passed cfg to determain if the action is okay or not. If it's not it returns an error. For convenience it also returns the member if the action is okay.

func FromContext

func FromContext(ctx context.Context) *roomdb.Member

FromContext returns the member or nil if not logged in

func MiddlewareForTests

func MiddlewareForTests(m *roomdb.Member) func(http.Handler) http.Handler

MiddlewareForTests gives us a way to inject _test members_. It should not be used in production. This is part of testing.go because we need to use roomMemberContextKey, which shouldn't be exported either. TODO: could be protected with an extra build tag. (Sadly +build test does not exist https://github.com/golang/go/issues/21360 )

func TemplateHelpers

func TemplateHelpers(roomCfg roomdb.RoomConfig) []render.Option

TemplateHelpers returns functions to be used with the go.mindeco.de/http/render package. Each helper has to return a function twice because the first is evaluated with the request before it gets passed onto html/template's FuncMap.

{{ is_logged_in }} returns true or false depending on if the user is logged in

{{ member_has_role "string" }} returns a boolean which confrms wether the member has a certain role (RoleMemeber, RoleAdmin, etc)

{{ member_is_admin }} is a shortcut for {{ member_has_role "RoleAdmin" }}

{{ member_is_elevated }} is a shortcut for {{ or member_has_role "RoleAdmin" member_has_role "RoleModerator"}}

{{ member_can "action" }} returns true if a member can execute a certain action. Actions are "invite" and "remove-denied-key". See allowedActions to add more.

Types

type AllowedFunc

type AllowedFunc func(mode roomdb.PrivacyMode, role roomdb.Role) bool

AllowedFunc returns true if a member role is allowed to do a thing under the passed mode

func AllowedActions

func AllowedActions(name string) (AllowedFunc, bool)

AllowedActions exposes check function by name. It exists to protected against changes of the map

type Middleware

type Middleware func(next http.Handler) http.Handler

func AuthenticateFromContext

func AuthenticateFromContext(r *render.Renderer) Middleware

AuthenticateFromContext calls the next http handler if there is a member stored in the context otherwise it will call r.Error

func ContextInjecter

func ContextInjecter(mdb roomdb.MembersService, withPassword *auth.Handler, withSSB *authWithSSB.WithSSBHandler) Middleware

ContextInjecter returns middleware for injecting a member into the context of the request. Retreive it using FromContext(ctx)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL