rework of hubs

This commit is contained in:
2026-04-29 19:32:26 +02:00
parent 6378966267
commit 909d222a89
5 changed files with 80 additions and 334 deletions
+9 -9
View File
@@ -65,20 +65,20 @@ func getHubByIdStr(ctx context.Context, hubId string) (*types.Hub, error) {
return hub, nil
}
func getHubUserIfValidWithResponseOnFail(ctx context.Context, response http.ResponseWriter, token string, hubId string) (
func getHubUserIfValidWithResponseOnFail(ctx context.Context, response http.ResponseWriter, request *http.Request) (
*types.User, *types.HubUser, *types.Hub, error) {
hub, err := getHubByIdStr(ctx, hubId)
if err != nil {
http.Error(response, "invalid hubid", http.StatusBadRequest)
return nil, nil, nil, errors.New("no such hub")
}
user, err := getUserByToken(ctx, token)
user, err := getUserByToken(ctx, request.Header.Get("token"))
if err != nil {
http.Error(response, "invalid token", http.StatusBadRequest)
return nil, nil, nil, errors.New("invalid token")
}
hub, err := getHubByIdStr(ctx, request.Header.Get("hubid"))
if err != nil {
http.Error(response, "invalid hubid", http.StatusBadRequest)
return nil, nil, nil, errors.New("no such hub")
}
hub.Mu.RLock()
hubUser, ok := hub.Users[user.Id]
hub.Mu.RUnlock()
@@ -103,7 +103,7 @@ func getHubChannelIfValidWithResponseOnFail(ctx context.Context, response http.R
return nil, errors.New("invalid channelid")
}
if !haveHubUserPermissionsOnChannel(types.CachedUserCanView, hubUser, channel) {
if !haveHubUserCachedPermissions(types.CachedUserCanView, hubUser, channel) {
return nil, errors.New("invalid channelid")
}