-
Notifications
You must be signed in to change notification settings - Fork 2
Update REST API, RBAC, and metadata handling for improved security and clarity #82
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
jlegrand62
wants to merge
19
commits into
dev
Choose a base branch
from
hotfix/rest_api
base: dev
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.
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
- Update `session.headers` to include Authorization header with JWT token upon successful login.
- Added `size` and `base64` query parameters for image endpoints, allowing thumbnail, large, or original images with optional Base64 JSON output. - Extended point cloud and ground‑truth endpoints with `size` (preview/orig/voxel) and `coords` flags to return point coordinates as JSON. - Added mesh endpoint support for `coords` flag to expose vertices and triangles in JSON. - Updated MIME type handling with `mimetypes` and incorporated `pybase64` for Base64 encoding. - Refactored documentation and cleaned up deprecated comments.
- Include `pybase64` in `src/server/pyproject.toml` to support Base64 image encoding.
- Update POST handler signatures to accept `**kwargs` and forward them to underlying DB operations. - Pass `**kwargs` to `scan.set_metadata`, `scan.create_fileset`, `fileset.create_file`, `fileset.delete_file`, and `file.set_metadata` calls. - Adjust method definitions for file‑level and scan‑level metadata updates to propagate `**kwargs` to the appropriate underlying functions.
- Implement `has_role` to verify a user’s role membership - Add explanatory docstring to `get_guest_user` - Introduce `can_create_user` that checks the `MANAGE_USERS` permission for user creation privileges
- Update comment to correctly describe username availability check instead of “login” in user creation logic.
- Always set owner, timestamps, and creator on new scans/filesets - Add authentication context and permission checks to user‑creation, group deletion, and metadata modification - Enrich error messages with resource identifiers - Wrap all metadata updates, file creations, deletions, and imports in exclusive locks - Log detailed operation summaries including user and resource IDs - Propagate **kwargs to REST‑API helpers for proper user lookup and permissions - Update logging and error handling to be consistent across scan, fileset, and file APIs
- Standardize docstring formatting for all methods in `rbac.py`. - Remove redundant and inconsistent comments for better clarity. - Reorganize `can_create_group` logic to align with `can_manage_groups` permission. - Simplify admin role checks in group management functions (`can_add_to_group`, `can_delete_group`). - Ensure `create_group` uses `can_manage_groups` for permission validation. - Update role/permission summaries to include additional context like ownership and shared groups.
- Standardize references throughout `session.py` from `JWT` to `JSON Web Token` for clarity. - Update variable names, comments, log messages, and docstrings to reflect the terminology change. - Refine function signatures and parameters, replacing `jwt_token` with `token` for consistency. - Correct minor grammatical inconsistencies in comments for enhanced readability and uniformity.
…EST API methods - Add `requires_jwt` decorator to `post` methods for enhanced security and token validation. - Update method signatures in `rest_api.py` to include `**kwargs` and propagate them to relevant database operations (`create_user`, `logout`, `get_user_data`). - Replace `jwt_token` with `token` in function calls for consistency. - Refactor logout logic to rely on `kwargs` and use `db.logout` for session invalidation. - Clean up redundant comments and improve clarity in error handling and docstrings.
- Updated `can_modify_scan_owner` to require ``Permission.MANAGE_USERS`` instead of admin‑only. - Removed legacy `can_access_scan_by_owner` method that lacked group sharing support. - Fixed grammar and clarified docstrings for `can_modify_scan_sharing`, `can_modify_scan`, and related methods.
- In `src/commons/plantdb/commons/fsdb/metadata.py`, the `metadata` helper now logs a warning when a key `data` is set to `None` instead of raising an `IOError`.
- The warning message is generated by `logger.warning(f"Metadata key '{data}' was set to `None`!")`, preserving the operation flow while alerting developers to the missing value.
- Import `Any` from `typing` and add it to relevant type annotations. - Annotate all metadata loader and storer helpers with explicit return types. - Update the warning logic for `None` values remains unchanged, but the function signatures now reflect their return types.
- Introduced improved error messaging with resource-specific identifiers for better debugging. - Updated permission validation logic for scan creation and deletion, ensuring stricter checks on user roles. - Made docstrings consistent with refined terminology and updated type hints across core functions. - Improved locking mechanisms by wrapping metadata updates, scans, and fileset operations in exclusive locks. - Refactored RBAC methods for better clarity and alignment with security best practices.
- In **`src/server/plantdb/server/rest_api.py`** replace all `plantdb_url()` calls in docstring examples with `plantdb_url('localhost', port=5000)`.
- Add a login request example that obtains an `access_token` and stores it in a `token` variable.
- Show how to include `headers={'Authorization': 'Bearer ' + token}` in the file upload example.
- Update calls that previously used `self.db.get_scan(scan_id)` and `file.write_raw(...)` to pass `**kwargs` (e.g., `self.db.get_scan(scan_id, **kwargs)` and `file.write_raw(..., **kwargs)`).
- Adjust related example URLs for metadata retrieval and updates to use the new host/port form.
- Introduced `rank` property on `Role` to expose a numeric hierarchy (READER=1, CONTRIBUTOR=2, ADMIN=3) - Added `can_assign(target_role)` method to determine if a role can assign another role based on rank comparison - Updated docstrings in `src/commons/plantdb/commons/auth/models.py` with usage examples for `rank` and `can_assign`
- Add tests for `Permission` constants and string values - Add tests for `Role` constants, permissions set, rank ordering, and `can_assign` logic - Add tests for `User` serialization (`to_dict`, `from_dict`), JSON conversion, lock state checks, and failed‑attempt tracking - Add tests for `Group` add/remove user functionality, duplicate prevention, and `has_user` checks - Create new test file `src/commons/tests/test_auth_models.py` containing all tests above.
- Delete extensive test suite for `Permission`, `Role`, `User`, and `Group` that was previously in `src/commons/tests/test_auth.py`. - Consolidate all auth model tests into `src/commons/tests/test_auth_models.py`.
|
Looks like there are a few issues preventing this PR from being merged!
If you'd like me to help, just leave a comment, like Feel free to include any additional details that might help me get this PR into a better state. You can manage your notification settings |
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.
Summary of Changes
Improved REST API functionality
requires_jwtdecorator for enhanced token validation.size,base64, andcoordsquery parameters for image, mesh, and point cloud endpoints.**kwargsacross REST API methods, ensuring better parameter handling and user context.Refined RBAC logic and documentation
can_modify_scan_ownerand removed outdated methods.Enhanced metadata handling
None), added exclusive locks for updates to scans, filesets, and metadata.General improvements
pybase64for Base64 encoding in server dependencies.Additional Notes
These changes aim to enhance security, improve clarity, and standardize functionality across the codebase. Future work could further extend testing and optimize specific API operations.