Skip to content

Commit 7573860

Browse files
Merge pull request #465 from topcoder-platform/TCA-883_anon-profile
v2.0.7 TCA-883 Public Cert Hotfix Release - 2023-01-12 -> master
2 parents 0de2cd2 + d96085a commit 7573860

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@topcoder-platform/platform-ui",
3-
"version": "2.6",
3+
"version": "2.0.7",
44
"private": true,
55
"scripts": {
66
"dev": "yarn react-app-rewired start",
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { UserRole } from './profile-factory'
22
export {
3-
getAsync as profileGetAsync,
3+
getLoggedInAsync as profileGetLoggedInAsync,
4+
getPublicAsync as profileGetPublicAsync,
45
editNameAsync as profileEditNameAsync,
56
} from './profile.functions'

src-ts/lib/profile-provider/profile-functions/profile-factory/profile.factory.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { UserProfile } from '../../user-profile.model'
33

44
import { UserRole } from './user-role.enum'
55

6-
export function create(profile: UserProfile, token: TokenModel, hasDiceEnabled: boolean): UserProfile {
6+
export function create(profile: UserProfile, token?: TokenModel, hasDiceEnabled?: boolean): UserProfile {
77

88
// Currently, the "Self-Service Customer" role is being set when a user is created
99
// 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:
1212
// This is imperfect, bc a user could be both a Customer or a Member, but for now
1313
// we are okay with this and will have a more in-depth initiave to properly assign
1414
// roles.
15-
profile.isCustomer = !!token.roles?.some(role => role === UserRole.customer)
15+
profile.isCustomer = !!token?.roles?.some(role => role === UserRole.customer)
1616
profile.isMember = !profile.isCustomer
1717

18-
profile.isWipro = profile.email.endsWith('@wipro.com')
19-
profile.diceEnabled = hasDiceEnabled
18+
profile.isWipro = profile.email?.endsWith('@wipro.com')
19+
profile.diceEnabled = !!hasDiceEnabled
2020

2121
// store roles for custom capability checks
22-
profile.roles = token.roles || []
22+
profile.roles = token?.roles || []
2323

2424
// TODO: create the profile full name property
2525
return profile

src-ts/lib/profile-provider/profile-functions/profile.functions.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { UserProfile } from '../user-profile.model'
66
import { profileFactoryCreate } from './profile-factory'
77
import { profileStoreGet, profileStorePatchName } from './profile-store'
88

9-
export async function getAsync(handle?: string): Promise<UserProfile | undefined> {
9+
export async function getLoggedInAsync(handle?: string): Promise<UserProfile | undefined> {
1010

1111
// get the token
1212
const token: TokenModel = await tokenGetAsync()
@@ -28,6 +28,15 @@ export async function getAsync(handle?: string): Promise<UserProfile | undefined
2828
return output
2929
}
3030

31+
export async function getPublicAsync(handle: string): Promise<UserProfile | undefined> {
32+
33+
// get the profile
34+
const profileResult: UserProfile = await profileStoreGet(handle)
35+
36+
const output: UserProfile = profileFactoryCreate(profileResult)
37+
return output
38+
}
39+
3140
export async function editNameAsync(handle: string, profile: EditNameRequest): Promise<UserProfile> {
3241
return profileStorePatchName(handle, profile)
3342
}

src-ts/lib/profile-provider/profile.provider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { userUpdatePasswordAsync } from '../functions'
55
import { ChangePasswordRequest } from './change-password-request.model'
66
import { EditNameRequest } from './edit-name-request.model'
77
import { ProfileContextData } from './profile-context-data.model'
8-
import { profileEditNameAsync, profileGetAsync } from './profile-functions'
8+
import { profileEditNameAsync, profileGetLoggedInAsync } from './profile-functions'
99
import { UserProfile } from './user-profile.model'
1010
import profileContext, { defaultProfileContextData } from './profile.context'
1111

@@ -20,7 +20,7 @@ export const ProfileProvider: FC<{ children: ReactNode }> = ({ children }: { chi
2020
}
2121

2222
async function getAndSetProfileAsync(): Promise<void> {
23-
const profile: UserProfile | undefined = await profileGetAsync()
23+
const profile: UserProfile | undefined = await profileGetLoggedInAsync()
2424
const contextData: ProfileContextData = {
2525
changePassword,
2626
initialized: true,

src-ts/tools/learn/course-certificate/user-certificate/UserCertificate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Params, useParams, useSearchParams } from 'react-router-dom'
33

44
import {
55
LoadingSpinner,
6-
profileGetAsync,
6+
profileGetPublicAsync,
77
UserProfile,
88
} from '../../../../lib'
99
import { getViewStyleParamKey } from '../../learn.routes'
@@ -28,7 +28,7 @@ const UserCertificate: FC<{}> = () => {
2828

2929
useEffect(() => {
3030
if (routeParams.memberHandle) {
31-
profileGetAsync(routeParams.memberHandle)
31+
profileGetPublicAsync(routeParams.memberHandle)
3232
.then(userProfile => {
3333
setProfile(userProfile)
3434
setProfileReady(true)

0 commit comments

Comments
 (0)