From d57cf80c76df050b0d3ee96d4e3f7cb1283730d7 Mon Sep 17 00:00:00 2001 From: Brooke Date: Thu, 12 Jan 2023 12:37:49 -0800 Subject: [PATCH 1/4] TCA-883 Create public profile getter --- .../profile-provider/profile-functions/index.ts | 3 ++- .../profile-factory/profile.factory.ts | 10 +++++----- .../profile-functions/profile.functions.ts | 17 ++++++++++++++++- .../lib/profile-provider/profile.provider.tsx | 4 ++-- .../user-certificate/UserCertificate.tsx | 4 ++-- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src-ts/lib/profile-provider/profile-functions/index.ts b/src-ts/lib/profile-provider/profile-functions/index.ts index feefd3b99..6de4cee2c 100644 --- a/src-ts/lib/profile-provider/profile-functions/index.ts +++ b/src-ts/lib/profile-provider/profile-functions/index.ts @@ -1,5 +1,6 @@ export { UserRole } from './profile-factory' export { - getAsync as profileGetAsync, + getLoggedInAsync as profileGetLoggedInAsync, + getPublicAsync as profileGetPublicAsync, editNameAsync as profileEditNameAsync, } from './profile.functions' diff --git a/src-ts/lib/profile-provider/profile-functions/profile-factory/profile.factory.ts b/src-ts/lib/profile-provider/profile-functions/profile-factory/profile.factory.ts index 13fe53fdd..34879354d 100644 --- a/src-ts/lib/profile-provider/profile-functions/profile-factory/profile.factory.ts +++ b/src-ts/lib/profile-provider/profile-functions/profile-factory/profile.factory.ts @@ -3,7 +3,7 @@ import { UserProfile } from '../../user-profile.model' import { UserRole } from './user-role.enum' -export function create(profile: UserProfile, token: TokenModel, hasDiceEnabled: boolean): UserProfile { +export function create(profile: UserProfile, token?: TokenModel, hasDiceEnabled?: boolean): UserProfile { // Currently, the "Self-Service Customer" role is being set when a user is created // during the self-service workflow. There are no other roles being set to distinguish @@ -12,14 +12,14 @@ export function create(profile: UserProfile, token: TokenModel, hasDiceEnabled: // This is imperfect, bc a user could be both a Customer or a Member, but for now // we are okay with this and will have a more in-depth initiave to properly assign // roles. - profile.isCustomer = !!token.roles?.some(role => role === UserRole.customer) + profile.isCustomer = !!token?.roles?.some(role => role === UserRole.customer) profile.isMember = !profile.isCustomer - profile.isWipro = profile.email.endsWith('@wipro.com') - profile.diceEnabled = hasDiceEnabled + profile.isWipro = profile.email?.endsWith('@wipro.com') + profile.diceEnabled = !!hasDiceEnabled // store roles for custom capability checks - profile.roles = token.roles || [] + profile.roles = token?.roles || [] // TODO: create the profile full name property return profile diff --git a/src-ts/lib/profile-provider/profile-functions/profile.functions.ts b/src-ts/lib/profile-provider/profile-functions/profile.functions.ts index ede0f9ef7..765d7c0b8 100644 --- a/src-ts/lib/profile-provider/profile-functions/profile.functions.ts +++ b/src-ts/lib/profile-provider/profile-functions/profile.functions.ts @@ -6,7 +6,7 @@ import { UserProfile } from '../user-profile.model' import { profileFactoryCreate } from './profile-factory' import { profileStoreGet, profileStorePatchName } from './profile-store' -export async function getAsync(handle?: string): Promise { +export async function getLoggedInAsync(handle?: string): Promise { // get the token const token: TokenModel = await tokenGetAsync() @@ -28,6 +28,21 @@ export async function getAsync(handle?: string): Promise { + + // get the handle + if (!handle) { + return Promise.resolve(undefined) + } + + // get the profile + const profileResult: UserProfile = await profileStoreGet(handle) + + // make the changes we need based on the token + const output: UserProfile = profileFactoryCreate(profileResult) + return output +} + export async function editNameAsync(handle: string, profile: EditNameRequest): Promise { return profileStorePatchName(handle, profile) } diff --git a/src-ts/lib/profile-provider/profile.provider.tsx b/src-ts/lib/profile-provider/profile.provider.tsx index 7447e04f3..d646378a2 100644 --- a/src-ts/lib/profile-provider/profile.provider.tsx +++ b/src-ts/lib/profile-provider/profile.provider.tsx @@ -5,7 +5,7 @@ import { userUpdatePasswordAsync } from '../functions' import { ChangePasswordRequest } from './change-password-request.model' import { EditNameRequest } from './edit-name-request.model' import { ProfileContextData } from './profile-context-data.model' -import { profileEditNameAsync, profileGetAsync } from './profile-functions' +import { profileEditNameAsync, profileGetLoggedInAsync } from './profile-functions' import { UserProfile } from './user-profile.model' import profileContext, { defaultProfileContextData } from './profile.context' @@ -20,7 +20,7 @@ export const ProfileProvider: FC<{ children: ReactNode }> = ({ children }: { chi } async function getAndSetProfileAsync(): Promise { - const profile: UserProfile | undefined = await profileGetAsync() + const profile: UserProfile | undefined = await profileGetLoggedInAsync() const contextData: ProfileContextData = { changePassword, initialized: true, diff --git a/src-ts/tools/learn/course-certificate/user-certificate/UserCertificate.tsx b/src-ts/tools/learn/course-certificate/user-certificate/UserCertificate.tsx index 0d6dd0a0d..6be68de30 100644 --- a/src-ts/tools/learn/course-certificate/user-certificate/UserCertificate.tsx +++ b/src-ts/tools/learn/course-certificate/user-certificate/UserCertificate.tsx @@ -3,7 +3,7 @@ import { Params, useParams, useSearchParams } from 'react-router-dom' import { LoadingSpinner, - profileGetAsync, + profileGetPublicAsync, UserProfile, } from '../../../../lib' import { getViewStyleParamKey } from '../../learn.routes' @@ -28,7 +28,7 @@ const UserCertificate: FC<{}> = () => { useEffect(() => { if (routeParams.memberHandle) { - profileGetAsync(routeParams.memberHandle) + profileGetPublicAsync(routeParams.memberHandle) .then(userProfile => { setProfile(userProfile) setProfileReady(true) From 27e6e6a5c805dec19b489777f6bd57ac35ac740d Mon Sep 17 00:00:00 2001 From: Brooke Date: Thu, 12 Jan 2023 14:23:53 -0800 Subject: [PATCH 2/4] TCA-883 Add minor version in order to use npm version patch --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3ccbf5e7a..9e9c877c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@topcoder-platform/platform-ui", - "version": "2.6", + "version": "2.0.6", "private": true, "scripts": { "dev": "yarn react-app-rewired start", From 2688a8bda3ff03e47b7e8ea4bd749e2f882680ad Mon Sep 17 00:00:00 2001 From: Brooke Date: Thu, 12 Jan 2023 14:24:36 -0800 Subject: [PATCH 3/4] 2.0.7 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9e9c877c6..a880544cc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@topcoder-platform/platform-ui", - "version": "2.0.6", + "version": "2.0.7", "private": true, "scripts": { "dev": "yarn react-app-rewired start", From d96085af8397025eba615848e82ae4017c3874ca Mon Sep 17 00:00:00 2001 From: Brooke Date: Thu, 12 Jan 2023 14:29:00 -0800 Subject: [PATCH 4/4] TCA-883 clean up --- .../profile-functions/profile.functions.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src-ts/lib/profile-provider/profile-functions/profile.functions.ts b/src-ts/lib/profile-provider/profile-functions/profile.functions.ts index 765d7c0b8..bdb5c8fc9 100644 --- a/src-ts/lib/profile-provider/profile-functions/profile.functions.ts +++ b/src-ts/lib/profile-provider/profile-functions/profile.functions.ts @@ -28,17 +28,11 @@ export async function getLoggedInAsync(handle?: string): Promise { - - // get the handle - if (!handle) { - return Promise.resolve(undefined) - } +export async function getPublicAsync(handle: string): Promise { // get the profile const profileResult: UserProfile = await profileStoreGet(handle) - // make the changes we need based on the token const output: UserProfile = profileFactoryCreate(profileResult) return output }