ListUser lists the rights for the given user ID in the context.
(ctx context.Context, id *ttnpb.UserIdentifiers)
| 148 | |
| 149 | // ListUser lists the rights for the given user ID in the context. |
| 150 | func ListUser(ctx context.Context, id *ttnpb.UserIdentifiers) (rights *ttnpb.Rights, err error) { |
| 151 | uid := unique.ID(ctx, id) |
| 152 | if inCtx, ok := fromContext(ctx); ok { |
| 153 | r, _ := inCtx.UserRights.GetRights(uid) |
| 154 | return r, nil |
| 155 | } |
| 156 | if inCtx, ok := cacheFromContext(ctx); ok { |
| 157 | if r, ok := inCtx.UserRights.GetRights(uid); ok { |
| 158 | return r, nil |
| 159 | } |
| 160 | } |
| 161 | defer func() { |
| 162 | if err == nil { |
| 163 | cacheInContext(ctx, func(r *Rights) { r.setUserRights(uid, rights) }) |
| 164 | } |
| 165 | }() |
| 166 | fetcher, ok := fetcherFromContext(ctx) |
| 167 | if !ok { |
| 168 | panic(errNoFetcher) |
| 169 | } |
| 170 | rights, err = fetcher.UserRights(ctx, id) |
| 171 | if err != nil { |
| 172 | if errors.IsPermissionDenied(err) { |
| 173 | return &ttnpb.Rights{}, nil |
| 174 | } |
| 175 | return nil, err |
| 176 | } |
| 177 | return rights, nil |
| 178 | } |
no test coverage detected