Skip to content

Comments

Add cross-organization support to user query functions#221

Open
bclermont wants to merge 2 commits intocasdoor:masterfrom
transform-ia:feat/cross-org-user-queries
Open

Add cross-organization support to user query functions#221
bclermont wants to merge 2 commits intocasdoor:masterfrom
transform-ia:feat/cross-org-user-queries

Conversation

@bclermont
Copy link

Summary

Enable user queries across multiple organizations in multi-tenant Casdoor deployments while maintaining backward compatibility with existing single-organization usage.

Problem

The SDK client is initialized with a single organization and automatically prepends it to all user queries. This prevents querying users from other organizations in multi-tenant Casdoor instances.

Before:

  • SDK configured with org="built-in"
  • Query: GetUser("robotinfra/mcp-test-user")
  • SDK constructs: "built-in/robotinfra/mcp-test-user"

Solution

GetUser

Auto-detects org-prefixed names in "org/user" format:

  • If name contains /, uses as-is (explicit organization)
  • Otherwise, prepends configured organization (backward compatible)

Other Query Functions

Added optional variadic organization ...string parameter:

  • GetUsers(organization ...string)
  • GetUserByEmail(email string, organization ...string)
  • GetUserByPhone(phone string, organization ...string)
  • GetSortedUsers(sorter string, limit int, organization ...string)

Backward Compatibility

✅ All existing code continues to work without modification
✅ Optional parameters default to client's configured organization
✅ New code can specify organization explicitly when needed

Testing

Tested with mcp-casdoor integration:

  • ✅ User retrieval from custom organization
  • ✅ Password verification for custom org users
  • ✅ Backward compatibility with single-org usage

Use Case

This enables MCP servers and other SDK clients to manage users across multiple organizations without requiring separate SDK client instances per organization.

Enable user queries across multiple organizations while maintaining
backward compatibility with existing single-organization usage.

Changes:
- GetUser: Auto-detect org-prefixed names ("org/user" format)
  If name contains "/", use as-is; otherwise prepend configured org
- GetUsers: Add optional organization variadic parameter
- GetUserByEmail: Add optional organization variadic parameter
- GetUserByPhone: Add optional organization variadic parameter
- GetSortedUsers: Add optional organization variadic parameter

Backward compatibility:
- All existing code continues to work without modification
- Optional parameters default to client's configured organization
- New code can specify organization explicitly when needed

Fixes issue where multi-org Casdoor instances couldn't query users
from organizations other than the SDK client's configured org.
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Bruno Clermont seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

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 cross-organization support to user query functions in the Casdoor SDK, enabling multi-tenant deployments while maintaining backward compatibility with existing single-organization usage.

Changes:

  • Modified GetUser() to auto-detect organization-prefixed names in org/user format
  • Added optional organization parameter to GetUsers(), GetSortedUsers(), GetUserByEmail(), and GetUserByPhone() functions
  • All changes maintain backward compatibility through optional parameters and format detection
Comments suppressed due to low confidence (1)

casdoorsdk/user.go:1

  • The global wrapper functions in user_global.go don't expose the new optional organization parameter. The wrapper for GetUsers(), GetSortedUsers(), GetUserByEmail(), and GetUserByPhone() should be updated to accept and pass through the variadic organization parameter to maintain API consistency.
// Copyright 2021 The Casdoor Authors. All Rights Reserved.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +231 to +236
// Support optional organization parameter
// If not provided, use the client's configured organization for backward compatibility
owner := c.OrganizationName
if len(organization) > 0 && organization[0] != "" {
owner = organization[0]
}
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The pattern for handling the optional organization parameter is duplicated across four functions (GetUsers, GetSortedUsers, GetUserByEmail, GetUserByPhone). Consider extracting this logic into a helper method like resolveOrganization(organization ...string) string to reduce duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
// If name already contains "/", it's a fully qualified name
// Otherwise, prepend the client's organization for backward compatibility
id := name
if !strings.Contains(name, "/") {
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The slash detection for organization-qualified names could incorrectly treat usernames containing '/' as already qualified. Consider using strings.Count(name, \"/\") == 0 or better yet, validate that the format matches 'org/user' with exactly one slash. This prevents ambiguity if usernames themselves can contain slashes.

Copilot uses AI. Check for mistakes.
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.

2 participants