feat(server): add project sharing access control
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package sharing
|
||||
|
||||
import "context"
|
||||
|
||||
type actorContextKey struct{}
|
||||
type accessContextKey struct{}
|
||||
|
||||
func ContextWithActor(ctx context.Context, actor Actor) context.Context {
|
||||
return context.WithValue(ctx, actorContextKey{}, actor)
|
||||
}
|
||||
|
||||
func ActorFromContext(ctx context.Context) Actor {
|
||||
if ctx == nil {
|
||||
return Actor{}
|
||||
}
|
||||
actor, _ := ctx.Value(actorContextKey{}).(Actor)
|
||||
return actor
|
||||
}
|
||||
|
||||
func ContextWithAccess(ctx context.Context, access Access) context.Context {
|
||||
return context.WithValue(ctx, accessContextKey{}, access)
|
||||
}
|
||||
|
||||
func AccessFromContext(ctx context.Context) (Access, bool) {
|
||||
if ctx == nil {
|
||||
return Access{}, false
|
||||
}
|
||||
access, ok := ctx.Value(accessContextKey{}).(Access)
|
||||
return access, ok
|
||||
}
|
||||
Reference in New Issue
Block a user