Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip membership chains check if no entities are to be checked #6668

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ For details about compatibility between different releases, see the **Commitment
### Fixed

- Resolve scroll jumps when selecting different tabs of a table in the Console.
- `BatchGetGatewayConnectionStats` RPC rights check in certain cases.
nicholaspcr marked this conversation as resolved.
Show resolved Hide resolved

### Security

Expand Down
4 changes: 2 additions & 2 deletions pkg/identityserver/gateway_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ type gatewayBatchAccess struct {
}

var (
errEmtpyRequest = errors.DefineInvalidArgument(
errEmptyRequest = errors.DefineInvalidArgument(
"empty_request",
"empty request",
)
Expand All @@ -555,7 +555,7 @@ func (gba *gatewayBatchAccess) AssertRights(
// Sanitize request.
required := req.Required.Unique()
if len(required.GetRights()) == 0 {
return nil, errEmtpyRequest.New()
return nil, errEmptyRequest.New()
}

// Check that the request is checking only gateway rights.
Expand Down
19 changes: 19 additions & 0 deletions pkg/identityserver/rights.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2019 The Things Network Foundation, The Things Industries B.V.

Check warning on line 1 in pkg/identityserver/rights.go

View workflow job for this annotation

GitHub Actions / Check Mergeability

pkg/identityserver/rights.go has a conflict when merging TheThingsIndustries/lorawan-stack:v3.28.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -252,6 +252,9 @@
return errInsufficientRights.New()
}

// If the caller has specified the identifiers multiple times, deduplicate them.
gtwIDs = uniqueIdentifiers(gtwIDs)

return is.store.Transact(ctx, func(ctx context.Context, st store.Store) error {
gtws, err := st.FindGateways(ctx, gtwIDs, []string{"ids", "status_public", "location_public"})
if err != nil {
Expand Down Expand Up @@ -316,6 +319,9 @@
}
entityIDs = append(entityIDs, gtwID.GetEntityIdentifiers().IDString())
}
if len(entityIDs) == 0 {
return nil
}
membershipChains, err := st.FindAccountMembershipChains(
ctx,
ouID,
Expand All @@ -341,3 +347,16 @@
return nil
})
}

func uniqueIdentifiers[T ttnpb.IDStringer](ids []T) []T {
m := make(map[string]struct{}, len(ids))
result := make([]T, 0, len(ids))
for _, id := range ids {
if _, ok := m[id.IDString()]; ok {
continue
}
m[id.IDString()] = struct{}{}
result = append(result, id)
}
return result
}
Loading