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

Commit a65c415

Browse files
authored
Merge pull request #270 from appirio-tech/dev
add permission check for groups feature
2 parents bce1998 + 5e7ad9c commit a65c415

File tree

5 files changed

+30
-65
lines changed

5 files changed

+30
-65
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1572,5 +1572,5 @@ Set<Long> updatePreRegister(TCSubject tcSubject, SoftwareCompetition contest,
15721572
* @throws ContestServiceException if any database related exception occur
15731573
* @since 1.8.6
15741574
*/
1575-
public ProjectGroup[] getAllProjectGroups() throws ContestServiceException;
1575+
public ProjectGroup[] getAllProjectGroups(TCSubject tcSubject) throws ContestServiceException;
15761576
}

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -9312,9 +9312,13 @@ public void cancelSoftwareContestByUser(TCSubject tcSubject, long projectId) thr
93129312
* @throws ContestServiceException if any database related exception occur
93139313
* @since 3.7
93149314
*/
9315-
public ProjectGroup[] getAllProjectGroups() throws ContestServiceException {
9315+
public ProjectGroup[] getAllProjectGroups(TCSubject tcSubject) throws ContestServiceException {
93169316
logger.debug("getAllProjectGroups");
93179317

9318+
if (!isRole(tcSubject, ADMIN_ROLE) && !isRole(tcSubject, TC_STAFF_ROLE)) {
9319+
return new ProjectGroup[0];
9320+
}
9321+
93189322
try {
93199323
return projectServices.getAllProjectGroups();
93209324
} catch (ProjectServicesException e) {

src/java/main/com/topcoder/direct/services/configs/ReferenceDataBean.java

+1-60
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.List;
1010
import java.util.Map;
1111

12-
import com.topcoder.management.project.ProjectGroup;
1312
import com.topcoder.management.project.ProjectPlatform;
1413
import org.apache.commons.lang.StringUtils;
1514
import org.springframework.beans.factory.InitializingBean;
@@ -28,15 +27,7 @@
2827
* </ul>
2928
* </p>
3029
*
31-
* <p>
32-
* Version 1.2 (TOPCODER - SUPPORT GROUPS CONCEPT FOR CHALLENGES) :
33-
* <ul>
34-
* <li>Added {@link #groups}list of all project_group_lu</li>
35-
* <li>Added {@link #groupMap}map project_group_id to its object</li>
36-
* <li>Updated {@link #afterPropertiesSet()} to set groups and groupMap</li>
37-
* </ul>
38-
* </p>
39-
* @version 1.2
30+
* @version 1.1
4031
* @author GreatKevin, TCSCODER
4132
*/
4233
public class ReferenceDataBean implements InitializingBean {
@@ -145,20 +136,6 @@ public class ReferenceDataBean implements InitializingBean {
145136
*/
146137
private Map<Long, List<Category>> catalogToCategoriesMap;
147138

148-
/**
149-
* Challenge groups
150-
*
151-
* @since 1.2
152-
*/
153-
private List<ProjectGroup> groups;
154-
155-
/**
156-
* Map of challenge group if to its object
157-
*
158-
* @since 1.2
159-
*/
160-
private Map<Long, ProjectGroup> groupMap;
161-
162139
/**
163140
* <p>
164141
* Gets the contest service facade.
@@ -335,36 +312,6 @@ public Map<Long, List<Category>> getCatalogToCategoriesMap() {
335312
return catalogToCategoriesMap;
336313
}
337314

338-
/**
339-
* Getter for {@link #groups}
340-
*
341-
* @return groups
342-
* @since 1.2
343-
*/
344-
public List<ProjectGroup> getGroups() {
345-
return groups;
346-
}
347-
348-
/**
349-
* Setter for {@link #groups}
350-
*
351-
* @param groups list of ProjectGroup
352-
* @since 1.2
353-
*/
354-
public void setGroups(List<ProjectGroup> groups) {
355-
this.groups = groups;
356-
}
357-
358-
/**
359-
* Getter for {@link #groupMap}
360-
*
361-
* @return groupMap
362-
* @since 1.2
363-
*/
364-
public Map<Long, ProjectGroup> getGroupMap() {
365-
return groupMap;
366-
}
367-
368315
/**
369316
* <p>
370317
* Initialization function. It will be called by Spring context.
@@ -393,12 +340,6 @@ public void afterPropertiesSet() throws Exception {
393340
platformMap.put(platform.getId(), platform);
394341
}
395342

396-
groups = Arrays.asList(getContestServiceFacade().getAllProjectGroups());
397-
groupMap = new HashMap<Long, ProjectGroup>();
398-
for (ProjectGroup group : groups) {
399-
groupMap.put(group.getId(), group);
400-
}
401-
402343
// categories
403344
categories = new ArrayList<Category>();
404345
categoryMap = new HashMap<Long, Category>();

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

+14-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.topcoder.service.facade.project.DAOFault;
3636
import org.apache.commons.lang3.StringEscapeUtils;
3737
import org.codehaus.jackson.map.ObjectMapper;
38+
import com.topcoder.management.project.ProjectGroup;
3839

3940
/**
4041
* <p>
@@ -324,7 +325,7 @@ public String getContestConfigs() throws Exception {
324325

325326
configs.put("copilotFees", ConfigUtils.getCopilotFees());
326327
configs.put("billingInfos", getBillingProjectInfos());
327-
configs.put("groups", getReferenceDataBean().getGroups());
328+
configs.put("groups", getAllProjectGroups());
328329
setResult(configs);
329330
return SUCCESS;
330331
}
@@ -446,6 +447,18 @@ private List<Map<String, Object>> getBillingProjectInfos() throws DAOFault {
446447
return billings;
447448
}
448449

450+
/**
451+
* <p>
452+
* Gets all project groups
453+
* </p>
454+
*
455+
* @return the billing project information. each project is represented in a map object.
456+
* @throws ContestServiceException if contest service exception occurs
457+
*/
458+
private List<ProjectGroup> getAllProjectGroups() throws ContestServiceException {
459+
return Arrays.asList(getContestServiceFacade().getAllProjectGroups(DirectStrutsActionsHelper.getTCSubjectFromSession()));
460+
}
461+
449462

450463
/**
451464
* <p>

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -1011,11 +1011,18 @@ public boolean evaluate(Object object) {
10111011
populateSoftwareCompetition(softwareCompetition);
10121012
}
10131013

1014-
//set group
1014+
//set groups
10151015
if (groups != null && groups.size() > 0) {
10161016
List<ProjectGroup> groupsList = new ArrayList<ProjectGroup>();
1017+
// get the TCSubject from session
1018+
ProjectGroup[] allProjectGroups = getContestServiceFacade().getAllProjectGroups(DirectStrutsActionsHelper.getTCSubjectFromSession());
10171019
for (String groupId : groups) {
1018-
groupsList.add(getReferenceDataBean().getGroupMap().get(Long.valueOf(groupId)));
1020+
for (ProjectGroup projectGroup : allProjectGroups) {
1021+
if (Long.valueOf(projectGroup.getId()).equals(groupId)) {
1022+
groupsList.add(projectGroup);
1023+
}
1024+
}
1025+
10191026
}
10201027
softwareCompetition.getProjectHeader().setGroups(groupsList);
10211028
} else {

0 commit comments

Comments
 (0)