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

Commit 3b01230

Browse files
committed
add permission check for groups
1 parent 76fc847 commit 3b01230

File tree

5 files changed

+29
-42
lines changed

5 files changed

+29
-42
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 0 additions & 37 deletions
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;
@@ -335,36 +334,6 @@ public Map<Long, List<Category>> getCatalogToCategoriesMap() {
335334
return catalogToCategoriesMap;
336335
}
337336

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-
368337
/**
369338
* <p>
370339
* Initialization function. It will be called by Spring context.
@@ -393,12 +362,6 @@ public void afterPropertiesSet() throws Exception {
393362
platformMap.put(platform.getId(), platform);
394363
}
395364

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-
402365
// categories
403366
categories = new ArrayList<Category>();
404367
categoryMap = new HashMap<Long, Category>();

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

Lines changed: 14 additions & 1 deletion
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 DAOFault if a DAO error occurs
457+
*/
458+
private List<ProjectGroup> getAllProjectGroups() throws DAOFault {
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

Lines changed: 9 additions & 2 deletions
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)