RequireUser checks that context contains the required rights for the given user ID.
(ctx context.Context, id *ttnpb.UserIdentifiers, required ...ttnpb.Right)
| 198 | // RequireUser checks that context contains the required rights for the |
| 199 | // given user ID. |
| 200 | func RequireUser(ctx context.Context, id *ttnpb.UserIdentifiers, required ...ttnpb.Right) (err error) { |
| 201 | uid := unique.ID(ctx, id) |
| 202 | rights, err := ListUser(ctx, id) |
| 203 | if err != nil { |
| 204 | return err |
| 205 | } |
| 206 | if len(rights.GetRights()) == 0 { |
| 207 | return ErrNoUserRights.WithAttributes("uid", uid) |
| 208 | } |
| 209 | missing := ttnpb.RightsFrom(required...).Sub(rights).GetRights() |
| 210 | if len(missing) > 0 { |
| 211 | return ErrInsufficientUserRights.WithAttributes("uid", uid, "missing", rightsNames(missing...)) |
| 212 | } |
| 213 | return nil |
| 214 | } |
| 215 | |
| 216 | // RequireAny checks that context contains any rights for each of |
| 217 | // the given entity identifiers. |