diff --git a/backend/src/services/graph_access/graph_access.py b/backend/src/services/graph_access/graph_access.py index 53f8d5ee0..94756e73e 100644 --- a/backend/src/services/graph_access/graph_access.py +++ b/backend/src/services/graph_access/graph_access.py @@ -1,5 +1,6 @@ import base64 from typing import Mapping +from urllib.parse import urljoin # Using the same http client as sumo import httpx @@ -8,6 +9,7 @@ class GraphApiAccess: def __init__(self, access_token: str): self._access_token = access_token + self.base_url = "https://graph.microsoft.com/v1.0/" def _make_headers(self) -> Mapping[str, str]: return {"Authorization": f"Bearer {self._access_token}"} @@ -21,10 +23,7 @@ async def _request(self, url: str) -> httpx.Response: return response async def get_user_profile_photo(self, user_id: str) -> str | None: - request_url = f"https://graph.microsoft.com/v1.0/me/photo/$value" - - if user_id != "me": - request_url = f"https://graph.microsoft.com/v1.0/users/{user_id}/photo/$value" + request_url = urljoin(self.base_url, "me/photo/$value" if user_id == "me" else f"users/{user_id}/photo/$value") response = await self._request(request_url) @@ -34,10 +33,7 @@ async def get_user_profile_photo(self, user_id: str) -> str | None: return None async def get_user_info(self, user_id: str) -> Mapping[str, str] | None: - request_url = f"https://graph.microsoft.com/v1.0/me" - - if user_id != "me": - request_url = f"https://graph.microsoft.com/v1.0/users/{user_id}" + request_url = urljoin(self.base_url, "me" if user_id == "me" else f"users/{user_id}") response = await self._request(request_url) diff --git a/frontend/src/framework/internal/components/SelectEnsemblesDialog/private-components/userAvatar.tsx b/frontend/src/framework/internal/components/SelectEnsemblesDialog/private-components/userAvatar.tsx index 8e65c388c..7870d6d62 100644 --- a/frontend/src/framework/internal/components/SelectEnsemblesDialog/private-components/userAvatar.tsx +++ b/frontend/src/framework/internal/components/SelectEnsemblesDialog/private-components/userAvatar.tsx @@ -1,21 +1,19 @@ -import { UseQueryResult, useQuery } from "@tanstack/react-query"; import React from "react"; import { GraphUserPhoto_api } from "@api"; import { apiService } from "@framework/ApiService"; import { CircularProgress } from "@lib/components/CircularProgress"; import { AccountCircle } from "@mui/icons-material"; +import { UseQueryResult, useQuery } from "@tanstack/react-query"; export type UserAvatarProps = { userId: string; -} +}; const STALE_TIME = 60 * 1000; const CACHE_TIME = 60 * 1000; -function useUserInfoQuery( - userId: string -): UseQueryResult { +function useUserInfoQuery(userId: string): UseQueryResult { return useQuery({ queryKey: ["getUserInfo", userId], queryFn: () => apiService.graph.userInfo(`${userId.toUpperCase()}@equinor.com`), @@ -31,7 +29,7 @@ export const UserAvatar: React.FC = (props) => { if (userInfo.isFetching) { return ; } - + if (userInfo.data?.avatar_b64str) { return ( = (props) => { /> ); } - return ; -} \ No newline at end of file + return ( + + + + ); +}; diff --git a/frontend/src/framework/internal/components/SelectEnsemblesDialog/selectEnsemblesDialog.tsx b/frontend/src/framework/internal/components/SelectEnsemblesDialog/selectEnsemblesDialog.tsx index 49d1f435a..a9975fec7 100644 --- a/frontend/src/framework/internal/components/SelectEnsemblesDialog/selectEnsemblesDialog.tsx +++ b/frontend/src/framework/internal/components/SelectEnsemblesDialog/selectEnsemblesDialog.tsx @@ -259,7 +259,7 @@ export const SelectEnsemblesDialog: React.FC = (prop onChange={handleKeepCasesSwitchChange} /> -