Loading
feat(data-access): allow a caller to delete their own grant on the organisation resource
Summary
dataaccess/internal/relationships/authz/authz.gointroduces a newAuthorizer.AuthorizeDeletemethod, distinct fromAuthorizeWriteused by the create path, sharing a privateauthorizecore- Allows a non-owner to delete their own grant on the organisation resource only when all batch objects are the organisation resource and all key subject identities match the caller's token identity (same origin/origin_id/local_id comparison used by
ReadRelationships) - Defensive identity matching is verified inside the authorization logic, not relying on upstream validation
WriteRelationshipsremains unchanged — callers still cannot grant themselves roles on the organisation resource- Validation helper in
dataaccess/update/delete_relationships.gowas renamed and simplified; test doubles across theupdatepackage updated docs/relationships-api.mdupdated to document the exception- No database schema or proto changes required — pure in-memory authorization logic
Closes #99 (closed). See gitlab-org/gitlab!250806 (comment 3763110409) for context.
Testing
- Unit tests in
authz_test.goverify the self-delete path does not access the database (empty fake DB convention) - Integration tests in
authz_integration_test.goverify the exception bypasses grant/principal resolution - Integration tests in
delete_relationships_integration_test.gocover end-to-end throughDeleteRelationshipsagainst both Postgres and YugabyteDB - Scenarios covered: self-delete allowed for non-owner, deletion of another's grant still denied, organisation owner behavior unchanged, batch mixing organisation resource with other objects still denied even if self-targeted