Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit e607354

Browse files
committed
Merge branch 'develop' of github.com:topcoder-platform/topcoder-x-ui into develop
2 parents 69bbe00 + 005dfe5 commit e607354

File tree

5 files changed

+54
-10
lines changed

5 files changed

+54
-10
lines changed

.DS_Store

2 KB
Binary file not shown.

TopcoderXDeploy.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ To this:
8888

8989
## Local DNS setup
9090

91-
For login to work, your local Topcoder-X-UI deployment needs to have a `*.topcoder-dev.com` DNS name. Our development environment uses `x.topcoder-dev.com`
91+
For login to work, your local Topcoder-X-UI deployment needs to have a `*.topcoder-dev.com` DNS name. Our development environment uses `x.topcoder-dev.com`. But for local setup it's better to use another one to not interfere with the one deployed on DEV Topcoder environment. So better to use `topcoderx.topcoder-dev.com` which is already configured in `config.js`.
9292

9393
You can make this change in your local `/etc/hosts` file.
9494

9595
```
96-
127.0.0.1 x.topcoder-dev.com
96+
127.0.0.1 topcoderx.topcoder-dev.com
9797
```
9898

9999
You can login with one of these sample accounts:

src/controllers/GithubController.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* @version 1.0
1010
*/
1111

12+
const _ = require('lodash');
1213
const superagent = require('superagent');
1314
const superagentPromise = require('superagent-promise');
1415
const helper = require('../common/helper');
@@ -168,8 +169,20 @@ async function addUserToTeamCallback(req, res) {
168169
githubUserId: githubUser.id,
169170
});
170171
}
171-
// redirect to success page
172-
res.redirect(`${constants.USER_ADDED_TO_TEAM_SUCCESS_URL}/github`);
172+
173+
// check if user is already in the team or not yet
174+
if (githubUser.state === 'active') {
175+
// redirect user to the success page, to let user know that he is already in the team
176+
res.redirect(`${constants.USER_ADDED_TO_TEAM_SUCCESS_URL}/github`);
177+
} else {
178+
// redirect user to organization invitation page
179+
const teamDetails = await GithubService.getTeamDetails(team.ownerToken, team.teamId);
180+
const organizationLogin = _.get(teamDetails, 'organization.login');
181+
if (!organizationLogin) {
182+
throw new errors.ValidationError(`Couldn't get organization of the team with id '${team.teamId}'.`);
183+
}
184+
res.redirect(`https://github.com/orgs/${organizationLogin}/invitation?via_email=1`);
185+
}
173186
}
174187

175188
module.exports = {

src/front/src/app/members/member.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ <h2>{{title}}</h2>
1212
<div class="ibox float-e-margins">
1313
<div class="ibox-content">
1414
<div class="text-center m-t-lg" ng-if="provider==='github'">
15-
<h3>You were successfully invited to the team!</h3>
16-
<p>An invitation email will be sent to you if you are not already in the team.</p>
15+
<p>You are already in the team!</p>
1716
</div>
1817
<div class="text-center m-t-lg" ng-if="provider==='gitlab'">
1918
<p>You were successfully added to the group!</p>
@@ -22,4 +21,4 @@ <h3>You were successfully invited to the team!</h3>
2221
</div>
2322
</div>
2423
</div>
25-
</div>
24+
</div>

src/services/GithubService.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ getTeamRegistrationUrl.schema = Joi.object().keys({
183183
async function addTeamMember(teamId, ownerUserToken, normalUserToken) {
184184
let username;
185185
let id;
186+
let state;
186187
try {
187188
// get normal user name
188189
const githubNormalUser = new GitHub({
@@ -197,7 +198,8 @@ async function addTeamMember(teamId, ownerUserToken, normalUserToken) {
197198
token: ownerUserToken,
198199
});
199200
const team = github.getTeam(teamId);
200-
await team.addMembership(username);
201+
const membershipResponse = await team.addMembership(username);
202+
state = _.get(membershipResponse, 'data.state')
201203
} catch (err) {
202204
// if error is already exists discard
203205
if (_.chain(err).get('body.errors').countBy({
@@ -208,8 +210,8 @@ async function addTeamMember(teamId, ownerUserToken, normalUserToken) {
208210
throw helper.convertGitHubError(err, 'Failed to add team member');
209211
}
210212
}
211-
// return github username
212-
return {username, id};
213+
// return github username and its state
214+
return {username, id, state};
213215
}
214216

215217
addTeamMember.schema = Joi.object().keys({
@@ -240,12 +242,42 @@ getUserIdByUsername.schema = Joi.object().keys({
240242
username: Joi.string().required(),
241243
});
242244

245+
/**
246+
* Get team detailed data
247+
*
248+
* @param {String} token user owner token
249+
* @param {String|Number} teamId team id
250+
*
251+
* @returns {Object} team object, see https://developer.github.com/v3/teams/#get-team
252+
*/
253+
async function getTeamDetails(token, teamId) {
254+
const teamIdAsNumber = !_.isNumber(teamId) ? parseInt(teamId, 10) : teamId
255+
let team;
256+
257+
try {
258+
const github = new GitHub({token});
259+
const teamResponse = await github.getTeam(teamIdAsNumber).getTeam();
260+
261+
team = teamResponse.data;
262+
} catch (err) {
263+
throw helper.convertGitHubError(err, `Failed to get team with id '${teamId}'.`);
264+
}
265+
266+
return team;
267+
}
268+
269+
getTeamDetails.schema = Joi.object().keys({
270+
token: Joi.string().required(),
271+
teamId: Joi.alternatives().try(Joi.string(), Joi.number()).required(),
272+
});
273+
243274
module.exports = {
244275
ensureOwnerUser,
245276
listOwnerUserTeams,
246277
getTeamRegistrationUrl,
247278
addTeamMember,
248279
getUserIdByUsername,
280+
getTeamDetails,
249281
};
250282

251283
helper.buildService(module.exports);

0 commit comments

Comments
 (0)