Skip to content

Conversation

@jlegrand62
Copy link
Member

Summary of Changes

  • Improved REST API functionality

    • Added requires_jwt decorator for enhanced token validation.
    • Introduced size, base64, and coords query parameters for image, mesh, and point cloud endpoints.
    • Propagated **kwargs across REST API methods, ensuring better parameter handling and user context.
    • Updated session headers to include JSON Web Token (JWT) after login.
  • Refined RBAC logic and documentation

    • Updated permissions for can_modify_scan_owner and removed outdated methods.
    • Improved docstring consistency and clarified roles and permissions.
  • Enhanced metadata handling

    • Improved logging for missing metadata values (None), added exclusive locks for updates to scans, filesets, and metadata.
    • Enriched error messaging with resource-specific details.
    • Added stricter permission checks and improved operation consistency.
  • General improvements

    • Standardized terminology from "JWT" to "JSON Web Token."
    • Added type hints and refined docstrings across multiple files for clarity.
    • Included pybase64 for 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.

- 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.
@jlegrand62 jlegrand62 self-assigned this Jan 29, 2026
@jlegrand62 jlegrand62 added the bug Something isn't working label Jan 29, 2026
- 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`.
@openhands-ai
Copy link

openhands-ai bot commented Jan 29, 2026

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • CI UnitTests

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #82 at branch `hotfix/rest_api`

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants