Skip to content

feat: Add generic permission API (36 → 4 methods)#71

Merged
vieiralucas merged 1 commit intomainfrom
feat/grpc-consolidation
Jan 28, 2026
Merged

feat: Add generic permission API (36 → 4 methods)#71
vieiralucas merged 1 commit intomainfrom
feat/grpc-consolidation

Conversation

@vieiralucas
Copy link
Collaborator

@vieiralucas vieiralucas commented Jan 28, 2026

Summary

This PR implements the gRPC API consolidation from the RFC at docs/rfcs/grpc-consolidation.md.

Primary change: Generic permission methods (36 → 4)

Replace 36 permission methods with 4 generic ones using ResourceType/ActorType enums:

  • New enums:

    • ResourceType: WORKSPACE, PROJECT, ENVIRONMENT
    • ActorType: PRINCIPAL, GROUP, USER
  • New message types:

    • ResourceRef: Identifies a specific resource (workspace/project/environment)
    • ActorRef: Identifies who is being granted permission (principal/group/user)
  • New methods:

    • SetPermission - Generic permission setter
    • GetPermission - Generic permission getter
    • ListPermissions - List all permissions on a resource
    • RemovePermission - Generic permission remover
  • Deprecated methods (still work, marked for removal in v1.0):

    • All 12 principal permission methods (Set/Get/List/Remove × Workspace/Project/Environment)
    • All 12 group permission methods
    • All 12 user permission methods

Secondary changes

  • Remove CountAuditLogs: Redundant - use ListAuditLogs response's total_count field instead
  • Add UpsertOrganizationMember: Merges AddOrganizationMember + UpdateOrganizationMemberRole into one idempotent call
  • Mark deprecated: AddOrganizationMember and UpdateOrganizationMemberRole

Implementation details

  • New generic_permissions.rs handler with validation and dispatch logic
  • Updated CLI cmd_audit_count to use ListAuditLogs with limit=0
  • Updated server tests to use ListAuditLogs instead of CountAuditLogs

Testing

  • ✅ All 607 server unit tests pass
  • ✅ E2E tests pass (audit, counts, demo)
  • ✅ Clippy passes
  • ⏭️ Email verification tests skipped (need MailHog)
  • ⏭️ PostgreSQL tests skipped (need running database)

Breaking changes

None - This is fully backward compatible:

  • All deprecated methods still work
  • Old methods call the same underlying storage layer
  • Deprecation path: Old methods will be removed in v1.0

Migration path for clients

Before (old API):

client.set_user_project_permission(SetUserProjectPermissionRequest {
    workspace_name: "acme".into(),
    project_name: "api".into(),
    user_email: "alice@example.com".into(),
    role: Role::Write,
})

After (new API):

client.set_permission(SetPermissionRequest {
    resource: Some(ResourceRef {
        r#type: ResourceType::ResourceProject as i32,
        workspace_name: "acme".into(),
        project_name: Some("api".into()),
        environment_name: None,
    }),
    actor: Some(ActorRef {
        r#type: ActorType::ActorUser as i32,
        actor: Some(actor_ref::Actor::UserEmail("alice@example.com".into())),
    }),
    role: Role::Write as i32,
})

Related

  • RFC: /docs/rfcs/grpc-consolidation.md

Summary by cubic

Consolidates the gRPC permission API from 36 specific methods to 4 generic ones using ResourceType/ActorType, and removes the redundant CountAuditLogs in favor of ListAuditLogs total_count. Backward compatible; deprecated endpoints will be removed in v1.0.

  • New Features

    • Add SetPermission, GetPermission, ListPermissions, RemovePermission.
    • Introduce ResourceRef/ActorRef with ResourceType (WORKSPACE, PROJECT, ENVIRONMENT) and ActorType (PRINCIPAL, GROUP, USER).
    • Add UpsertOrganizationMember (idempotent add or role update).
    • Deprecate all 36 old permission RPCs and AddOrganizationMember/UpdateOrganizationMemberRole.
  • Migration

    • For counts, call ListAuditLogs with limit=0 and read total_count.
    • For permissions, use the generic methods with ResourceRef and ActorRef.
    • Prefer UpsertOrganizationMember over the older add/update role calls.

Written for commit 6bd6fb4. Summary will update on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 7 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

This PR implements the gRPC API consolidation from the RFC:

- Add ResourceType (WORKSPACE, PROJECT, ENVIRONMENT) and ActorType (PRINCIPAL, GROUP, USER) enums
- Add ResourceRef and ActorRef message types for flexible targeting
- Add 4 new generic methods: SetPermission, GetPermission, ListPermissions, RemovePermission
- Mark old 36 permission methods as deprecated (backward compatible)

- Remove redundant CountAuditLogs (use ListAuditLogs response.total_count)
- Add UpsertOrganizationMember (merges Add + UpdateRole)
- Mark AddOrganizationMember and UpdateOrganizationMemberRole as deprecated

- New generic_permissions.rs handler with validation and dispatch logic
- Updated CLI to use ListAuditLogs for count operations
- All 607 server tests pass
- E2E tests pass (except those requiring external services)

Breaking changes: None - all old methods still work
Deprecation path: Old methods will be removed in v1.0
@vieiralucas vieiralucas force-pushed the feat/grpc-consolidation branch from 68bd190 to 6bd6fb4 Compare January 28, 2026 09:52
@vieiralucas vieiralucas merged commit ff8638c into main Jan 28, 2026
3 of 7 checks passed
@vieiralucas vieiralucas deleted the feat/grpc-consolidation branch January 28, 2026 09:52
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.

1 participant

Comments