Skip to content

Commit

Permalink
Merge pull request #6668 from TheThingsNetwork/fix/single-stats
Browse files Browse the repository at this point in the history
Skip membership chains check if no entities are to be checked
  • Loading branch information
adriansmares authored Nov 1, 2023
2 parents 9899438 + bd7061c commit 8f61cd8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
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.

### 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
Expand Up @@ -252,6 +252,9 @@ func (is *IdentityServer) assertGatewayRights( // nolint:gocyclo
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 @@ func (is *IdentityServer) assertGatewayRights( // nolint:gocyclo
}
entityIDs = append(entityIDs, gtwID.GetEntityIdentifiers().IDString())
}
if len(entityIDs) == 0 {
return nil
}
membershipChains, err := st.FindAccountMembershipChains(
ctx,
ouID,
Expand All @@ -341,3 +347,16 @@ func (is *IdentityServer) assertGatewayRights( // nolint:gocyclo
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
}

0 comments on commit 8f61cd8

Please sign in to comment.