-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add SecretShare model and migration (Phase 3 foundation) #183
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
Conversation
- Create secret_shares table with XOR constraint (user_id OR role_id) - Implement SecretShare model with UUID, relationships, and scopes - Add Secret.shares() relationship and userHasPermission() method - Permission hierarchy: admin > write > read - Optional expiration support via expires_at timestamp - Add active() scope for filtering non-expired shares - Migration tests verify schema integrity (3 tests) - Model tests cover relationships, scopes, expiration (10 tests) - All 355 tests passing (1116 assertions) Refs: #182 (Phase 3: Secret Sharing & Access Control)
💡 Tip: Consider Using Draft PRsBenefits of opening PRs as drafts initially:
How to convert:
This is just a friendly reminder - feel free to continue as is! 😊 |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Pull Request Overview
This PR establishes the database foundation for Phase 3: Secret Sharing & Access Control by introducing a secret_shares table, model, and relationships. The implementation enables fine-grained permission management where secrets can be shared with individual users or roles with read/write/admin permissions and optional expiration.
Key Changes:
- Database schema with XOR constraint ensuring shares target either a user OR a role
SecretSharemodel with UUID keys, temporal filtering, and relationship definitionsSecretmodel extensions adding share relationship and permission checking logic
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
database/migrations/2025_11_16_164313_create_secret_shares_table.php |
Creates secret_shares table with UUID keys, XOR constraint, permission enum, and comprehensive indexes |
app/Models/SecretShare.php |
Defines SecretShare model with relationships, active scope for non-expired shares, and expiration accessor |
app/Models/Secret.php |
Adds shares() relationship and userHasPermission() method for authorization checks with permission hierarchy |
tests/Feature/Migrations/CreateSecretSharesTableTest.php |
Migration tests validating schema structure, indexes, and unique constraints |
tests/Feature/Models/SecretShareTest.php |
Model tests covering relationships, UUID keys, scopes, and expiration logic |
CHANGELOG.md |
Documents new secret sharing foundation features |
- Add missing 'use Illuminate\Support\Facades\DB;' import in migration - Add explicit type declaration for $query parameter in scopeActive() - Follows Laravel conventions and codebase patterns Addresses Copilot review comments
- Fix phpdoc alignment in SecretShare model - Fix PHPDoc tags in Secret model - Ensure PSR-12 compliance Fixes CI/CD pipeline
Overview
Implements the foundation for Phase 3: Secret Sharing & Access Control (#182) by adding database schema, models, and relationships for fine-grained permission management.
Changes
Database Schema
secret_sharestable with UUID primary keyread,write,admin(hierarchical)expires_attimestampsecret_id,user_id,role_id,expires_atModels
✅
SecretSharemodel with UUID, relationships, and scopessecret()- BelongsTo Secretuser()- BelongsTo User (nullable, XOR with role)role()- BelongsTo Role (nullable, XOR with user)granter()- BelongsTo User (who granted access)active()- Scope for non-expired sharesis_expired- Accessor for expiration logic✅
Secretmodel extensionsshares()- HasMany SecretShare relationshipuserHasPermission($user, $permission)- Authorization helper with hierarchyTests
Testing
Next Steps (Separate PRs)
This PR provides the foundation. Follow-up PRs will add:
Checklist
Related