request: Refactor remote_server into RequestNotes.

This eliminates the possibility of having `request.user` as
`RemoteZulipServer` by refactoring it as an attribute of `RequestNotes`.

So we can effectively narrow the type of `request.user` by testing
`user.is_authenticated` in most cases (except that of `SCIMClient`) in
code paths that require access to `.format_requestor_for_logs` where we
previously expect either `UserProfile` or `RemoteZulipServer` backed by
the implied polymorphism.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li
2022-06-12 15:33:20 -04:00
committed by Tim Abbott
parent 3bc78d2473
commit b02779c005
6 changed files with 18 additions and 11 deletions

View File

@@ -299,7 +299,8 @@ class HostRequestMock(HttpRequest):
def __init__(
self,
post_data: Dict[str, Any] = {},
user_profile: Union[UserProfile, RemoteZulipServer, None] = None,
user_profile: Union[UserProfile, None] = None,
remote_server: Optional[RemoteZulipServer] = None,
host: str = settings.EXTERNAL_HOST,
client_name: Optional[str] = None,
meta_data: Optional[Dict[str, Any]] = None,
@@ -335,6 +336,7 @@ class HostRequestMock(HttpRequest):
log_data={},
tornado_handler_id=None if tornado_handler is None else tornado_handler.handler_id,
client=get_client(client_name) if client_name is not None else None,
remote_server=remote_server,
),
)