All jobs

Add a Password Change Endpoint to a Django REST Framework API from a Linear Issue

Yes. An agent reads the labelled Linear issue, adds a password change service and an authenticated API in the repo's own layout with tests, and opens a linked PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent works from the issue text and the repository as it is. In a project shaped like HackSoftware/Django-Styleguide-Example it reads requirements/base.txt and finds Django 5.2.7, djangorestframework 3.16.1 and drf-jwt 1.19.2, and requirements/local.txt with pytest 8.4.2, pytest-django, factory-boy, mypy and ruff. It reads styleguide_example/users/apis.py, where UserDetailApi, UserListApi, UserCreateApi and UserUpdateApi each declare an inner InputSerializer or OutputSerializer and call into users/services.py or users/selectors.py, and users/urls.py, which routes them under api/users/. It reads users/services.py, where user_create and user_update are @transaction.atomic functions with keyword-only arguments, and api/mixins.py, where ApiAuthMixin combines CSRF-exempt session, session-as-header and JWT authentication with IsAuthenticated. There is no way for a user to change a password.

The change follows the layout the repository teaches. In users/services.py the agent adds user_change_password(*, user, current_password, new_password): it checks current_password with user.check_password, raises Django's ValidationError when it does not match, runs validate_password from django.contrib.auth.password_validation against the new one so the project's AUTH_PASSWORD_VALIDATORS apply, calls set_password, saves with update_fields, and returns the user. In users/apis.py it adds UserPasswordChangeApi(ApiAuthMixin, APIView) with an InputSerializer of two CharFields, calls the service with request.user, and returns an empty 200. In users/urls.py it adds path("me/password/", ...) placed before the <int:user_id>/ patterns so it is matched by name and never as an id. Because ValidationError is already turned into a 400 by api/exception_handlers.py, the API needs no try block of its own.

The tests sit where the project keeps them. users/tests/services/test_user_create.py is a Django TestCase calling the service directly, so the agent adds test_user_change_password.py beside it: a correct current password changes the hash and check_password on the new one returns true, a wrong current password raises ValidationError and leaves the hash unchanged, and a new password that fails the configured validators is refused. For the API it adds users/tests/apis/test_user_password_change.py using DRF's APIClient with force_authenticate, covering a 200, a 400 on a wrong current password, and a 401 with no authentication. The JWT secret in authentication/services.py is derived per user, so the agent adds one more assertion that logging in with the new password still works through api/auth/jwt/login/.

It runs pytest with config.django.test as the settings module, which pytest.ini already sets, then ruff check . and mypy --config mypy.ini styleguide_example/ exactly as .github/workflows/django.yml does, fixes whatever those report, and only then pushes a branch and opens a pull request that links the Linear issue in its description.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "A Linear issue labelled agent says: \"Add a password change endpoint. An authenticated user POSTs their current and new password to api/users/me/password/; a wrong current password is a 400, a weak new password is refused by the configured validators, and a successful change returns 200.\" Follow this repository's service and selector layout: a user_change_password service in users/services.py, an ApiAuthMixin API with an inner InputSerializer in users/apis.py, the URL in users/urls.py. Add service tests and API tests under users/tests, run pytest, ruff check and mypy as the CI workflow does, and open a pull request that links back to the issue.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request on its own branch. The diff adds user_change_password to styleguide_example/users/services.py, UserPasswordChangeApi to users/apis.py, one path line to users/urls.py, and two new test files under users/tests/services and users/tests/apis. No model or migration changes, because BaseUser already stores the password hash through AbstractBaseUser. The description quotes the issue, names the endpoint, and lists the three error cases the tests cover.

The repository's own CI runs the proof again. .github/workflows/django.yml installs requirements/local.txt on Python 3.12, starts a Postgres service, and runs ruff check ., mypy and pytest on every push, so the new tests execute on the pull request branch as well as in the sandbox. The session's trajectory at GET /o/{org}/sessions/{id}/messages keeps every pytest run with its output.

Before merging, a reviewer checks that the service calls validate_password with the user so validators like the similarity check have what they need, that the URL pattern sits above <int:user_id>/ in users/urls.py, and that the API returns no body that could echo the new password. Nothing reaches the main branch until the pull request merges.

Run it on every Linear issue labelled agent

Sign in to Linear once from the console, which creates a linear app connection on your account. Then add an automation in the Project that holds this repository with the prompt above, minus the quoted issue, and a linear trigger on linear.issue.labeled for the agent label. Each labelled issue starts one run with the issue as its context after the prompt, and each run opens its own pull request that links back, so a backlog of small API additions turns into reviewable branches without anyone checking the repository out.

The Rush GitHub App must be installed on the repository first, the one step the API does not do. An automation run has its own max_runs_per_hour cap, so relabelling a whole sprint spreads the runs out rather than refusing them. Changes made by an app integration never fire the trigger, so a comment the run leaves on its own issue does not start another.

The use case this job follows, with its automation and trigger: Turn a Linear label into a PR.

Why run it on Rush?

A password endpoint is the kind of change where the layout matters as much as the code: this repository has a styleguide for where services, selectors, serializers and tests live, and a pull request that ignores it gets sent back. Proving it means Postgres running, the local requirements installed, and pytest, ruff and mypy all green, which on a laptop is a working tree you cannot use for anything else until the branch is pushed. On Rush the run gets its own sandbox with a computer in it: the agent brings up the database from docker-compose.yml, runs the three checks as many times as it takes, and pushes only when they pass.

The result is a pull request with evidence, not a summary. The diff shows the service, the API and the tests in the places the styleguide names, the CI workflow runs the same three checks on the pull request, and the trajectory keeps every run and its output. Several labelled issues become several sandboxes and several pull requests at once, each isolated from the others.

Frequently asked questions

Which authentication does the endpoint accept?

The same three ApiAuthMixin already combines for UserMeApi and UserJwtLogoutApi: a session cookie with CSRF exempted, a session passed as an Authorization: Session header, and a JWT from drf-jwt. A request with none of them is a 401, and one of the API tests asserts that.

Will existing JWTs stay valid after a password change?

That depends on auth_user_get_jwt_secret_key in authentication/services.py, which derives each user's JWT secret. The agent reads it and says in the pull request whether the secret changes with the password; if you want every other session logged out on change, say so in the issue and the agent rotates the per-user secret in the service.

Does it add a password reset by email as well?

No. The issue asks for a change by an authenticated user who knows the current password, which needs no token or email. Reset by email is a separate flow with its own token model and would be its own issue and its own pull request.

How are weak passwords refused?

The service calls Django's validate_password with the user, so every validator in the project's AUTH_PASSWORD_VALIDATORS runs, and a failure is a ValidationError that the repository's exception handler turns into a 400 with the messages. One service test and one API test cover a password the validators reject.

Why is there no serializer file?

Because the styleguide this repository follows declares serializers inline on each API class, as UserCreateApi.InputSerializer already does, and keeps business rules in services. The new API follows that exactly so it reads like the code around it.

More Django REST Framework jobs

More jobs like this: Turn a Linear label into a PR

Keep reading