MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / GatewayRights

Method GatewayRights

pkg/identityserver/rights.go:145–175  ·  view source on GitHub ↗

GatewayRights returns the rights the caller has on the given gateway. The query for the gateway only considers the Gateway ID and not the EUI (if provided).

(ctx context.Context, gtwIDs *ttnpb.GatewayIdentifiers)

Source from the content-addressed store, hash-verified

143// GatewayRights returns the rights the caller has on the given gateway.
144// The query for the gateway only considers the Gateway ID and not the EUI (if provided).
145func (is *IdentityServer) GatewayRights(ctx context.Context, gtwIDs *ttnpb.GatewayIdentifiers) (*ttnpb.Rights, error) {
146 ids := &ttnpb.GatewayIdentifiers{
147 GatewayId: gtwIDs.GatewayId,
148 }
149 entity, universal, err := is.getRights(ctx, ids.GetEntityIdentifiers())
150 if err != nil {
151 return nil, err
152 }
153 err = is.store.Transact(ctx, func(ctx context.Context, st store.Store) (err error) {
154 gtw, err := st.GetGateway(ctx, ids, []string{"ids", "status_public", "location_public"})
155 if err != nil {
156 return err
157 }
158 if gtw.StatusPublic {
159 entity = entity.Union(ttnpb.RightsFrom(ttnpb.Right_RIGHT_GATEWAY_STATUS_READ))
160 }
161 if gtw.LocationPublic {
162 entity = entity.Union(ttnpb.RightsFrom(ttnpb.Right_RIGHT_GATEWAY_LOCATION_READ))
163 }
164 return nil
165 })
166 if errors.IsNotFound(err) {
167 if is.IsAdmin(ctx) {
168 return nil, err
169 }
170 return &ttnpb.Rights{}, nil
171 } else if err != nil {
172 return nil, err
173 }
174 return entity.Union(universal), nil
175}
176
177// OrganizationRights returns the rights the caller has on the given organization.
178func (is *IdentityServer) OrganizationRights(ctx context.Context, orgIDs *ttnpb.OrganizationIdentifiers) (*ttnpb.Rights, error) {

Callers

nothing calls this directly

Implementers 5

mockInteroppkg/component/interop_test.go
interopServerpkg/joinserver/http_interop.go
noopServerpkg/interop/server.go
mockTargetpkg/interop/server_test.go
interopServerpkg/identityserver/http_interop.go

Calls 8

getRightsMethod · 0.95
GetEntityIdentifiersMethod · 0.95
IsAdminMethod · 0.95
RightsFromFunction · 0.92
IsNotFoundFunction · 0.92
UnionMethod · 0.80
TransactMethod · 0.65
GetGatewayMethod · 0.65

Tested by

no test coverage detected