MCPcopy Create free account
hub / github.com/diillson/chatcli / authorizeConv

Method authorizeConv

server/handler_hub.go:51–63  ·  view source on GitHub ↗

authorizeConv ensures principal owns convID (admins bypass). Returns a gRPC status error suitable to return directly.

(ctx context.Context, convID, principal string)

Source from the content-addressed store, hash-verified

49// authorizeConv ensures principal owns convID (admins bypass). Returns a
50// gRPC status error suitable to return directly.
51func (h *Handler) authorizeConv(ctx context.Context, convID, principal string) error {
52 owner, err := h.hub.OwnerOf(ctx, convID)
53 if err != nil {
54 return status.Errorf(codes.NotFound, "%s", i18n.T("server.hub.conv_not_found"))
55 }
56 if owner == principal {
57 return nil
58 }
59 if u := UserFromContext(ctx); u != nil && u.HasRole(RoleAdmin) {
60 return nil
61 }
62 return status.Errorf(codes.PermissionDenied, "%s", i18n.T("server.hub.conv_forbidden"))
63}
64
65func (h *Handler) hubReady() error {
66 if h.hub == nil {

Callers 3

AppendEventMethod · 0.95
ReadConversationMethod · 0.95
SubscribeConversationMethod · 0.95

Calls 5

TFunction · 0.92
UserFromContextFunction · 0.85
ErrorfMethod · 0.80
HasRoleMethod · 0.80
OwnerOfMethod · 0.65

Tested by

no test coverage detected