Web/maintenance/explicit model endpoints#22897
Open
kensternberg-authentik wants to merge 2 commits into
Open
Conversation
## What
Provide an alternative syntax for defining the load/create/update methods in ModelForm.
Provide a default message for `getSuccessMessage`: `Successfully created` or `Successfully updated` plus the verboseName, if defined.
The old syntax still exists, and is required for a number of complicated and crusty forms with multiple fetches or unusual return values.
`getSuccessMessage()` can still be overridden, if you feel it’s necessary.
## How
### Retrieve / Create / Update
This builds on the insights from the `aki()` authentik API wrapper: find a way to wrap boilerplate in a function. Every ModelForm supplies three methods: `load()`, `send()`, and `getSuccessMessage()`. `send()` is secretly two different methods in a trenchcoat: it’s `create()` and `update()`, depending on whether or not the object has an instancePk.
This commit adds a new field to ModelForm: `endpoints?`, which contains fields for `load`, `create`, and `update`; these contain *only* the minimal code needed to perform these duties. For example, the FlowForm’s endpoints look like this:
protected endpoints = {
load: (slug: string) => aki(FlowsApi).flowsInstancesRetrieve({ slug }),
create: (flowRequest: Flow) => aki(FlowsApi).flowsInstancesCreate({ flowRequest }),
update: (slug: string, flowRequest: Flow) =>
aki(FlowsApi).flowsInstancesUpdate({ slug, flowRequest }),
};
New concrete implementations of `load` and `send` in FlowForm, if not overridden (as they typically are now), look for `endpoints.load`, `endpoints.create`, and (if `instancePk` is set) `endpoints.update`, and call the functions defined in `endpoints`, providing the same functionality as before. Both calls have exception handlers for “Neither overridden nor properly parameterized”, preserving the existing error condition semantics.
### Success… messages.
`getSuccessMessage()` was just a funny fix: every form defines a `verboseName`; it exists to populate this message: `An error occurred while loading ${this.verboseName}.` That’s it. That’s all it does.
And then every form implements this stanza:
public override getSuccessMessage(): string {
return this.instance
? msg("Successfully updated flow.")
: msg("Successfully created flow.");
}
So I provided a better default in ModelForm.
public override getSuccessMessage() {
if (!this.verboseName) return super.getSuccessMessage();
return this.instancePk === null
? msg(str`Successfully created ${this.verboseName}`)
: msg(str`Successfully updated ${this.verboseName}`);
}
Define the verboseName and don’t worry, be happy:
✅ Deploy Preview for authentik-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-integrations ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
…to web/maintenance/explicit-model-endpoints * web/maintenance/eliminates-even-the-toughest-stains: ci: bump taiki-e/install-action from 2.81.1 to 2.81.2 in /.github/actions/setup (#22884) website/integrations: add Atlantis integration (#22888) website/docs: Document WebAuthn device restrictions (#22867) web/admin: fix Docker outpost integration form CA Cert filter (#22863) web: bump @sentry/browser from 10.54.0 to 10.55.0 in /web in the sentry group across 1 directory (#22873) core: bump sentry-sdk from 2.60.0 to 2.61.0 (#22875) core: bump google-api-python-client from 2.196.0 to 2.197.0 (#22876) core: bump kubernetes from 36.0.0 to 36.0.2 (#22879) web: bump the bundler group across 1 directory with 3 updates (#22881) core: bump debugpy from 1.8.20 to 1.8.21 (#22880) ci: bump github/codeql-action from 4.36.0 to 4.36.1 (#22882) ci: bump AndreKurait/docker-cache from 0.6.0 to 0.7.0 in /.github/actions/setup (#22883)
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
|
authentik PR Installation instructions Instructions for docker-composeAdd the following block to your AUTHENTIK_IMAGE=ghcr.io/goauthentik/dev-server
AUTHENTIK_TAG=gh-2ffcbc37c7d2c7413fa5bb55b88e3be2ac0308fd
AUTHENTIK_OUTPOSTS__CONTAINER_IMAGE_BASE=ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)sAfterwards, run the upgrade commands from the latest release notes. Instructions for KubernetesAdd the following block to your authentik:
outposts:
container_image_base: ghcr.io/goauthentik/dev-%(type)s:gh-%(build_hash)s
global:
image:
repository: ghcr.io/goauthentik/dev-server
tag: gh-2ffcbc37c7d2c7413fa5bb55b88e3be2ac0308fdAfterwards, run the upgrade commands from the latest release notes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
web/maintenance: eliminate boilerplate methods from ModelForm
What
Provide an alternative syntax for defining the load/create/update methods in ModelForm.
Provide a default message for
getSuccessMessage:Successfully createdorSuccessfully updatedplus the verboseName, if defined.The old syntax still exists, and is required for a number of complicated and crusty forms with multiple fetches or unusual return values.
getSuccessMessage()can still be overridden, if you feel it’s necessary.How
Retrieve / Create / Update
This builds on the insights from the
aki()authentik API wrapper: find a way to wrap boilerplate in a function. Every ModelForm supplies three methods:load(),send(), andgetSuccessMessage().send()is secretly two different methods in a trenchcoat: it’screate()andupdate(), depending on whether or not the object has an instancePk.This commit adds a new field to ModelForm:
endpoints?, which contains fields forload,create, andupdate; these contain only the minimal code needed to perform these duties. For example, the FlowForm’s endpoints look like this:New concrete implementations of
loadandsendin FlowForm, if not overridden (as they typically are now), look forendpoints.load,endpoints.create, and (ifinstancePkis set)endpoints.update, and call the functions defined inendpoints, providing the same functionality as before. Both calls have exception handlers for “Neither overridden nor properly parameterized”, preserving the existing error condition semantics.Success… messages.
getSuccessMessage()was just a funny fix: every form defines averboseName; it exists to populate this message:An error occurred while loading ${this.verboseName}.That’s it. That’s all it does.And then every form implements this stanza:
So I provided a better default in ModelForm.
Define the verboseName and don’t worry, be happy:
Checklist
make all)make docs)