Skip to content

Commit

Permalink
DASH-202
Browse files Browse the repository at this point in the history
Adding methods to add links for maintainers when an entity is not "available".


git-svn-id: https://source.sakaiproject.org/svn/dashboard/trunk@313186 66ffb92e-73f9-0310-93c1-f5514f145a0a
  • Loading branch information
jimeng committed Mar 15, 2012
1 parent cd86d27 commit ccb6a9f
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ public interface DashboardLogic {
*/
public void addCalendarLinks(String sakaiUserId, String contextId);

/**
* Add links to a calendar item for users who can see it even when it is hidden or in draft mode (i.e. not "available").
* Also removes links for any users who do not have adequate permissions to see the entity when it is not available.
* @param calendarItem
*/
public void addCalendarLinksForMaintainers(CalendarItem calendarItem);

/**
* Add links to news items in a context for a particular user. Links
* will be limited to items referencing entities for which the user has
Expand All @@ -81,6 +88,13 @@ public interface DashboardLogic {
*/
public void addNewsLinks(String sakaiUserId, String contextId);

/**
* Add links to a news item for users who can see it even when it is hidden or in draft mode (i.e. not "available").
* Also removes links for any users who do not have adequate permissions to see the entity when it is not available.
* @param newsItem
*/
public void addNewsLinksForMaintainers(NewsItem newsItem);

/**
* Creates and persists a CalendarItem with specified attributes. Returns the complete CalendarItem object.
* @param title
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,12 @@ private void addContentNewsItem(Event event, ContentResource resource) {
dashboardLogic.scheduleAvailabilityCheck(newsItem.getEntityReference(), RESOURCE_TYPE_IDENTIFIER, retractDate);
}
} else {

// verify that users with permissions in alwaysAllowPermission have links and others do not
if(sourceType != null && sourceType.getAlwaysAccessPermission() != null && sourceType.getAlwaysAccessPermission().length > 0) {

dashboardLogic.addNewsLinksForMaintainers(newsItem);
}
// schedule availability checks
Date releaseDate = getReleaseDate(newsItem.getEntityReference());
if(releaseDate != null && releaseDate.after(new Date())) {
dashboardLogic.scheduleAvailabilityCheck(newsItem.getEntityReference(), RESOURCE_TYPE_IDENTIFIER, releaseDate);
Expand All @@ -703,4 +708,5 @@ private void addContentNewsItem(Event event, ContentResource resource) {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -269,6 +270,44 @@ public void addCalendarLinks(String sakaiUserId, String contextId) {

}

/* (non-Javadoc)
* @see org.sakaiproject.dash.logic.DashboardLogic#addCalendarLinksForMaintainers(org.sakaiproject.dash.model.CalendarItem)
*/
public void addCalendarLinksForMaintainers(CalendarItem calendarItem) {
// get a list of existing links to the item
Set<String> existingLinks = dao.getSakaIdsForUserWithCalendarLinks(calendarItem.getEntityReference());
if(existingLinks == null) {
existingLinks = new HashSet<String>();
}

Set<String> sakaiUserIds = new HashSet<String>();
if(calendarItem != null && calendarItem.getSourceType() != null && calendarItem.getSourceType().getAlwaysAccessPermission() != null && calendarItem.getSourceType().getAlwaysAccessPermission().length > 0) {
for(String permission : calendarItem.getSourceType().getAlwaysAccessPermission()) {
List<String> userNames = sakaiProxy.getUsersWithReadAccess(calendarItem.getEntityReference(), permission);
if(userNames != null && userNames.size() > 0) {
sakaiUserIds.addAll(userNames);
}
}
for(String sakaiUserId : sakaiUserIds) {
// if this user already has a link, don't add a new link & delete that link from the list of existing links
if(existingLinks.contains(sakaiUserId)) {
// no need to add a link
existingLinks.remove(sakaiUserId);
} else {
Person person = this.getOrCreatePerson(sakaiUserId);
CalendarLink link = new CalendarLink(person, calendarItem, calendarItem.getContext(), false, false);
dao.addCalendarLink(link);
}
}
}

// if there are any links still in the list of existing links, delete them from the database
for(String sakaiUserId : existingLinks) {
Person person = dao.getPersonBySakaiId(sakaiUserId);
dao.deleteCalendarLink(person.getId(), calendarItem.getId());
}
}

/* (non-Javadoc)
* @see org.sakaiproject.dash.logic.DashboardLogic#addNewsLinks(java.lang.String, java.lang.String)
*/
Expand Down Expand Up @@ -302,6 +341,44 @@ public void addNewsLinks(String sakaiUserId, String contextId) {
}
}
}

/* (non-Javadoc)
* @see org.sakaiproject.dash.logic.DashboardLogic#addNewsLinksForMaintainers(org.sakaiproject.dash.model.NewsItem)
*/
public void addNewsLinksForMaintainers(NewsItem newsItem) {
// get a list of existing links to the item
Set<String> existingLinks = dao.getSakaiIdsForUserWithNewsLinks(newsItem.getEntityReference());
if(existingLinks == null) {
existingLinks = new HashSet<String>();
}

Set<String> sakaiUserIds = new HashSet<String>();
if(newsItem != null && newsItem.getSourceType() != null && newsItem.getSourceType().getAlwaysAccessPermission() != null && newsItem.getSourceType().getAlwaysAccessPermission().length > 0) {
for(String permission : newsItem.getSourceType().getAlwaysAccessPermission()) {
List<String> userNames = sakaiProxy.getUsersWithReadAccess(newsItem.getEntityReference(), permission);
if(userNames != null && userNames.size() > 0) {
sakaiUserIds.addAll(userNames);
}
}
for(String sakaiUserId : sakaiUserIds) {
// if this user already has a link, don't add a new link & delete that link from the list of existing links
if(existingLinks.contains(sakaiUserId)) {
// no need to add a link
existingLinks.remove(sakaiUserId);
} else {
Person person = this.getOrCreatePerson(sakaiUserId);
NewsLink link = new NewsLink(person, newsItem, newsItem.getContext(), false, false);
dao.addNewsLink(link);
}
}
}

// if there are any links still in the list of existing links, delete them from the database
for(String sakaiUserId : existingLinks) {
Person person = dao.getPersonBySakaiId(sakaiUserId);
dao.deleteNewsLink(person.getId(), newsItem.getId());
}
}

/* (non-Javadoc)
* @see org.sakaiproject.dash.logic.DashboardLogic#createCalendarItem(java.lang.String, java.util.Date, java.lang.String, java.lang.String, org.sakaiproject.dash.model.Context, org.sakaiproject.dash.model.SourceType, java.lang.String, org.sakaiproject.dash.model.RepeatingCalendarItem, java.lang.Integer)
Expand Down Expand Up @@ -1233,6 +1310,8 @@ protected void handleAvailabilityChecks() {
createNewsLinks(newsItem);
}
} else {
// verify that users with permissions in alwaysAllowPermission have links and others do not

// need to remove all links, if there are any
this.removeCalendarLinks(check.getEntityReference());
this.removeNewsLinks(check.getEntityReference());
Expand Down

0 comments on commit ccb6a9f

Please sign in to comment.