-
Notifications
You must be signed in to change notification settings - Fork 461
feat: hooks round 5 (Option 2) - add before-user-created hook #2034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
This commit explores one possible implementation of this hook by: - Adding a `triggerBeforeUserCreated` method to the `*API` object in `internal/api/hooks.go` - Adding a `triggerBeforeUserCreatedExternal` method to the `*API` object in `internal/api/hooks.go` - Updating callers of `signupNewUser` to first call `triggerBeforeUserCreated` in: - internal/api/anonymous.go - internal/api/external.go - internal/api/invite.go - internal/api/mail.go - internal/api/signup.go - Updating callers of `signupNewUser` to first call `triggerBeforeUserCreatedExternal` in: - internal/api/external.go - internal/api/samlacs.go - internal/api/token_oidc.go - internal/api/web3.go - Add end to end tests in `internal/api/e2e_test.go`
Pull Request Test Coverage Report for Build 15329359133Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Note: I'll improve test coverage if this implementation is approved. |
hf
approved these changes
May 23, 2025
Adding the e2e unit tests for the admin routes revealed a bug in the handling of invite type within adminGenerateLink.
Otherwise test ordering can change the test result.
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.
Hooks Round 5 - Option 2
This PR contains Option 1 for implementing the
before-user-created
hook. See #2032 for option 1.Summary
This commit explores one possible implementation of this hook by:
triggerBeforeUserCreated
method to the*API
object ininternal/api/hooks.go
triggerBeforeUserCreatedExternal
method to the*API
object ininternal/api/hooks.go
signupNewUser
to first calltriggerBeforeUserCreated
in:signupNewUser
to first calltriggerBeforeUserCreatedExternal
in:internal/api/e2e_test.go
This has the benefit of being outside the transaction, but is a bit more complex. I make a best-effort to ensure I only trigger before-user-created when the user doesn't exist, but being outside the transaction there is a small chance for duplicate calls or calls that happen when a user already has been created. The main thought here is that we can document this behavior and the tradeoff is worth the benefits.
Depends on
feat: hooks round 1 - prepare package structure
internal/hooks/v0hooks/v0http
->internal/hooks/hookshttp
8a398abinternal/hooks/v0hooks/v0pgfunc
->internal/hooks/hookspgfunc
8a398abinternal/e2e
for test setup in:internal/hooks/hookspgfunc
4d60288internal/hooks/v0hooks
4a7432bfeat: hooks round 2 - remove indirection and simplify error handling
internal/api
to:internal/hooks/v0hooks.Manager
instead ofinternal/hooks/hooks.Manager
aec5995internal/hooks/hooks.Manager
062da5dinternal/hooks/hookserrors
7e80afcinternal/hooks/hookserrors
ininternal/hooks/v0hooks
57744e8internal/hooks/v0hooks
with anEnabled
method 16cc4c9feat: hooks round 3 - begin adding the Before and After user created hooks
internal/conf
d5f5436BeforeUserCreated
andAfterUserCreated
toHookConfiguration
structEmailValidationBlockedMX
to restore 100% test coverageinternal/hooks/v0hooks
bd37fe2BeforeUserCreated
method tov0hooks.Manager
structAfterUserCreated
method tov0hooks.Manager
structinternal/e2e/e2ehooks
903e623HookCall
to record calls to hooksHook
struct to hold[]*HookCall
for a given hook nameHookRecorder
to hold oneHook
object per hook nameInstance
struct to hold thehttptest.Server
andHookRecorder
AfterUserCreated
method tov0hooks.Manager
structinternal/e2e
packagesinternal/hooks/v0hooks
829aec6internal/hooks/v0hooks
ca67be0BeforeUserCreated
andAfterUserCreated
methodsInvokeHook
internal/e2e/e2eapi
46c144ehttp.RoundTripper
t.Fatal
to userequire
feat: hooks round 4 - update tests to use require package
require
for tests in: f2b3600internal/e2e/...
internal/hooks/...