Skip to content

Commit

Permalink
fix: remove unnecessary region parameter from Oauth2TokenHolder update (
Browse files Browse the repository at this point in the history
  • Loading branch information
piglei authored Mar 6, 2025
1 parent 5321066 commit 37ee7f2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
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

0 comments on commit 37ee7f2

Please sign in to comment.