-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: pass context to interface methods
- Loading branch information
Showing
6 changed files
with
36 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,35 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from ckan import model | ||
from ckan.plugins.interfaces import Interface | ||
|
||
|
||
class ILetMeIn(Interface): | ||
"""Interface to do something on user login via OTL link""" | ||
|
||
def manage_user(self, user: model.User) -> model.User: | ||
def manage_user(self, user: model.User, context: dict[str, Any]) -> model.User: | ||
"""Accept a user object that will be logged. Only Active user could be | ||
logged in, so here we could implement user re-activation, for example. | ||
The user is always exists, otherwise we are not getting here. | ||
This happend before we are checking for user state and actual login | ||
You can use context to pass some information further, for example, if you | ||
did something to user in `manage_user`, you can pass this information | ||
to `before_otl_login` or `after_otl_login` funcs. | ||
Must return a user object | ||
""" | ||
return user | ||
|
||
def before_otl_login(self, user: model.User) -> None: | ||
def before_otl_login(self, user: model.User, context: dict[str, Any]) -> None: | ||
"""Allows to do something before we are logging in a user. | ||
Happens after all checks and `manage_user` method.""" | ||
pass | ||
|
||
def after_otl_login(self, user: model.User) -> None: | ||
def after_otl_login(self, user: model.User, context: dict[str, Any]) -> None: | ||
"""Allows to do something after we logged in a user.""" | ||
pass |
This file contains 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 file contains 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 file contains 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 file contains 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 file contains 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