rework of hubs
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user