Skip to content

Conversation

@bencap
Copy link
Collaborator

@bencap bencap commented Dec 4, 2025

This pull request introduces a new, modular permission system for MaveDB entities. The new system centralizes permission checks, provides clear separation by entity type, and offers a unified API for permission evaluation and enforcement. It adds comprehensive documentation, consistent logging, and improved error handling for permission-related operations.

Key changes include:

Core Permission Framework:

  • Introduced a new entry point for permission checks with has_permission and assert_permission functions in src/mavedb/lib/permissions/core.py, which dispatch requests to entity-specific permission handlers and raise exceptions on denial.
  • Refactored to a centralized Action enum in src/mavedb/lib/permissions/actions.py to standardize supported permission actions across all entity types.
  • Refactored to a PermissionResponse model in src/mavedb/lib/permissions/models.py to encapsulate permission results, HTTP status codes, and messages, with integrated logging.
  • Refactored the custom PermissionException for consistent exception handling when permission is denied.
  • Added a documented package initializer (__init__.py) to expose the main permission API and provide usage examples.

Entity-Specific Permission Handlers:

  • Refactored existing permission logic into entity-specific handlers, which are invoked by the core handler.

Test Updates

  • Added comprehensive tests for the new permissions module, which is now tested directly.

These changes lay the foundation for a robust and extensible permission system, making permission checks more maintainable and consistent across the codebase.

bencap added 13 commits December 3, 2025 10:51
…ufficient permissions when user data is missing
…nd testability

- Refactored the `permissions.py` file into a permissions module
- Entities now have their own has_permission function, and the core `has_permission` function acts as a dispatcher. This structure significantly improves readability and testability of the permissions boundary. It also greatly improves its extensibility for future permissions updates.
- Added comprehensive tests for all implemented permissions. Tests are modular and can be easily added to and changed.
…ation permissions

When fetching score sets via this method, score calibration relationships were being unset in an unsafe manner. Because of this, functions in this router were refactored to access score sets directly and load the score set contributors directly when loading calibrations.
…stency and duplication

- Added unified deny action handler for reduced duplication
- Removed now unused deny action tests from score calibration, score set, and user permission tests.
- Updated error messages in various tests to consistently reference the entity type (e.g., "ScoreCalibration", "ScoreSet", "User") in the detail messages.
- Adjusted test assertions to ensure they check for the correct error messages when permissions are insufficient or entities are not found.
- Renamed tests to clarify expected outcomes, particularly for contributor permissions.
@bencap bencap requested a review from sallybg December 4, 2025 22:24
@bencap bencap linked an issue Dec 4, 2025 that may be closed by this pull request
@bencap bencap force-pushed the tests/bencap/543/permissions-module-direct-testing branch 2 times, most recently from 52d18b5 to 3359a1d Compare December 5, 2025 01:47
@bencap bencap force-pushed the tests/bencap/543/permissions-module-direct-testing branch from 3359a1d to d4c685c Compare December 5, 2025 18:40
Copy link
Collaborator

@jstone-dev jstone-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look great to me.

One small comment: In exception messages that may be user-facing, I'm not sure I would use model class names like ScoreSet and Experiment.

Copy link
Collaborator

@jstone-dev jstone-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look great to me.

One small comment: In exception messages that may be user-facing, I'm not sure I would use model class names like ScoreSet and Experiment.

@bencap bencap merged commit 326ddb0 into release-2025.5.1 Dec 16, 2025
6 checks passed
@bencap bencap deleted the tests/bencap/543/permissions-module-direct-testing branch December 16, 2025 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Full (and Direct) Test Coverage for the Permissions Library Module

3 participants