All practice tasks

Coding (Platform)

Tenant Project Pagination

Flask · Medium · Authorization

Two customer accounts use the same project service. An incident report shows another tenant’s projects in a search response and inconsistent totals after pagination. The service authenticates correctly; the regression lies between repository results and the response projection.

Task

Repair tenant isolation and pagination as one consistent pipeline. Preserve existing authentication and error behavior.

Contract

  • Request: GET /projects reads the supplied project repository. Query parameters are optional.
  • Query parameters: q — title text to search for. Default: empty string. Trim whitespace; maximum length: 80 characters. limit — number of rows requested. Default: 20; allowed integers: 1..50. offset — number of matching rows to skip. Default: 0; allowed integers: 0..10000. Numeric parameters must contain digits only. For example, 1.5, -1 and abc are invalid.
  • Authentication: Authorization: Bearer fixture-alpha identifies tenant alpha; fixture-bravo identifies tenant bravo. The supplied authentication helper resolves the tenant. A query/body field is not an identity source.
  • Repository records: Each project has id, title, tenant, archived, seats and version. The fixture provides the data. Use its repository; no external database is required.

Acceptance criteria

  • Success response: Return HTTP 200 with {total, items, nextOffset}. items contains only {id, title, seats, version}. Do not expose the internal tenant field.
  • Which projects appear: Keep only the authenticated tenant’s non-archived projects. Match the title against the trimmed query without regard to letter case. Sort matching projects by ASCII ID before taking the requested page.
  • Pagination: total is the number of all matching projects before pagination, not the page length. Skip offset matches and return at most limit items. nextOffset is offset + items.length only when another matching item remains; otherwise it is null. An exhausted page has items: [] and nextOffset: null, while keeping the full total.
  • Errors: Invalid query: HTTP 400 with {code: "INVALID_QUERY"}. Missing or unknown bearer token: HTTP 401 with {code: "UNAUTHORIZED"}.

Constraints

  • At most 10000 records; query length at most 80; page size at most 50. Test data is local and disposable.
  • Directory reads must not modify records or expose internal tenant fields.
  • Use the supplied repository; no remote database is required.

Editable files

  • src/app.py — Real framework application, HTTP integration and error mapping.
  • src/service.py — Repair the domain selection or consistency operation.
  • src/helpers.py — Optional implementation helpers.
  • tests/test_candidate.py — Add task-specific regressions through api.get/api.post.

What this task practices

Tenant Project Pagination is a coding (platform) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.