Skip to content

Commit 8031596

Browse files
committed
feature(profile): redirect from private community to community app profile page
add support for redirecting configured community member stats page to topcoder community app stats page when authenticated user views member who is not part of the configured community.
1 parent feae08c commit 8031596

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed

config/default.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ module.exports = {
162162
ABANDONMENT_EMBED: 'https://43d132d5dbff47c59d9d53ad448f93c2.js.ubembed.com',
163163
// If a logged in user is a member of any of these groups, when they land on
164164
// their profile page (members/:handle), they'll be redirected to the "userProfile" url
165-
SUBDOMAIN_PROFILE_CONFIG: [
166-
{ groupId: '20000000', communityId: 'wipro', userProfile: 'https://topgear-app.wipro.com/user-details' },
167-
],
165+
SUBDOMAIN_PROFILE_CONFIG: [{
166+
groupId: '20000000', communityId: 'wipro', communityName: 'topgear', userProfile: 'https://topgear-app.wipro.com/user-details',
167+
}],
168168
},
169169

170170
/* Information about Topcoder user groups can be cached in various places.

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@
147147
"supertest": "^3.1.0",
148148
"tc-core-library-js": "github:appirio-tech/tc-core-library-js#v2.6.3",
149149
"tc-ui": "^1.0.12",
150-
"topcoder-react-lib": "1000.27.15",
150+
"topcoder-react-lib": "1000.27.16",
151151
"topcoder-react-ui-kit": "2.0.1",
152152
"topcoder-react-utils": "0.7.8",
153153
"turndown": "^4.0.2",

src/shared/containers/Profile.jsx

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@ class ProfileContainer extends React.Component {
2121
meta,
2222
auth,
2323
} = this.props;
24-
2524
loadProfile(handleParam, _.get(meta, 'groupIds', []), auth.tokenV3, loadPublicStatsOnly(meta));
26-
if (auth.tokenV3 && auth.memberGroups && auth.memberGroups.length > 0
27-
&& auth.user && auth.user.handle === handleParam) {
28-
_.forEach(auth.memberGroups, (memberGroup) => { /* eslint consistent-return: off */
29-
const profileConfig = _.find(config.URL.SUBDOMAIN_PROFILE_CONFIG, { groupId: memberGroup });
30-
if (profileConfig && profileConfig.userProfile) {
31-
// redirect user to configured profile url
32-
window.location.href = profileConfig.userProfile;
33-
return false;
34-
}
35-
});
25+
if (auth.tokenV3 && auth.memberGroups && auth.memberGroups.length > 0 && auth.user) {
26+
if (auth.user.handle === handleParam) {
27+
_.forEach(auth.memberGroups, (memberGroup) => { /* eslint consistent-return: off */
28+
const profileConfig = _.find(
29+
config.URL.SUBDOMAIN_PROFILE_CONFIG,
30+
{ groupId: memberGroup },
31+
);
32+
if (profileConfig && profileConfig.userProfile) {
33+
// redirect user to configured profile url
34+
window.location.href = profileConfig.userProfile;
35+
return false;
36+
}
37+
});
38+
}
3639
}
3740
}
3841

@@ -41,13 +44,40 @@ class ProfileContainer extends React.Component {
4144
handleParam,
4245
profileForHandle,
4346
loadProfile,
47+
loadMemberGroups,
4448
meta,
4549
auth,
50+
info,
51+
memberGroups,
4652
} = nextProps;
4753

54+
const {
55+
info: prevInfo,
56+
memberGroups: prevMemberGroups,
57+
} = this.props;
58+
4859
if (handleParam !== profileForHandle) {
4960
loadProfile(handleParam, _.get(meta, 'groupIds', []), auth.tokenV3, loadPublicStatsOnly(meta));
5061
}
62+
63+
if (auth.tokenV3 && auth.user && auth.user.handle !== handleParam
64+
&& info != null && info.userId != null
65+
&& (prevInfo == null || info.userId !== prevInfo.userId)) {
66+
loadMemberGroups(info.userId, auth.tokenV3);
67+
}
68+
69+
if (memberGroups && memberGroups !== prevMemberGroups) {
70+
_.forEach(auth.memberGroups, (memberGroup) => { /* eslint consistent-return: off */
71+
const profileConfig = _.find(config.URL.SUBDOMAIN_PROFILE_CONFIG, { groupId: memberGroup });
72+
if (profileConfig && profileConfig.userProfile
73+
&& memberGroups.indexOf(profileConfig.groupId) === -1) {
74+
if (window.location.href.indexOf(profileConfig.communityName) !== -1) {
75+
window.location.href = `${config.URL.BASE}/members/${handleParam}`;
76+
}
77+
return false;
78+
}
79+
});
80+
}
5181
}
5282

5383
render() {
@@ -106,6 +136,7 @@ ProfileContainer.defaultProps = {
106136
skills: null,
107137
stats: null,
108138
meta: null,
139+
memberGroups: null,
109140
auth: {},
110141
};
111142

@@ -119,9 +150,11 @@ ProfileContainer.propTypes = {
119150
info: PT.shape(),
120151
loadingError: PT.bool.isRequired,
121152
loadProfile: PT.func.isRequired,
153+
loadMemberGroups: PT.func.isRequired,
122154
profileForHandle: PT.string,
123155
skills: PT.shape(),
124156
stats: PT.arrayOf(PT.shape()),
157+
memberGroups: PT.arrayOf(PT.string),
125158
lookupData: PT.shape().isRequired,
126159
meta: PT.shape(),
127160
auth: PT.shape(),
@@ -140,6 +173,7 @@ const mapStateToProps = (state, ownProps) => ({
140173
profileForHandle: state.profile.profileForHandle,
141174
skills: state.profile.skills,
142175
stats: state.profile.stats,
176+
memberGroups: state.groups.memberGroups,
143177
lookupData: state.lookup,
144178
auth: {
145179
...state.auth,
@@ -150,6 +184,9 @@ function mapDispatchToProps(dispatch) {
150184
const a = actions.profile;
151185
const lookupActions = actions.lookup;
152186
return {
187+
loadMemberGroups: (userId, tokenV3) => {
188+
dispatch(actions.groups.getMemberGroups(userId, tokenV3));
189+
},
153190
loadProfile: (handle, groupIds, tokenV3, showPublicStats) => {
154191
dispatch(a.clearProfile());
155192
dispatch(a.loadProfile(handle));

0 commit comments

Comments
 (0)