diff --git a/public/static/locales/en/common.json b/public/static/locales/en/common.json index 03185f7d3..709db041b 100644 --- a/public/static/locales/en/common.json +++ b/public/static/locales/en/common.json @@ -92,6 +92,7 @@ "update": "Update", "updateAccountInformation": "Update Account Information", "updateNow": "Update Now", + "userPlanError": "Unable to get user plan details.", "usageSummaryError": "Unable to get usage summary.", "useOldDEForThisFeature": "Please use the previous version of the Discovery Environment for access to this feature, until we can add it to this version.", "userMenuAriaLabel": "user menu", diff --git a/src/components/layout/AppBar.js b/src/components/layout/AppBar.js index 24763775b..4fbd6afd8 100644 --- a/src/components/layout/AppBar.js +++ b/src/components/layout/AppBar.js @@ -26,10 +26,7 @@ import { useBootStrap, USER_PROFILE_QUERY_KEY, } from "serviceFacades/users"; -import { - getSubscriptionDetails, - SUBSCRIPTION_DETAILS_QUERY_KEY, -} from "serviceFacades/subscriptions"; +import { getUserPlan, USER_PLAN_QUERY_KEY } from "serviceFacades/subscriptions"; import constants from "../../constants"; import withErrorAnnouncer from "../error/withErrorAnnouncer"; @@ -156,20 +153,19 @@ function DEAppBar(props) { useQuery({ queryKey: USER_PROFILE_QUERY_KEY, queryFn: getUserProfile, - enabled: profileRefetchInterval != null, onSuccess: updateUserProfile, refetchInterval: profileRefetchInterval, }); useQuery({ - queryKey: [ - SUBSCRIPTION_DETAILS_QUERY_KEY, - { username: userProfile?.id }, - ], - queryFn: () => getSubscriptionDetails(userProfile?.id), - enabled: !!userProfile?.id, + queryKey: USER_PLAN_QUERY_KEY, + queryFn: getUserPlan, + enabled: !!config?.subscriptions?.enforce && !!userProfile?.id, onSuccess: setUserSubscription, + onError: (e) => { + showErrorAnnouncer(t("userPlanError"), e); + }, }); useEffect(() => { diff --git a/src/server/api/subscriptions.js b/src/server/api/subscriptions.js index a66da3e9e..b7995701c 100644 --- a/src/server/api/subscriptions.js +++ b/src/server/api/subscriptions.js @@ -80,7 +80,7 @@ export default function subscriptionsRouter() { }) ); - // Return details about a subscription + // Administrators can return details about a subscription logger.info("adding the GET /admin/qms/users/:username/plan handler"); api.get( "/admin/qms/users/:username/plan", @@ -91,6 +91,17 @@ export default function subscriptionsRouter() { }) ); + // Return details about a user's subscription + logger.info("adding the GET /qms/user/plan handler"); + api.get( + "/qms/user/plan", + auth.authnTokenMiddleware, + terrainHandler({ + method: "GET", + pathname: "/qms/user/plan", + }) + ); + // Subscription add-ons // Get all available add-ons logger.info("adding the GET /admin/qms/addons handler"); diff --git a/src/serviceFacades/subscriptions.js b/src/serviceFacades/subscriptions.js index 4ab37407c..a215ba637 100644 --- a/src/serviceFacades/subscriptions.js +++ b/src/serviceFacades/subscriptions.js @@ -11,8 +11,9 @@ const RESOURCE_TYPES_QUERY_KEY = "fetchResourceTypes"; const SUBSCRIPTION_ADDONS_QUERY_KEY = "fetchSubscriptionAddons"; const SUBSCRIPTION_DETAILS_QUERY_KEY = "fetchSubscriptionDetails"; const SUBSCRIPTIONS_QUERY_KEY = "fetchSubscriptions"; +const USER_PLAN_QUERY_KEY = "fetchUserPlan"; -// Get available add-ons +// Administrators can get available add-ons function getAvailableAddOns() { return callApi({ endpoint: `/api/admin/qms/addons`, @@ -136,7 +137,7 @@ function updateUserQuota(quota, resourceType, username) { }); } -// Return details about the subscription +// Administrators can return details about a subscription function getSubscriptionDetails(username) { return callApi({ endpoint: `/api/admin/qms/users/${username}/plan`, @@ -144,6 +145,14 @@ function getSubscriptionDetails(username) { }); } +// Return details about a user's subscription +function getUserPlan() { + return callApi({ + endpoint: `/api/qms/user/plan`, + method: "GET", + }); +} + function updateUserQuotas(quotas, username) { return ( quotas && @@ -194,6 +203,7 @@ export { getSubscriptionAddons, getSubscriptionDetails, getSubscriptions, + getUserPlan, postAddon, postSubAddon, postSubscription, @@ -206,4 +216,5 @@ export { SUBSCRIPTION_ADDONS_QUERY_KEY, SUBSCRIPTION_DETAILS_QUERY_KEY, SUBSCRIPTIONS_QUERY_KEY, + USER_PLAN_QUERY_KEY, };