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

Method getRights

pkg/identityserver/rights.go:41–99  ·  view source on GitHub ↗
(
	ctx context.Context, entityID *ttnpb.EntityIdentifiers,
)

Source from the content-addressed store, hash-verified

39}
40
41func (is *IdentityServer) getRights(
42 ctx context.Context, entityID *ttnpb.EntityIdentifiers,
43) (entityRights, universalRights *ttnpb.Rights, err error) {
44 authInfo, err := is.authInfo(ctx)
45 if err != nil {
46 return nil, nil, err
47 }
48
49 authInfoRights := ttnpb.RightsFrom(authInfo.GetRights()...)
50 universalRights = allPotentialRights(entityID, authInfo.GetUniversalRights())
51 if len(universalRights.GetRights()) == 0 {
52 universalRights = nil
53 }
54 allPotentialRights := allPotentialRights(entityID, authInfoRights)
55
56 // If the rights of the auth do not contain any rights for the entity type,
57 // there's nothing more to do.
58 if len(allPotentialRights.GetRights()) == 0 {
59 return nil, universalRights, nil
60 }
61
62 // If the caller is the requested entity,
63 // we can directly return the rights of the auth.
64 authenticatedAs := authInfo.GetEntityIdentifiers()
65 if entityID.EntityType() == authenticatedAs.EntityType() &&
66 entityID.IDString() == authenticatedAs.IDString() {
67 return authInfoRights, universalRights, nil
68 }
69
70 // If the caller is not an organization or user, there's nothing more to do.
71 ouID := authInfo.GetOrganizationOrUserIdentifiers()
72 if ouID == nil {
73 return nil, universalRights, nil
74 }
75
76 // If the caller is requesting a user, and they're not that user (see above),
77 // they don't have rights on it, so nothing more to do.
78 if entityID.GetUserIds() != nil {
79 return nil, universalRights, nil
80 }
81
82 err = is.store.Transact(ctx, func(ctx context.Context, st store.Store) error {
83 membershipChains, err := st.FindAccountMembershipChains(ctx, ouID, entityID.EntityType(), entityID.IDString())
84 if err != nil {
85 return err
86 }
87 for _, chain := range membershipChains {
88 entityRights = entityRights.Union(chain.GetRights())
89 }
90 return nil
91 })
92 if err != nil {
93 return nil, nil, err
94 }
95
96 entityRights = entityRights.Intersect(authInfoRights)
97
98 return entityRights, universalRights, err

Callers 5

ApplicationRightsMethod · 0.95
ClientRightsMethod · 0.95
GatewayRightsMethod · 0.95
OrganizationRightsMethod · 0.95
UserRightsMethod · 0.95

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 14

authInfoMethod · 0.95
RightsFromFunction · 0.92
allPotentialRightsFunction · 0.85
UnionMethod · 0.80
IntersectMethod · 0.80
GetEntityIdentifiersMethod · 0.65
EntityTypeMethod · 0.65
IDStringMethod · 0.65
TransactMethod · 0.65
GetRightsMethod · 0.45
GetUniversalRightsMethod · 0.45

Tested by

no test coverage detected