Skip to content

Refactor user settings access-token flow to form-fetch-action + JSONError #39241

Description

@joestump-agent

Description

routers/web/user/setting/applications.go still manages access tokens with the deprecated page-rerender pattern: ApplicationsPost answers validation and domain errors with ctx.Flash.Error + redirect (and the last renderPage-style attempt in PR #38966 was rejected in favor of the form-fetch-action + JSONError framework). The form in templates/shared/user/access_tokens.tmpl is a plain form submit, so a failed POST redirects away and wipes the token name the user just typed.

Proposal

Migrate the user-settings access-token flow onto the modern "form-fetch-action" + JSONError framework, the same way repo/setting/deploy_key.go already does:

  • Add form-fetch-action to the create form (regenerate/delete already answer ctx.JSONRedirect) and bind the handler with context.GetFetchActionForm instead of web.GetForm + ctx.HasError.
  • Answer validation and domain errors (ErrAccessTokenNoPermission, duplicate name, scope escalation) with ctx.JSONError / ctx.JSONErrorWithField so the client shows a toast and the submitted form state survives.
  • Decide on a consistent way to display the one-time token value after a successful create (currently ctx.Flash.Info), ideally with the existing clipboard affordance.

This extracts the settings-side half of the rework done in #38966 so the admin bot-token flow and the user-settings flow stay consistent.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions