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

Commit 5a8d6bc

Browse files
committed
fix group challenge with read-only access
1 parent fbfc7d8 commit 5a8d6bc

File tree

8 files changed

+154
-43
lines changed

8 files changed

+154
-43
lines changed

services/contest_service_facade/src/java/main/com/topcoder/service/facade/contest/ContestServiceFacade.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
import com.topcoder.project.service.ScorecardReviewData;
3232
import com.topcoder.search.builder.SearchBuilderException;
3333
import com.topcoder.security.TCSubject;
34+
import com.topcoder.service.contest.eligibility.ContestEligibility;
35+
import com.topcoder.service.contest.eligibility.dao.ContestEligibilityPersistenceException;
3436
import com.topcoder.service.facade.contest.notification.ProjectNotification;
3537
import com.topcoder.service.payment.CreditCardPaymentData;
3638
import com.topcoder.service.payment.TCPurhcaseOrderPaymentData;
@@ -1666,4 +1668,14 @@ Set<Long> updatePreRegister(TCSubject tcSubject, SoftwareCompetition contest,
16661668
* @since 1.8.6
16671669
*/
16681670
public ProjectGroup[] getAllProjectGroups(TCSubject tcSubject) throws ContestServiceException;
1671+
1672+
/**
1673+
* Get group for a contest
1674+
*
1675+
* @param contestId contestId
1676+
* @param isStudio false
1677+
* @return
1678+
* @throws ContestServiceException
1679+
*/
1680+
public List<ProjectGroup> getGroupForContest(long contestId, boolean isStudio) throws ContestServiceException;
16691681
}

services/contest_service_facade/src/java/main/com/topcoder/service/facade/contest/ejb/ContestServiceFacadeBean.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9592,4 +9592,26 @@ private ProjectPayment addManualCopilotPayment(com.topcoder.management.resource.
95929592
newPayment.setResourceId(copilotResource.getId());
95939593
return projectPaymentManager.create(newPayment, String.valueOf(tcSubject.getUserId()));
95949594
}
9595+
9596+
/**
9597+
* Get group for a contest
9598+
*
9599+
* @param contestId contestId
9600+
* @param isStudio false
9601+
* @return
9602+
* @throws ContestServiceException
9603+
*/
9604+
public List<ProjectGroup> getGroupForContest(long contestId, boolean isStudio) throws ContestServiceException {
9605+
try {
9606+
List<ContestEligibility> ces = contestEligibilityManager.getContestEligibility(contestId, isStudio);
9607+
List<ProjectGroup> groupList = new ArrayList<ProjectGroup>();
9608+
for (ContestEligibility ce : ces) {
9609+
groupList.add(new ProjectGroup(((GroupContestEligibility) ce).getGroupId(), ""));
9610+
}
9611+
return groupList;
9612+
} catch (ContestEligibilityPersistenceException ce) {
9613+
logger.error("Failed to get security group for challenge id:" + contestId);
9614+
throw new ContestServiceException("Failed to get security group for challenge id:" + contestId);
9615+
}
9616+
}
95959617
}

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.topcoder.direct.services.view.util.SessionData;
2525
import com.topcoder.management.deliverable.Submission;
2626
import com.topcoder.management.project.Prize;
27+
import com.topcoder.management.project.ProjectGroup;
2728
import com.topcoder.management.resource.Resource;
2829
import com.topcoder.management.resource.ResourceRole;
2930
import com.topcoder.security.TCSubject;
@@ -342,11 +343,11 @@ public class GetContestAction extends ContestAction {
342343
private boolean admin;
343344

344345
/**
345-
* The registration end date.
346-
*/
347-
private String regEndDate;
348-
349-
/**
346+
* The registration end date.
347+
*/
348+
private String regEndDate;
349+
350+
/**
350351
* The submission end date.
351352
* @since 1.5
352353
*/
@@ -452,11 +453,16 @@ protected void executeAction() throws Exception {
452453
if (DirectUtils.isStudio(softwareCompetition)) {
453454
softwareCompetition.setType(CompetionType.STUDIO);
454455
}
456+
softwareCompetition.getProjectHeader().setGroups(DirectUtils.getGroupIdAndName(
457+
softwareCompetition.getProjectHeader().getGroups()));
458+
455459
setResult(softwareCompetition);
456-
regEndDate = DirectUtils.getDateString(DirectUtils.getRegistrationEndDate(softwareCompetition));
460+
regEndDate = DirectUtils.getDateString(DirectUtils.getRegistrationEndDate(softwareCompetition));
457461
subEndDate = DirectUtils.getDateString(DirectUtils.getSubmissionEndDate(softwareCompetition));
458462
contestEndDate = DirectUtils.getDateString(DirectUtils.getEndDate(softwareCompetition));
459463

464+
465+
460466
// depends on the type :
461467
// 1. if contest, store softwareCompetition in session
462468
// 2. if json data for contest, stops here since we are getting it
@@ -955,13 +961,13 @@ public void setType(TYPE type) {
955961
this.type = type;
956962
}
957963

958-
/**
959-
* Gets the registration end date.
960-
*/
961-
public String getRegEndDate() {
962-
return regEndDate;
963-
}
964-
964+
/**
965+
* Gets the registration end date.
966+
*/
967+
public String getRegEndDate() {
968+
return regEndDate;
969+
}
970+
965971
/**
966972
* Gets the submission end date.
967973
* @since 1.5

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,17 @@ public class SaveDraftContestAction extends ContestAction {
506506
*/
507507
private static final long APPIRIO_MANAGER_METADATA_KEY_ID = 15L;
508508

509+
/**
510+
* Private constant specifying administrator role.
511+
*/
512+
private static final String ADMIN_ROLE = "Cockpit Administrator";
513+
514+
/**
515+
* Private constant specifying administrator role.
516+
*/
517+
private static final String TC_STAFF_ROLE = "TC Staff";
518+
519+
509520
/**
510521
* </p>
511522
*
@@ -1056,8 +1067,13 @@ public boolean evaluate(Object object) {
10561067
}
10571068

10581069
//set groups
1070+
List<ProjectGroup> groupsList = new ArrayList<ProjectGroup>();
1071+
//read-only group we need to set it with current group
1072+
if (!DirectUtils.isRole(getCurrentUser(), ADMIN_ROLE) && !DirectUtils.isRole(getCurrentUser(), TC_STAFF_ROLE) && projectId > 0) {
1073+
groupsList = getContestServiceFacadeWithISE().getGroupForContest(projectId, false);
1074+
groups = null;
1075+
}
10591076
if (groups != null && groups.size() > 0) {
1060-
List<ProjectGroup> groupsList = new ArrayList<ProjectGroup>();
10611077
// get the TCSubject from session
10621078
ProjectGroup[] allProjectGroups = getContestServiceFacade().getAllProjectGroups(DirectStrutsActionsHelper.getTCSubjectFromSession());
10631079
for (String groupId : groups) {
@@ -1066,12 +1082,9 @@ public boolean evaluate(Object object) {
10661082
groupsList.add(projectGroup);
10671083
}
10681084
}
1069-
10701085
}
1071-
softwareCompetition.getProjectHeader().setGroups(groupsList);
1072-
} else {
1073-
softwareCompetition.getProjectHeader().setGroups(new ArrayList<ProjectGroup>());
10741086
}
1087+
softwareCompetition.getProjectHeader().setGroups(groupsList);
10751088

10761089
// remove the thurgood information if needed
10771090
if(softwareCompetition.getProjectHeader().getProperties().containsKey(THURGOOD_PLATFORM_KEY)) {

src/java/main/com/topcoder/direct/services/view/ajax/SoftwareCompetitionBeanProcessor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ public Object transform(Object object) {
319319
}
320320
}));
321321

322+
result.put("groupNames", CollectionUtils.collect(bean.getProjectHeader().getGroups(), new Transformer() {
323+
public Object transform(Object object) {
324+
return ((ProjectGroup) object).getName();
325+
}
326+
}));
327+
322328
// documentation
323329
result.put("documentation", CollectionUtils.collect(assetDTO.getDocumentation(), new Transformer() {
324330
public Object transform(Object object) {

src/java/main/com/topcoder/direct/services/view/util/DirectUtils.java

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@
3636
import com.topcoder.management.deliverable.Submission;
3737
import com.topcoder.management.deliverable.Upload;
3838
import com.topcoder.management.deliverable.persistence.UploadPersistenceException;
39-
import com.topcoder.management.project.CopilotContestExtraInfo;
40-
import com.topcoder.management.project.CopilotContestExtraInfoType;
41-
import com.topcoder.management.project.Prize;
42-
import com.topcoder.management.project.ProjectCopilotType;
43-
import com.topcoder.management.project.ProjectPropertyType;
44-
import com.topcoder.management.project.ProjectType;
39+
import com.topcoder.management.project.*;
4540
import com.topcoder.management.resource.Resource;
4641
import com.topcoder.management.resource.ResourceRole;
4742
import com.topcoder.management.review.data.Comment;
@@ -954,6 +949,9 @@ public final class DirectUtils {
954949

955950
private static final String QUERY_GET_USERS_FROM_ID = "SELECT user_id, handle FROM user WHERE user_id in (";
956951

952+
private static final String QUERY_GET_SECURITY_GROUP_FROM_ID = "SELECT group_id, description FROM security_groups " +
953+
" WHERE group_id in (";
954+
957955
/**
958956
* <p>
959957
* Default Constructor.
@@ -3790,4 +3788,48 @@ public static Map<Long, List<TermOfUse>> getUnAgreedProjectTermByUser(long proje
37903788
DatabaseUtils.close(con);
37913789
}
37923790
}
3791+
3792+
/**
3793+
* Get security Groups id and name from given projectGroup id
3794+
*
3795+
* @param projectGroups project group
3796+
* @return List <ProjectGroup> of security group
3797+
* @throws Exception
3798+
*/
3799+
public static List<ProjectGroup> getGroupIdAndName(List<ProjectGroup> projectGroups) throws Exception{
3800+
Connection con = null;
3801+
PreparedStatement ps = null;
3802+
ResultSet rs = null;
3803+
if (projectGroups == null || projectGroups.size() < 1){
3804+
return null;
3805+
}
3806+
3807+
try{
3808+
con = DatabaseUtils.getDatabaseConnection(DBMS.COMMON_OLTP_DATASOURCE_NAME);
3809+
StringBuilder sbQueryGids = new StringBuilder(QUERY_GET_SECURITY_GROUP_FROM_ID);
3810+
for (ProjectGroup pg : projectGroups){
3811+
sbQueryGids.append(" ?,");
3812+
}
3813+
sbQueryGids.setCharAt(sbQueryGids.length() - 1, ')');
3814+
3815+
ps = con.prepareStatement(sbQueryGids.toString());
3816+
3817+
for (int i = 0; i < projectGroups.size(); i++){
3818+
ps.setString(i + 1, String.valueOf(projectGroups.get(i).getId()));
3819+
}
3820+
rs = ps.executeQuery();
3821+
List<ProjectGroup> result = new ArrayList<ProjectGroup>();
3822+
while (rs.next()){
3823+
ProjectGroup pg = new ProjectGroup();
3824+
pg.setId(rs.getLong("group_id"));
3825+
pg.setName(rs.getString("description"));
3826+
result.add(pg);
3827+
}
3828+
return result;
3829+
}finally {
3830+
DatabaseUtils.close(rs);
3831+
DatabaseUtils.close(ps);
3832+
DatabaseUtils.close(con);
3833+
}
3834+
}
37933835
}

src/web/scripts/launch/contestDetailSoftware.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,13 @@ $(document).ready(function(){
207207
});
208208

209209
$(".cancel_text").click(function(){
210+
groupCancel = true;
210211
jQuery_1_11_1("#groups").magicSuggest().clear();
211-
if (mainWidget.softwareCompetition.groups.length > 0){
212-
jQuery_1_11_1("#groups").magicSuggest().setValue(mainWidget.softwareCompetition.groups);
213-
}
212+
jQuery_1_11_1("#groups").magicSuggest().setValue(mainWidget.softwareCompetition.groups);
213+
groupCancel = false;
214+
214215
jQuery_1_11_1("#preRegisterUsers").magicSuggest().clear();
215-
if (mainWidget.softwareCompetition.registrants.length > 0) {
216-
jQuery_1_11_1("#preRegisterUsers").magicSuggest().setValue(mainWidget.softwareCompetition.registrants);
217-
}
216+
jQuery_1_11_1("#preRegisterUsers").magicSuggest().setValue(mainWidget.softwareCompetition.registrants);
218217
populateTypeSection();
219218
showTypeSectionDisplay();
220219
});
@@ -875,6 +874,7 @@ function initContest(contestJson) {
875874
}
876875

877876
mainWidget.softwareCompetition.groups = contestJson.groupIds;
877+
mainWidget.softwareCompetition.groupNames = contestJson.groupNames;
878878

879879
var projectHeader = mainWidget.softwareCompetition.projectHeader;
880880
projectHeader.tcDirectProjectId = contestJson.tcDirectProjectId;
@@ -1212,6 +1212,17 @@ function initContest(contestJson) {
12121212
}
12131213

12141214
$(".drHide").hide();
1215+
1216+
if (securityGroups.length < 1 && mainWidget.softwareCompetition.groups.length > 0) {
1217+
var allGroups = [];
1218+
$.each(mainWidget.softwareCompetition.groups, function(i, val){
1219+
allGroups.push({id: val, name: mainWidget.softwareCompetition.groupNames[i]});
1220+
});
1221+
jQuery_1_11_1("#groups").magicSuggest().setData(allGroups);
1222+
}
1223+
1224+
jQuery_1_11_1("#groups").magicSuggest().setValue(mainWidget.softwareCompetition.groups);
1225+
12151226
}
12161227

12171228

@@ -1270,8 +1281,6 @@ function populateTypeSection() {
12701281
$('#rProjectName').text(mainWidget.softwareCompetition.projectHeader.tcDirectProjectName);
12711282
}
12721283

1273-
jQuery_1_11_1("#groups").magicSuggest().setValue(mainWidget.softwareCompetition.groups);
1274-
12751284
if (isF2F() || isDesignF2F()) {
12761285
var privateProject = p[TASK_FLAG];
12771286
var registrants = [];
@@ -1387,16 +1396,7 @@ function populateTypeSection() {
13871396

13881397
}
13891398

1390-
var groupMap = {};
1391-
$.each(securityGroups, function(i, val){
1392-
groupMap[''+val.id]=val.name;
1393-
});
1394-
var selectedGroupName = [];
1395-
$.each(mainWidget.softwareCompetition.groups, function(i, val){
1396-
selectedGroupName.push(groupMap[val]);
1397-
});
1398-
1399-
$('#rswGroups').html(selectedGroupName.join(", "));
1399+
$('#rswGroups').html(mainWidget.softwareCompetition.groupNames.join(", "));
14001400
}
14011401

14021402
/**
@@ -1453,6 +1453,11 @@ function saveTypeSection() {
14531453
success: function (jsonResult) {
14541454
handleSaveAsDraftContestResult(jsonResult);
14551455
mainWidget.softwareCompetition.groups = jQuery_1_11_1("#groups").magicSuggest().getValue();
1456+
mainWidget.softwareCompetition.groupNames=[];
1457+
$.each(jQuery_1_11_1("#groups").magicSuggest().getSelection(), function(i, val){
1458+
mainWidget.softwareCompetition.groupNames.push(val.name);
1459+
})
1460+
mainWidget.softwareCompetition.registrants = jQuery_1_11_1("#preRegisterUsers").magicSuggest().getSelection().slice();
14561461
populateTypeSection();
14571462
populateRoundSection();
14581463
if (mainWidget.competitionType == "SOFTWARE") {

src/web/scripts/launch/main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ var swDocuments = [];
203203
var REPORTING_ID = "36";
204204

205205
var securityGroups = [];
206+
var groupCancel = false;
206207
/**
207208
* Configuration/General Set up
208209
*/
@@ -232,9 +233,13 @@ $(document).ready(function() {
232233
var ms_group = jQuery_1_11_1("#groups").magicSuggest({
233234
placeholder: 'Type group name here',
234235
allowFreeEntries: false,
235-
data: securityGroups
236+
data: securityGroups,
237+
disabled: securityGroups.length > 0 ? false : true
236238
});
237239
jQuery_1_11_1(ms_group).on('selectionchange', function(e,m){
240+
if (groupCancel){
241+
return;
242+
}
238243
if (this.getValue().length > 0 && jQuery_1_11_1("#preRegisterUsers").magicSuggest().getValue().length > 0){
239244
displayWarning("#yesNoConfirmation", "Confirmation", "Changing group will remove all assigned members.\n" +
240245
"Do you want to proceed?", "OK", function(){

0 commit comments

Comments
 (0)