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

Commit d49c967

Browse files
committed
use group api to get groups
1 parent a1d1d06 commit d49c967

File tree

6 files changed

+133
-33
lines changed

6 files changed

+133
-33
lines changed

conf/web/WEB-INF/applicationContext.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@
356356
<property name="loggerName" value="com.topcoder.accounting.fees.view.actions.ContestFeesHomeAction"/>
357357
<property name="contestFeeService" ref="contestFeeService"/>
358358
<property name="contestFeePercentageService" ref="contestFeePercentageService"/>
359+
<property name="userGroupsApiEndpoint" value="@userGroupsApiEndpoint@"/>
359360
</bean>
360361

361362
<bean id="projectAction" class="com.topcoder.direct.services.view.action.contest.launch.ProjectAction"

conf/web/WEB-INF/struts.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,6 +1661,11 @@
16611661
<result name="error" type="json"/>
16621662
</action>
16631663

1664+
<action name="getGroups" method="getGroups" class="commonAction">
1665+
<result name="success" type="json"/>
1666+
<result name="error" type="json"/>
1667+
</action>
1668+
16641669
<action name="documentUpload" class="documentUploadAction">
16651670
<result name="success" type="json"/>
16661671
<result name="error" type="json"/>

src/java/main/com/topcoder/direct/services/view/action/contest/launch/CommonAction.java

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
*/
44
package com.topcoder.direct.services.view.action.contest.launch;
55

6-
import java.util.ArrayList;
7-
import java.util.Arrays;
8-
import java.util.HashMap;
9-
import java.util.List;
10-
import java.util.Map;
6+
import java.net.URI;
7+
import java.util.*;
118

129
import com.topcoder.clients.model.Project;
1310
import com.topcoder.clients.model.ProjectContestFee;
@@ -29,11 +26,21 @@
2926
import com.topcoder.direct.services.view.util.AuthorizationProvider;
3027
import com.topcoder.direct.services.view.util.DataProvider;
3128
import com.topcoder.direct.services.view.util.DirectUtils;
29+
import com.topcoder.direct.services.view.util.JwtTokenUpdater;
3230
import com.topcoder.direct.services.view.util.challenge.CostCalculationService;
3331
import com.topcoder.security.TCSubject;
3432
import com.topcoder.service.facade.contest.ContestServiceException;
3533
import com.topcoder.service.facade.project.DAOFault;
34+
import com.topcoder.util.log.Level;
3635
import org.apache.commons.lang3.StringEscapeUtils;
36+
import org.apache.http.HttpEntity;
37+
import org.apache.http.HttpHeaders;
38+
import org.apache.http.HttpResponse;
39+
import org.apache.http.HttpStatus;
40+
import org.apache.http.client.methods.HttpGet;
41+
import org.apache.http.client.utils.URIBuilder;
42+
import org.apache.http.impl.client.DefaultHttpClient;
43+
import org.codehaus.jackson.JsonNode;
3744
import org.codehaus.jackson.map.ObjectMapper;
3845
import com.topcoder.management.project.ProjectGroup;
3946

@@ -130,6 +137,16 @@ public class CommonAction extends BaseContestFeeAction {
130137

131138
private long categoryId;
132139

140+
private String userGroupsApiEndpoint;
141+
142+
/**
143+
* The jackson object mapping which is used to deserialize json return from API to domain model.
144+
*/
145+
protected static final ObjectMapper objectMapper;
146+
static {
147+
objectMapper = new ObjectMapper();
148+
}
149+
133150
/**
134151
* <p>
135152
* Executes the action.
@@ -325,7 +342,6 @@ public String getContestConfigs() throws Exception {
325342

326343
configs.put("copilotFees", ConfigUtils.getCopilotFees());
327344
configs.put("billingInfos", getBillingProjectInfos());
328-
configs.put("groups", getAllProjectGroups());
329345
configs.put("platforms", getReferenceDataBean().getPlatforms());
330346
configs.put("technologies", getReferenceDataBean().getTechnologies());
331347
setResult(configs);
@@ -552,4 +568,62 @@ public long getCategoryId() {
552568
public void setCategoryId(long categoryId) {
553569
this.categoryId = categoryId;
554570
}
571+
572+
/**
573+
* Get Accessible security groups from group Api
574+
*
575+
* @return
576+
*/
577+
public String getGroups() {
578+
try {
579+
TCSubject tcSubject = DirectUtils.getTCSubjectFromSession();
580+
URIBuilder uri = new URIBuilder(userGroupsApiEndpoint);
581+
582+
if (!DirectUtils.isCockpitAdmin(tcSubject) && !DirectUtils.isTcStaff(tcSubject)) {
583+
uri.setParameter("memberId", String.valueOf(tcSubject.getUserId()));
584+
}
585+
586+
DefaultHttpClient httpClient = new DefaultHttpClient();
587+
588+
HttpGet getRequest = new HttpGet(uri.build());
589+
getLogger().log(Level.INFO, "Getting Group with thi uri: " + uri.build().toString());
590+
591+
String v3Token = new JwtTokenUpdater().check().getToken();
592+
593+
getRequest.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + v3Token);
594+
595+
getRequest.addHeader(HttpHeaders.ACCEPT, "application/json");
596+
HttpResponse httpResponse = httpClient.execute(getRequest);
597+
598+
HttpEntity entity = httpResponse.getEntity();
599+
600+
if (httpResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
601+
throw new Exception("Unable to get groups from the API:" + httpResponse.getStatusLine().getReasonPhrase());
602+
}
603+
604+
JsonNode result = objectMapper.readTree(entity.getContent());
605+
JsonNode groups = result.path("result").path("content");
606+
Set<Map<String, String>> groupResults = new HashSet<Map<String, String>>();
607+
for (JsonNode group : groups) {
608+
Map<String,String> gr = new HashMap<String, String>();
609+
gr.put("id", group.get("id").asText());
610+
gr.put("name", group.get("name").asText());
611+
groupResults.add(gr);
612+
}
613+
setResult(groupResults);
614+
} catch (Throwable e) {
615+
if (getModel() != null) {
616+
setResult(e);
617+
}
618+
}
619+
return SUCCESS;
620+
}
621+
622+
public String getUserGroupsApiEndpoint() {
623+
return userGroupsApiEndpoint;
624+
}
625+
626+
public void setUserGroupsApiEndpoint(String userGroupsApiEndpoint) {
627+
this.userGroupsApiEndpoint = userGroupsApiEndpoint;
628+
}
555629
}

src/web/scripts/launch/main.js

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ $(document).ready(function() {
215215
data: {},
216216
cache: false,
217217
dataType: 'json',
218-
async : false,
219218
success: function (jsonResult) {
220219
handleJsonResult(jsonResult,
221220
function(result) {
@@ -228,30 +227,6 @@ $(document).ready(function() {
228227
billingInfos = result.billingInfos;
229228
copilotFees = result.copilotFees;
230229
if (typeof jQuery_1_11_1 !== 'undefined' && jQuery_1_11_1 !== null) {
231-
securityGroups = result.groups;
232-
securityGroups.sort(sortByname);
233-
var ms_group = jQuery_1_11_1("#groups").magicSuggest({
234-
placeholder: 'Type group name here',
235-
allowFreeEntries: false,
236-
data: securityGroups,
237-
disabled: securityGroups.length > 0 ? false : true
238-
});
239-
jQuery_1_11_1(ms_group).on('selectionchange', function(e,m){
240-
if (groupCancel){
241-
return;
242-
}
243-
if (this.getValue().length > 0 && jQuery_1_11_1("#preRegisterUsers").magicSuggest().getValue().length > 0){
244-
displayWarning("#yesNoConfirmation", "Confirmation", "Changing group will remove all assigned members.\n" +
245-
"Do you want to proceed?", "OK", function(){
246-
jQuery_1_11_1("#preRegisterUsers").magicSuggest().clear();
247-
closeModal();
248-
}, "CANCEL", function(){
249-
jQuery_1_11_1("#groups").magicSuggest().clear();
250-
closeModal();
251-
});
252-
253-
}
254-
});
255230
platforms = result.platforms;
256231
platforms.sort(sortByname);
257232
jQuery_1_11_1("#platforms").magicSuggest({
@@ -325,7 +300,48 @@ $(document).ready(function() {
325300
})
326301
}
327302
});
328-
303+
$.ajax({
304+
type: 'POST',
305+
url: ctx+"/launch/getGroups",
306+
cache: false,
307+
dataType: 'json',
308+
success: function (jsonResult) {
309+
handleJsonResult(jsonResult,
310+
function(result) {
311+
if (typeof jQuery_1_11_1 !== 'undefined' && jQuery_1_11_1 !== null) {
312+
console.log(result);
313+
securityGroups = $.map(result, function(val){
314+
return {id: Number(val["id"]), name: val["name"]};
315+
});
316+
securityGroups.sort(sortByname);
317+
var ms_group = jQuery_1_11_1("#groups").magicSuggest({
318+
placeholder: 'Type group name here',
319+
allowFreeEntries: false,
320+
data: securityGroups,
321+
disabled: securityGroups.length > 0 ? false : true
322+
});
323+
jQuery_1_11_1(ms_group).on('selectionchange', function(e,m){
324+
if (groupCancel){
325+
return;
326+
}
327+
if (this.getValue().length > 0 && jQuery_1_11_1("#preRegisterUsers").magicSuggest().getValue().length > 0){
328+
displayWarning("#yesNoConfirmation", "Confirmation", "Changing group will remove all assigned members.\n" +
329+
"Do you want to proceed?", "OK", function(){
330+
jQuery_1_11_1("#preRegisterUsers").magicSuggest().clear();
331+
closeModal();
332+
}, "CANCEL", function(){
333+
jQuery_1_11_1("#groups").magicSuggest().clear();
334+
closeModal();
335+
});
336+
}
337+
});
338+
}
339+
},
340+
function(errorMessage) {
341+
showServerError(errorMessage);
342+
});
343+
}
344+
});
329345
// multiple prizes add for studio
330346
$('.prizesInner .studioAdd').click(function(){
331347
if($('#extraPrizes').is( ":hidden ")){

token.properties.docker

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,4 @@
365365
@directChallengeServicesApiUrl@=http://api.topcoder-dev.com/v3/direct/challenges
366366
@authorizationUrl@=http://api.topcoder-dev.com/v3/authorizations
367367
@ssoLoginUrl@=https://topcoder-dev.com/login/
368+
@userGroupsApiEndpoint@=http://172.18.0.1:8080/v3/groups

token.properties.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@
417417
@member.profile.url.base@=http://tc.cloud.topcoder.com
418418

419419
@memberSearchApiUrl@=https://tc-api.cloud.topcoder.com:8443/v3/members/_suggest/
420+
@groupMemberSearchApiUrl@=https://cockpit.cloud.topcoder.com/direct/group/member?handle=
421+
@groupMemberApiUrl@=http://172.18.0.1:8080/v3/groups/%d/members
420422
@directChallengeServicesApiUrl@=http://api.topcoder-dev.com/v3/direct/challenges
421423
@authorizationUrl@=http://api.topcoder-dev.com/v3/authorizations
422-
@ssoLoginUrl@=https://topcoder-dev.com/login/
424+
@ssoLoginUrl@=https://topcoder-dev.com/login/
425+
@userGroupsApiEndpoint@=http://172.18.0.1:8080/v3/groups

0 commit comments

Comments
 (0)