-
Notifications
You must be signed in to change notification settings - Fork 14
Feat/operator logins #448
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
Open
julietteceb16
wants to merge
7
commits into
main
Choose a base branch
from
feat/operator-logins
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feat/operator logins #448
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ed9cd1a
Add OperatorOtp resource for generating email OTPs in operator portal
julietteceb16 d8dc3f5
Update cuenca-validations to version 2.1.48 and enhance OperatorLogin…
julietteceb16 6b87f5f
Add OperatorLoginResponse and OperatorLoginSessionResponse models to …
julietteceb16 2115090
Update cuenca-validations dependency to 2.1.47
julietteceb16 93219b5
Update cuenca-validations dependency to 2.1.47 in setup.py
julietteceb16 b1ad3fd
Update cuenca-validations to 2.1.48.dev2 and add OperatorToken resource
julietteceb16 d9d640d
Update version to 2.2.5.dev0 to indicate a development release
julietteceb16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 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 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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import datetime as dt | ||
| from typing import Annotated, ClassVar | ||
|
|
||
| from cuenca_validations.types import LogConfig | ||
| from pydantic import ConfigDict | ||
|
|
||
| from ..http import Session, session as global_session | ||
| from .base import Creatable | ||
|
|
||
|
|
||
| class OperatorOtp(Creatable): | ||
| """Email OTP challenge for authorized actions in operator portal. | ||
|
|
||
| Requires an active operator Session (from completed OperatorLogin). | ||
| ``POST /operator-otps`` creates an email OTP challenge and emails | ||
| a 6-digit code to the operator. Use the code with the ``X-Cuenca-OTP`` | ||
| header in protected endpoints. | ||
|
|
||
| Expires in 5 minutes. | ||
| """ | ||
|
|
||
| _resource: ClassVar = 'operator-otps' | ||
|
|
||
| id: Annotated[str, LogConfig(masked=True, unmasked_chars_length=4)] | ||
| expires_at: dt.datetime | ||
|
|
||
| model_config = ConfigDict( | ||
| json_schema_extra={ | ||
| 'example': { | ||
| 'id': 'OCWqY5cvkISJOxHyEKjAKf8w', | ||
| 'expires_at': '2026-09-25T12:34:56Z', | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| @classmethod | ||
| def create(cls, *, session: Session = global_session) -> 'OperatorOtp': | ||
| """Create an email OTP challenge for the current operator Session. | ||
|
|
||
| Requires: X-Cuenca-SessionId header set (from OperatorLogin.update). | ||
| A 6-digit code is sent via email to the operator's registered address. | ||
|
|
||
| Returns: OperatorOtp with challenge id and expiration timestamp. | ||
| """ | ||
| return cls._create(session=session) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import datetime as dt | ||
| from typing import Annotated, ClassVar, Optional, Union | ||
|
|
||
| from cuenca_validations.types import LogConfig, OperatorRole | ||
| from pydantic import ConfigDict | ||
|
|
||
| from ..http import Session, session as global_session | ||
| from .base import Creatable | ||
|
|
||
|
|
||
| class OperatorToken(Creatable): | ||
| """One-time invitation token to set an operator password. | ||
|
|
||
| ``POST /operator_tokens`` creates the invite in Authed and returns the | ||
| plaintext ``token`` once (for the magic-link email). Does not send email. | ||
| """ | ||
|
|
||
| _resource: ClassVar = 'operator_tokens' | ||
|
|
||
| id: str | ||
| operator_id: str | ||
| email: str | ||
| legal_person_id: str | ||
| role: Union[OperatorRole, str] | ||
| token: Annotated[str, LogConfig(masked=True, unmasked_chars_length=4)] | ||
| created_at: Optional[dt.datetime] = None | ||
| expires_at: Optional[dt.datetime] = None | ||
| used_at: Optional[dt.datetime] = None | ||
|
|
||
| model_config = ConfigDict( | ||
| json_schema_extra={ | ||
| 'example': { | ||
| 'id': 'OTWqY5cvkISJOxHyEKjAKf8w', | ||
| 'operator_id': 'OPWqY5cvkISJOxHyEKjAKf8w', | ||
| 'email': 'maria.lopez@aceros.com', | ||
| 'legal_person_id': 'USWqY5cvkISJOxHyEKjAKf8w', | ||
| 'role': 'operator', | ||
| 'token': 'plaintext-invite-secret', | ||
| 'expires_at': '2026-09-24T21:30:56Z', | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| @classmethod | ||
| def create( | ||
| cls, | ||
| operator_id: str, | ||
| email: str, | ||
| legal_person_id: str, | ||
| role: Union[OperatorRole, str], | ||
| *, | ||
| session: Session = global_session, | ||
| ) -> 'OperatorToken': | ||
| role_value = role.value if isinstance(role, OperatorRole) else role | ||
| return cls._create( | ||
| session=session, | ||
| operator_id=operator_id, | ||
| email=email, | ||
| legal_person_id=legal_person_id, | ||
| role=role_value, | ||
| ) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| __version__ = '2.2.5' | ||
| __version__ = '2.2.5.dev0' | ||
| CLIENT_VERSION = __version__ | ||
| API_VERSION = '2020-03-19' |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| requests==2.32.3 | ||
| cuenca-validations==2.1.46 | ||
| cuenca-validations==2.1.48.dev2 | ||
| pydantic-extra-types==2.10.2 |
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 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Validate the session response before setting the session header.
If PATCH returns a successful response with the challenge shape shown in
tests/resources/test_operator_logins.py,cls(**resp)accepts it becauseroleandlegal_person_idare optional. The method then stores the challenge’sOLID inX-Cuenca-SessionIdand reports completion. Parse the PATCH response with a session-specific model that requires the session fields and validates the session ID before changing the header.🤖 Prompt for AI Agents