Skip to content
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

fix: remove unnecessary region parameter from Oauth2TokenHolder update #1944

Merged
merged 3 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apiserver/paasng/paasng/core/tenant/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def get_tenant(user: User) -> Tenant:
try:
_id = getattr(user, "tenant_id")
except AttributeError:
raise ValueError("No tenant can be found")
raise ValueError("The user object doesn't have the tenant_id attribute")
if not _id:
raise ValueError("The tenant_id exists but its value is empty")

return Tenant(_id)


Expand Down
10 changes: 8 additions & 2 deletions apiserver/paasng/paasng/infras/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class User(AbstractBaseUser):
_("active"),
default=True,
help_text=_(
"Designates whether this user should be treated as active. " "Unselect this instead of deleting accounts."
"Designates whether this user should be treated as active. Unselect this instead of deleting accounts."
),
)
date_joined = models.DateTimeField(_("date joined"), default=timezone.now)
Expand Down Expand Up @@ -273,7 +273,13 @@ def get_scope(self) -> str:


class PrivateTokenHolder(AuditedModel):
"""Private Token for sourcectl"""
"""Besides the OAuth2 token, the private token is also supported for authentication
with external code services, such as GitLab, etc. When a user (such as a system user)
cannot use OAuth2, the private token is a good alternative.

Despite the name, the "private token" in this model is not related to the "UserPrivateToken"
model.
"""

provider = models.CharField(max_length=32)
private_token = EncryptField(default="")
Expand Down
2 changes: 1 addition & 1 deletion apiserver/paasng/paasng/infras/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def bind(self, request, backend):
scope = token_params.pop("scope", None)
try:
Oauth2TokenHolder.objects.update_or_create(
provider=backend_name, user=user_profile, region="ieod", scope=scope, defaults=token_params
provider=backend_name, user=user_profile, scope=scope, defaults=token_params
)
except Exception:
msg = f"failed to save access token(from {backend}) to {user_profile.username}"
Expand Down