Skip to content

Commit

Permalink
SAK-22238
Browse files Browse the repository at this point in the history
SAK-21523
SAK-21524

Fix the matrix/assignment integration so things work when you aren't in both sites.

git-svn-id: https://source.sakaiproject.org/svn/assignment/trunk@111458 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
maurercw committed Aug 14, 2012
1 parent 192aeab commit aada0a9
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,16 @@ public void removeAssignmentContent(AssignmentContentEdit content) throws Assign
*/
public String assignmentReference(String context, String id);

/**
* Access the internal reference which can be used to assess security clearance.
* This will make a database call, so might not be the best choice in every situation.
* But, if you don't have the context (site id) and need the reference, it's the only way to get it.
* @param id
* The assignment id string.
* @return The the internal reference which can be used to access the resource from within the system.
*/
public String assignmentReference(String id);

/**
* Access the internal reference which can be used to access the resource from within the system.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.sakaiproject.assignment.api.AssignmentService;
import org.sakaiproject.assignment.api.AssignmentSubmission;
import org.sakaiproject.assignment.api.Assignment.AssignmentAccess;
import org.sakaiproject.authz.api.SecurityAdvisor;
import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.entity.api.Entity;
Expand Down Expand Up @@ -510,16 +511,13 @@ public String getEntityPrefix() {
* @see org.sakaiproject.entitybroker.entityprovider.CoreEntityProvider#entityExists(java.lang.String)
*/
public boolean entityExists(String id) {
boolean rv = false;
try {
Assignment assignment = assignmentService.getAssignment(id);
if (assignment != null) {
rv = true;
}
} catch (Exception e) {
rv = false;
}
return rv;
boolean rv = false;
//This will look up the ref from the database, so if ref is not null, that means it found one.
String ref = assignmentService.assignmentReference(id);
if (ref != null) {
rv = true;
}
return rv;
}

/* (non-Javadoc)
Expand Down Expand Up @@ -837,7 +835,7 @@ public Map<String, String> getProperties(String reference) {
String parsedRef = reference;
String defaultView = "doView_submission";
String[] refParts = reference.split(Entity.SEPARATOR);
String submissionId = "";
String submissionId = "null"; //setting to the string null
String decWrapper = null;
String decWrapperTag = "";
String decSiteId = "";
Expand Down Expand Up @@ -865,7 +863,7 @@ public Map<String, String> getProperties(String reference) {

String assignmentId = parsedRef;
boolean canUserAccessWizardPageAndLinkedArtifcact = false;
if (!"".equals(decSiteId) && !"".equals(decPageId) && !"".equals(submissionId)) {
if (!"".equals(decSiteId) && !"".equals(decPageId) && !"null".equals(submissionId)) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("siteId", decSiteId);
params.put("pageId", decPageId);
Expand Down Expand Up @@ -914,22 +912,30 @@ public Map<String, String> getProperties(String reference) {
props.put("security.site.function", SiteService.SITE_VISIT);
props.put("security.site.ref", site.getReference());
props.put("security.assignment.function", AssignmentService.SECURE_ACCESS_ASSIGNMENT);
props.put("security.assignment.grade.function", AssignmentService.SECURE_GRADE_ASSIGNMENT_SUBMISSION);
props.put("security.assignment.grade.ref", assignment.getReference());

// OSP specific
if (("ospMatrix".equals(decWrapperTag) && canUserAccessWizardPageAndLinkedArtifcact)
|| "".equals(submissionId)) {
|| "null".equals(submissionId)) {

List<Reference> attachments = new ArrayList<Reference>();

if (!"".equals(submissionId)) {
if (!"null".equals(submissionId)) {
props.put("security.assignment.ref", submissionId);
SecurityAdvisor subAdv = new MySecurityAdvisor(
sessionManager.getCurrentSessionUserId(),
AssignmentService.SECURE_ACCESS_ASSIGNMENT_SUBMISSION,
submissionId);
SecurityAdvisor subAdv2 = new MySecurityAdvisor(
sessionManager.getCurrentSessionUserId(),
AssignmentService.SECURE_GRADE_ASSIGNMENT_SUBMISSION,
assignment.getReference());
try
{
// enable permission to access submission
securityService.pushAdvisor(new MySecurityAdvisor(
sessionManager.getCurrentSessionUserId(),
AssignmentService.SECURE_ACCESS_ASSIGNMENT_SUBMISSION,
submissionId));
securityService.pushAdvisor(subAdv);
securityService.pushAdvisor(subAdv2);
AssignmentSubmission as = assignmentService.getSubmission(submissionId);
attachments.addAll(as.getSubmittedAttachments());
attachments.addAll(as.getFeedbackAttachments());
Expand All @@ -941,7 +947,8 @@ public Map<String, String> getProperties(String reference) {
finally
{
// remove security advisor
securityService.popAdvisor();
securityService.popAdvisor(subAdv2);
securityService.popAdvisor(subAdv);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,20 @@ public String assignmentReference(String context, String id)
return retVal;

} // assignmentReference

/**
* I feel silly having to look up the entire assignment object just to get the reference,
* but if there's no context, that seems to be the only way to do it.
* @param id
* @return
*/
public String assignmentReference(String id) {
String ref = null;
Assignment assignment = findAssignment(id);
if (assignment != null)
ref = assignment.getReference();
return ref;
} // assignmentReference

public List getSortedGroupUsers(Group _g) {
List retVal = new ArrayList();
Expand Down Expand Up @@ -994,7 +1008,7 @@ private Assignment checkAssignmentAccessibleForUser(Assignment assignment, Strin
// always return for users can add assignent in the context
return assignment;
}
else if (allowAddSubmission(assignment.getContext()))
else
{
String deleted = assignment.getProperties().getProperty(ResourceProperties.PROP_ASSIGNMENT_DELETED);
if (deleted == null || "".equals(deleted))
Expand All @@ -1013,7 +1027,7 @@ && getSubmission(assignment.getReference(), UserDirectoryService.getCurrentUser(
return assignment;
}
}
return null;
throw new PermissionException(currentUserId, SECURE_ACCESS_ASSIGNMENT, assignment.getReference());
}

protected Assignment findAssignment(String assignmentReference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,22 @@ public String getActivityDetailUrl()
{
//String url = assignment.getUrl();
String url = ServerConfigurationService.getServerUrl() +
"/direct/assignment/" + assignment.getId() + "/doView_assignment?TB_iframe=true";
"/direct/assignment/" + assignment.getId() + "/doView_assignment";
return url;
}

public String getTypeName()
{
return producer.getName();
}

public boolean getUseDecoration()
{
return true;
}

public String getActivityDetailUrlParams() {
return "?TB_iframe=true";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ public TaggableActivity getActivity(String activityRef,
TaggableActivity activity = null;
if (checkReference(activityRef)) {
try {
activity = new AssignmentActivityImpl(assignmentService
.getAssignment(activityRef), this);
Assignment assignment = assignmentService.getAssignment(activityRef);
if (assignment != null)
activity = new AssignmentActivityImpl(assignment, this);
} catch (IdUnusedException iue) {
logger.error(iue.getMessage(), iue);
} catch (PermissionException pe) {
Expand Down
Loading

0 comments on commit aada0a9

Please sign in to comment.