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

Function ListOrganization

pkg/auth/rights/list.go:119–147  ·  view source on GitHub ↗

ListOrganization lists the rights for the given organization ID in the context.

(ctx context.Context, id *ttnpb.OrganizationIdentifiers)

Source from the content-addressed store, hash-verified

117
118// ListOrganization lists the rights for the given organization ID in the context.
119func ListOrganization(ctx context.Context, id *ttnpb.OrganizationIdentifiers) (rights *ttnpb.Rights, err error) {
120 uid := unique.ID(ctx, id)
121 if inCtx, ok := fromContext(ctx); ok {
122 r, _ := inCtx.OrganizationRights.GetRights(uid)
123 return r, nil
124 }
125 if inCtx, ok := cacheFromContext(ctx); ok {
126 if r, ok := inCtx.OrganizationRights.GetRights(uid); ok {
127 return r, nil
128 }
129 }
130 defer func() {
131 if err == nil {
132 cacheInContext(ctx, func(r *Rights) { r.setOrganizationRights(uid, rights) })
133 }
134 }()
135 fetcher, ok := fetcherFromContext(ctx)
136 if !ok {
137 panic(errNoFetcher)
138 }
139 rights, err = fetcher.OrganizationRights(ctx, id)
140 if err != nil {
141 if errors.IsPermissionDenied(err) {
142 return &ttnpb.Rights{}, nil
143 }
144 return nil, err
145 }
146 return rights, nil
147}
148
149// ListUser lists the rights for the given user ID in the context.
150func ListUser(ctx context.Context, id *ttnpb.UserIdentifiers) (rights *ttnpb.Rights, err error) {

Callers 4

EventIsVisibleFunction · 0.92
RequireOrganizationFunction · 0.85
RequireAnyFunction · 0.85

Calls 9

IDFunction · 0.92
IsPermissionDeniedFunction · 0.92
fromContextFunction · 0.85
cacheFromContextFunction · 0.85
cacheInContextFunction · 0.85
setOrganizationRightsMethod · 0.80
fetcherFromContextFunction · 0.70
OrganizationRightsMethod · 0.65
GetRightsMethod · 0.45

Tested by

no test coverage detected