Skip to content

Commit

Permalink
Merge pull request #546 from sboleyn/master
Browse files Browse the repository at this point in the history
CORE-1950 Pro user cannot see Intercom widget
  • Loading branch information
sboleyn authored Aug 18, 2023
2 parents d19b54e + d14853b commit fb65dab
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
1 change: 1 addition & 0 deletions public/static/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <oldDELink>previous version of the Discovery Environment</oldDELink> for access to this feature, until we can add it to this version.",
"userMenuAriaLabel": "user menu",
Expand Down
18 changes: 7 additions & 11 deletions src/components/layout/AppBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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(() => {
Expand Down
13 changes: 12 additions & 1 deletion src/server/api/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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");
Expand Down
15 changes: 13 additions & 2 deletions src/serviceFacades/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down Expand Up @@ -136,14 +137,22 @@ 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`,
method: "GET",
});
}

// Return details about a user's subscription
function getUserPlan() {
return callApi({
endpoint: `/api/qms/user/plan`,
method: "GET",
});
}

function updateUserQuotas(quotas, username) {
return (
quotas &&
Expand Down Expand Up @@ -194,6 +203,7 @@ export {
getSubscriptionAddons,
getSubscriptionDetails,
getSubscriptions,
getUserPlan,
postAddon,
postSubAddon,
postSubscription,
Expand All @@ -206,4 +216,5 @@ export {
SUBSCRIPTION_ADDONS_QUERY_KEY,
SUBSCRIPTION_DETAILS_QUERY_KEY,
SUBSCRIPTIONS_QUERY_KEY,
USER_PLAN_QUERY_KEY,
};

0 comments on commit fb65dab

Please sign in to comment.