Skip to content

Commit

Permalink
SAK-23733 - Fix external grade integration to show unprovided tool items
Browse files Browse the repository at this point in the history
A bug was introduced that would not allow externally maintained gradebook
items to be shown unless the tool implemented a provider. The default
behavior should be that a provider need only be implemented if the tool
wishes to exert some additional controls, such as group access, on which
items are included for specific student views and grades.

This change implements a solution that does this by asking providers to
also implement a method to list all items they are responsible for. This
list is compared to the items that should be visible and the items that
are not reported by any provider to preserve the default behavior that
was present in the 2.8 release.



git-svn-id: https://source.sakaiproject.org/svn/assignment/trunk@126908 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
botimer committed Jul 11, 2013
1 parent d17bb5b commit 0f9be52
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import org.sakaiproject.assignment.api.Assignment;
import org.sakaiproject.assignment.api.AssignmentService;
import org.sakaiproject.assignment.impl.BaseAssignmentService;
import org.sakaiproject.authz.api.AuthzGroup;
import org.sakaiproject.authz.api.AuthzGroupService;
import org.sakaiproject.authz.api.SecurityService;
Expand All @@ -43,11 +44,12 @@
import org.sakaiproject.exception.PermissionException;
import org.sakaiproject.site.api.SiteService;
import org.sakaiproject.service.gradebook.shared.ExternalAssignmentProvider;
import org.sakaiproject.service.gradebook.shared.ExternalAssignmentProviderCompat;
import org.sakaiproject.service.gradebook.shared.GradebookExternalAssessmentService;
import org.sakaiproject.tool.api.SessionManager;
import org.sakaiproject.tool.api.SessionManager;

public class AssignmentGradeInfoProvider implements ExternalAssignmentProvider {
public class AssignmentGradeInfoProvider implements ExternalAssignmentProvider, ExternalAssignmentProviderCompat {

private Log log = LogFactory.getLog(AssignmentGradeInfoProvider.class);

Expand Down Expand Up @@ -147,6 +149,25 @@ public List<String> getExternalAssignmentsForCurrentUser(String gradebookUid) {
return externalIds;
}

public List<String> getAllExternalAssignments(String gradebookUid) {
// We check and cast here on the very slim chance that something other than
// a BaseAssignmentService is registered as the service. If that is the case,
// we won't have access to the protected method to get unfiltered assignments
// and the best we can do is return the filtered list, which is exposed on
// the AssignmentService interface.

List<String> externalIds = new ArrayList<String>();
if (assignmentService instanceof BaseAssignmentService) {
List assignments = ((BaseAssignmentService) assignmentService).getUnfilteredAssignments(gradebookUid);
for (Assignment a : (List<Assignment>) assignments) {
externalIds.add(a.getReference());
}
} else {
externalIds = getExternalAssignmentsForCurrentUser(gradebookUid);
}
return externalIds;
}

public Map<String, List<String>> getAllExternalAssignments(String gradebookUid, Collection<String> studentIds) {
Map<String, List<String>> allExternals = new HashMap<String, List<String>>();
for (String studentId : studentIds) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1173,78 +1173,96 @@ private List assignments(String context, String userId)
}
else
{
List assignments = getUnfilteredAssignments(context);

if (userId == null)
{
userId = SessionManager.getCurrentSessionUserId();
}
List assignments = new ArrayList();

if ((m_caching) && (m_assignmentCache != null) && (!m_assignmentCache.disabled()))

// check for the site and group permissions of these assignments as well as visibility (release time, etc.)
rv = getAccessibleAssignments(assignments, context, userId);
}

return rv;
}

/**
* Access all assignment objects for a site without considering user permissions.
* This should be used with care; almost all scenarios should use {@link getAssignments(String)}
* or {@link getAssignments(String, String)}, which do enforce permissions and visibility.
*
* TODO: Decide whether or not this should be exposed as part of the public API.
*
* @return A list of Assignment objects.
*
*/
protected List getUnfilteredAssignments(String context)
{
List assignments = new ArrayList();

if ((m_caching) && (m_assignmentCache != null) && (!m_assignmentCache.disabled()))
{
// if the cache is complete, use it
if (m_assignmentCache.isComplete())
{
// if the cache is complete, use it
if (m_assignmentCache.isComplete())
{
assignments = m_assignmentCache.getAll();
// TODO: filter by context
}

// otherwise get all the assignments from storage
else
assignments = m_assignmentCache.getAll();
// TODO: filter by context
}

// otherwise get all the assignments from storage
else
{
// Note: while we are getting from storage, storage might change. These can be processed
// after we get the storage entries, and put them in the cache, and mark the cache complete.
// -ggolden
synchronized (m_assignmentCache)
{
// Note: while we are getting from storage, storage might change. These can be processed
// after we get the storage entries, and put them in the cache, and mark the cache complete.
// -ggolden
synchronized (m_assignmentCache)
// if we were waiting and it's now complete...
if (m_assignmentCache.isComplete())
{
// if we were waiting and it's now complete...
if (m_assignmentCache.isComplete())
{
assignments = m_assignmentCache.getAll();
return assignments;
}

// save up any events to the cache until we get past this load
m_assignmentCache.holdEvents();

assignments = m_assignmentStorage.getAll(context);

// update the cache, and mark it complete
for (int i = 0; i < assignments.size(); i++)
{
Assignment assignment = (Assignment) assignments.get(i);
m_assignmentCache.put(assignment.getReference(), assignment);
}

m_assignmentCache.setComplete();
// TODO: not reall, just for context

// now we are complete, process any cached events
m_assignmentCache.processEvents();
assignments = m_assignmentCache.getAll();
return assignments;
}

// save up any events to the cache until we get past this load
m_assignmentCache.holdEvents();

assignments = m_assignmentStorage.getAll(context);

// update the cache, and mark it complete
for (int i = 0; i < assignments.size(); i++)
{
Assignment assignment = (Assignment) assignments.get(i);
m_assignmentCache.put(assignment.getReference(), assignment);
}

m_assignmentCache.setComplete();
// TODO: not reall, just for context

// now we are complete, process any cached events
m_assignmentCache.processEvents();
}
}

else
{
// // if we have done this already in this thread, use that
// assignments = (List) CurrentService.getInThread(context+".assignment.assignments");
// if (assignments == null)
// {
assignments = m_assignmentStorage.getAll(context);
//
// // "cache" the assignments in the current service in case they are needed again in this thread...
// if (assignments != null)
// {
// CurrentService.setInThread(context+".assignment.assignments", assignments);
// }
// }
}

// check for the site and group permissions of these assignments as well as visibility (release time, etc.)
rv = getAccessibleAssignments(assignments, context, userId);
}

return rv;
else
{
// // if we have done this already in this thread, use that
// assignments = (List) CurrentService.getInThread(context+".assignment.assignments");
// if (assignments == null)
// {
assignments = m_assignmentStorage.getAll(context);
//
// // "cache" the assignments in the current service in case they are needed again in this thread...
// if (assignments != null)
// {
// CurrentService.setInThread(context+".assignment.assignments", assignments);
// }
// }
}

return assignments;
}

/**
Expand Down

0 comments on commit 0f9be52

Please sign in to comment.