Commit Graph

48 Commits

Author SHA1 Message Date
Fabian @ Blax Software 190c500d86 fix: align schema with HasUuids design + add reusable MorphAliasRegistry
The package's models (Permission, PermissionMember, Role, RoleMember,
Access, RequiredAccess) all use HasUuids but the published create
migrations created bigint columns. Every insert blew up in production
with 'Incorrect integer value: <uuid> for column id'.

Migrations
- create_blax_role_tables: uuid PK + uuidMorphs throughout
- create_blax_access_table: uuid PK + uuidMorphs/nullableUuidMorphs
- create_required_accesses_table: uuid PK + uuidMorphs
- add_source_to_accesses_table: nullableUuidMorphs

Two upgrade migrations convert in-place for hosts with existing data:
- 2026_04_29_000001 fixes required_accesses (idempotent, drops empty
  table or leaves correct schema alone)
- 2026_04_29_000002 fixes the rest (permissions, permission_members,
  permission_usages, roles, role_members, accesses) by adding staging
  uuid columns, generating UUIDs per row, propagating into FK columns,
  swapping in place, and rebuilding FK constraints. MySQL-only;
  SQLite hosts get the correct schema directly from the create
  migration. Idempotent (no-op on already-uuid schemas).

Models / traits
- Permission/PermissionMember restored to HasUuids (the schema fix
  removes the conflict with the bigint id columns)
- RoleMember constructor was looking up the wrong config key
  (role_members instead of role_member) and falling through to a
  non-pluralised parent::getTable()
- HasRoles/HasPermissions now treat UUID strings as ids; previously
  they were misinterpreted as role/permission names, so passing
  $role->id to assignRole created a new role keyed by the UUID
- extendOrAddRoleByOrigin no longer json_encodes the context array;
  the RoleMember 'context' cast handles it (it was double-encoding)

Reusable infrastructure
- MorphAliasRegistry: central alias <-> FQCN map with custom
  per-class alias and name resolvers. Auto-bound as a singleton in
  RolesServiceProvider; hosts register their own (alias, FQCN) pairs
- HasRequiredAccess gained addRequiredAccessByAlias /
  removeRequiredAccessByAlias / requiredAccessAdminPayload helpers
- RequiredAccess::toAdminArray serializes a link via the registry

Test fixtures
- Manual DB::table()->insert() pivot rows now pass an explicit id
  since pivot inserts don't go through HasUuids
- All 162 package tests passing

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-29 11:48:51 +02:00
Fabian @ Blax Software 2ca17ba914 feat: add HasRequiredAccess trait for OR-combined entity dependencies
Introduces a generic "Required Access" mechanism: any model using
HasRequiredAccess can list other entities as required-access targets;
if the requesting entity has access to ANY of them — direct, role,
or permission — the holder is considered unlocked. Sits alongside
Required Roles / Permissions and is OR-combined with them.

The unlock check resolves in a single EXISTS query that joins
required_accesses with accesses, so cost stays O(1) regardless of
target count.

20 new unit tests cover relations, sync semantics, expiry handling,
isolation between holders, and the constant-cost query property.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-27 12:35:09 +02:00
Fabian @ Blax Software 20d94caa33 feat: Enhance access management with source tracking and revocation
- Added source_id and source_type fields to the Access model to track the origin of access grants.
- Implemented source relationship in the Access model for better access management.
- Introduced revokeBySource method to delete access entries based on their source.
- Updated grantAccess and revokeAccess methods to handle source parameters for more granular control.
- Added RevokesAccessOnDelete trait to automatically revoke access when the source model is deleted.
- Created SourceAccessesRevoked event to notify when access grants are revoked due to source deletion.
- Enhanced tests to cover new source-related functionality and ensure proper behavior during access management.
- Updated RolesServiceProvider to support auto-loading migrations based on configuration.
- Added migration files for creating roles and access tables, including source columns for existing installations.
2026-04-26 09:54:57 +02:00
Fabian @ Blax Software 01cff931bc feat: switch models to UUIDs and use MorphPivot for role/permission members 2026-04-17 11:03:02 +02:00
Fabian @ Blax Software 46c01f1b06 feat: add Laravel 13 support 2026-04-16 07:49:51 +02:00
Fabian @ Blax Software b780d154f2 I context logic & tests 2026-03-31 18:56:47 +02:00
Fabian @ Blax Software 2f19523dcf I extendByHourse method 2026-03-09 13:17:02 +01:00
Fabian @ Blax Software 2ce9893e81 BF has access 2026-02-28 13:05:01 +01:00
Fabian @ Blax Software 2d3f5ec00e A ccess 2026-02-24 12:07:32 +01:00
Fabian @ Blax Software 7878069c0b AM access capabilities 2026-02-23 11:16:27 +01:00
Fabian @ Blax Software 477405c6ec BF config 2026-02-10 15:28:39 +01:00
Fabian @ Blax Software 62484f9307 BF joints 2026-02-10 15:22:26 +01:00
a6a2f5842 5a843191b9 BF extend or add role 2025-11-27 12:15:00 +01:00
a6a2f5842 f75e90ac15 I has roles 2025-10-31 11:12:00 +01:00
a6a2f5842 241f5ae53b BFI has roles 2025-10-31 11:00:52 +01:00
a6a2f5842 a854e85388 I role expiration extension 2025-10-30 11:23:53 +01:00
a6a2f5842 84d81863ed I allow count limit on assign role 2025-09-21 11:19:12 +02:00
a6a2f5842 2d35fab83d BF default role slug 2025-09-02 11:13:33 +02:00
a6a2f5842 4488b7821f A role expiration 2025-07-31 17:03:41 +02:00
a6a2f5842 925b5f846f BF relation 2025-07-10 10:31:51 +02:00
a6a2f5842 ebc23249c4 I has permissions trait 2025-07-10 10:29:53 +02:00
a6a2f5842 5f8c190120 I hasRole trait 2025-06-24 09:38:55 +02:00
a6a2f5842 4d1f57c4a1 I hasRole trait 2025-06-24 09:30:56 +02:00
a6a2f5842 87d2429630 I hasPermissions 2025-06-19 15:08:49 +02:00
a6a2f5842 7e522f222a I hasPermissions 2025-06-19 14:52:09 +02:00
a6a2f5842 dd2ac01cdb IBF hasRoles 2025-06-19 14:45:06 +02:00
a6a2f5842 d9bdc10f78 RMI permissions table/structure & has permission trait 2025-06-19 13:36:10 +02:00
a6a2f5842 79e5c832db I syncRoles & hasRole 2025-06-19 11:34:12 +02:00
a6a2f5842 20162a4931 I hasRole trait 2025-06-18 19:02:51 +02:00
a6a2f5842 93e952a271 I hasRole trait 2025-06-18 18:52:27 +02:00
a6a2f5842 4d2252d360 I hasRole trait 2025-06-18 18:49:14 +02:00
a6a2f5842 318e6a90ac A testing 2025-06-17 17:53:26 +02:00
a6a2f5842 578b735f4f C removed unused requirement 2025-06-16 09:50:19 +02:00
a6a2f5842 cf337a8bb6 A traits, I fields 2025-06-16 09:49:36 +02:00
a6a2f5842 e65ea42586 C composer script 2025-06-16 08:38:50 +02:00
a6a2f5842 d3f88b30bb R revert migration offering 2025-06-16 08:34:58 +02:00
a6a2f5842 ed457199c1 R publishing, BF namespace 2025-06-16 08:31:14 +02:00
a6a2f5842 5e7510e026 AC migration tables names 2025-06-16 08:04:18 +02:00
a6a2f5842 add96a6609 BF wrong config path 2025-06-16 08:01:11 +02:00
a6a2f5842 85b7e689db A register config 2025-06-16 07:57:01 +02:00
a6a2f5842 f7e090ce26 A migration resolver 2025-06-16 07:42:57 +02:00
a6a2f5842 006b3ead08 BF wrong name 2025-06-16 07:40:14 +02:00
a6a2f5842 84f7159436 I discover provider 2025-06-16 07:39:39 +02:00
a6a2f5842 7ddd3491e1 R renamed config & files 2025-06-16 07:37:35 +02:00
a6a2f5842 19f4b8a220 A composer autofind 2025-06-16 07:12:26 +02:00
a6a2f5842 1fb57141bc I basic structure 2025-06-15 18:29:50 +02:00
a6a2f5842 7cfc7749cc A more files & structure 2025-06-15 11:56:28 +02:00
Alexander Blasl e4a6824dcb Init 2025-06-11 15:44:39 +02:00