mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 05:23:35 +00:00
scim: Downgrade SCIMClient from a model to an ephemeral dataclass.
SCIMClient is a type-unsafe workaround for django-scim2’s conflation of SCIM users with Django users. Given that a SCIMClient is not a UserProfile, it might as well not be a model at all, since it’s only used to satisfy django-scim2’s request.user.is_authenticated queries. This doesn’t solve the type safety issue with assigning a SCIMClient to request.user, nor the performance issue with running the SCIM middleware on non-SCIM requests. But it reduces the risk of potential consequences worse than crashing, since there’s no longer a request.user.id for Django to confuse with the ID of an actual UserProfile. Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
8fc811dfa9
commit
9198fe4fac
@@ -4793,26 +4793,3 @@ def flush_alert_word(*, instance: AlertWord, **kwargs: object) -> None:
|
||||
|
||||
post_save.connect(flush_alert_word, sender=AlertWord)
|
||||
post_delete.connect(flush_alert_word, sender=AlertWord)
|
||||
|
||||
|
||||
class SCIMClient(models.Model):
|
||||
realm: Realm = models.ForeignKey(Realm, on_delete=CASCADE)
|
||||
name: str = models.TextField()
|
||||
|
||||
class Meta:
|
||||
unique_together = ("realm", "name")
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"<SCIMClient {self.name} for realm {self.realm_id}>"
|
||||
|
||||
def format_requestor_for_logs(self) -> str:
|
||||
return f"scim-client:{self.name}:realm:{self.realm_id}"
|
||||
|
||||
@property
|
||||
def is_authenticated(self) -> bool:
|
||||
"""
|
||||
The purpose of this is to make SCIMClient behave like a UserProfile
|
||||
when an instance is assigned to request.user - we need it to pass
|
||||
request.user.is_authenticated verifications.
|
||||
"""
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user