fix hub bugs, add channel role permission endpoints

Covers: snake_case param renames, mutex RLock/Unlock mismatches, user.Hubs keyed by hub.Id, hub color using new_name, DELETE params sent as query, delete(target.Hubs, hub.Id), root/member role Id swap, and the three new PATCH
  /hub/channel/roles/* handlers.
This commit is contained in:
2026-05-03 15:51:57 +02:00
parent cb003d235f
commit c0d4483154
9 changed files with 732 additions and 218 deletions
+11 -8
View File
@@ -73,9 +73,9 @@ func getHubUserIfValidWithResponseOnFail(ctx context.Context, response http.Resp
return nil, nil, nil, errors.New("invalid token")
}
hub, err := getHubByIdStr(ctx, request.Header.Get("hubid"))
hub, err := getHubByIdStr(ctx, request.Header.Get("hub_id"))
if err != nil {
http.Error(response, "invalid hubid", http.StatusBadRequest)
http.Error(response, "invalid hub_id", http.StatusBadRequest)
return nil, nil, nil, errors.New("no such hub")
}
@@ -83,8 +83,8 @@ func getHubUserIfValidWithResponseOnFail(ctx context.Context, response http.Resp
hubUser, ok := hub.Users[user.Id]
hub.Mu.RUnlock()
if !ok {
http.Error(response, "invalid hubid", http.StatusUnauthorized)
return nil, nil, nil, errors.New("invalid hubid")
http.Error(response, "invalid hub_id", http.StatusUnauthorized)
return nil, nil, nil, errors.New("invalid hub_id")
}
return user, hubUser, hub, nil
@@ -94,13 +94,16 @@ func getHubChannelIfValidWithResponseOnFail(ctx context.Context, response http.R
*types.HubChannel, error) {
channelUuid, err := convertions.StringToUuid(channelId)
if err != nil {
http.Error(response, "invalid channelid", http.StatusBadRequest)
return nil, errors.New("invalid channelid")
http.Error(response, "invalid channel_id", http.StatusBadRequest)
return nil, errors.New("invalid channel_id")
}
hub.Mu.RLock()
channel, ok := hub.Channels[channelUuid]
hub.Mu.RUnlock()
if !ok {
http.Error(response, "invalid channelid", http.StatusBadRequest)
return nil, errors.New("invalid channelid")
http.Error(response, "channel not found", http.StatusNotFound)
return nil, errors.New("channel not found")
}
if !haveHubUserCachedPermissions(types.CachedUserCanView, hubUser, channel) {