8000 feat: add admin API to create organizations by whoAbhishekSah · Pull Request #962 · raystack/frontier · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: add admin API to create organizations #962

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

Merged
merged 5 commits into from
Apr 23, 2025

Conversation

whoAbhishekSah
Copy link
Member
@whoAbhishekSah whoAbhishekSah commented Apr 22, 2025

Add Admin Organization Creation API

Summary

  • Add capability for platform administrators to create organizations with designated owners
  • Automatically create users for organization owners if they don't exist
  • Enforce proper validation and error handling for admin-created organizations

Changes

This PR introduces the ability for platform administrators to create organizations and designate ownership without requiring the owner to be an existing authenticated user. Key changes include:

  • Added AdminCreate method in the organization service that:

    • Validates email formats for organization owners
    • Creates users automatically if they don't exist
    • Handles organization name conflicts
    • Respects platform preferences for default organization state
  • Added unit tests for the new functionality

  • Updated authorization interceptors to secure the admin endpoint

  • Enhanced error handling for various edge cases

Example Usage

curl -X POST \
  https://frontier-api.example.com/v1beta1/admin/organizations \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer ADMIN_TOKEN' \
  -d '{
    "body": {
      "name": "acme-corp",
      "title": "ACME Corporation",
      "org_owner_email": "admin@acme-corp.com",
      "metadata": {
        "industry": "technology",
        "size": "enterprise"
      }
    }
  }'

Response:

{
  "organization": {
    "id": "org_2cDu8ZUPKFznvFh",
    "name": "acme-corp",
    "title": "ACME Corporation",
    "metadata": {
      "industry": "technology",
      "size": "enterprise"
    },
    "state": "enabled",
    "created_at": "2025-04-22T15:30:45.123Z",
    "updated_at": "2025-04-22T15:30:45.123Z"
  }
}

Testing

  • Added unit tests for the new organization service method
  • Added tests for API handler
  • Verified proper error handling for various scenarios

Related Issues

raystack/proton#404

8000
Copy link
vercel bot commented Apr 22, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
frontier ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 23, 2025 6:28am

@coveralls
Copy link
coveralls commented Apr 22, 2025
8000

Pull Request Test Coverage Report for Build 14611456311

Details

  • 0 of 91 (0.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 33.301%

Changes Missing Coverage Covered Lines Changed/Added Lines %
core/user/service.go 0 3 0.0%
pkg/server/interceptors/authorization.go 0 3 0.0%
internal/api/v1beta1/org.go 0 31 0.0%
core/organization/service.go 0 54 0.0%
Totals Coverage Status
Change from base Build 14572289088: -0.1%
Covered Lines: 9751
Relevant Lines: 29281

💛 - Coveralls

Copy link
Contributor
@Copilot Copilot AI left a 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 adds an admin API endpoint enabling platform administrators to create organizations and register organization owners automatically. Key changes include:

  • Adding a new gRPC method (AdminCreateOrganization) and corresponding HTTP gateway handlers.
  • Extending the organization service with an AdminCreate method and updating related mock implementations.
  • Enhancing authorization and error handling for admin organization creation.

Reviewed Changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
proto/v1beta1/admin_grpc.pb.go Added AdminCreateOrganization method and related server/client logic.
proto/v1beta1/admin.pb.gw.go Implemented HTTP gateway handlers for the new admin creation endpoint.
pkg/server/interceptors/authorization.go Added authorization for the new admin endpoint.
internal/api/v1beta1/org.go Introduced AdminCreateOrganization API handler with error handling.
internal/api/v1beta1/mocks/organization_service.go Added mocks for the AdminCreate method.
core/user/service.go Exposed IsValidEmail function as public.
core/organization/service.go Added AdminCreate method with user creation and org ownership assignment.
core/organization/mocks/user_service.go Extended user service mocks to support Create and GetByEmail.
Files not reviewed (2)
  • Makefile: Language not supported
  • proto/apidocs.swagger.yaml: Language not supported

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@rohilsurana rohilsurana merged commit e0f7bee into main Apr 23, 2025
7 checks passed
@rohilsurana rohilsurana deleted the org_create_by_superadmin branch April 23, 2025 06:34
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.

3 participants
0