From ccb6a9fde2bdbb5e7143b96e8034e42b4e201076 Mon Sep 17 00:00:00 2001 From: Jim Eng Date: Thu, 15 Mar 2012 21:12:27 +0000 Subject: [PATCH] DASH-202 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 --- .../dash/logic/DashboardLogic.java | 14 ++++ .../dash/entity/ResourceSupport.java | 8 +- .../dash/logic/DashboardLogicImpl.java | 79 +++++++++++++++++++ 3 files changed, 100 insertions(+), 1 deletion(-) diff --git a/dashboard/api/src/java/org/sakaiproject/dash/logic/DashboardLogic.java b/dashboard/api/src/java/org/sakaiproject/dash/logic/DashboardLogic.java index 4353ec40168e..36c474e9229b 100644 --- a/dashboard/api/src/java/org/sakaiproject/dash/logic/DashboardLogic.java +++ b/dashboard/api/src/java/org/sakaiproject/dash/logic/DashboardLogic.java @@ -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 @@ -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 diff --git a/dashboard/impl/src/java/org/sakaiproject/dash/entity/ResourceSupport.java b/dashboard/impl/src/java/org/sakaiproject/dash/entity/ResourceSupport.java index b8c5b0c2e9d8..786a7be359e0 100644 --- a/dashboard/impl/src/java/org/sakaiproject/dash/entity/ResourceSupport.java +++ b/dashboard/impl/src/java/org/sakaiproject/dash/entity/ResourceSupport.java @@ -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); @@ -703,4 +708,5 @@ private void addContentNewsItem(Event event, ContentResource resource) { } } } + } diff --git a/dashboard/impl/src/java/org/sakaiproject/dash/logic/DashboardLogicImpl.java b/dashboard/impl/src/java/org/sakaiproject/dash/logic/DashboardLogicImpl.java index e28fe82e6ffa..2b1f3d29a6e6 100644 --- a/dashboard/impl/src/java/org/sakaiproject/dash/logic/DashboardLogicImpl.java +++ b/dashboard/impl/src/java/org/sakaiproject/dash/logic/DashboardLogicImpl.java @@ -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; @@ -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 existingLinks = dao.getSakaIdsForUserWithCalendarLinks(calendarItem.getEntityReference()); + if(existingLinks == null) { + existingLinks = new HashSet(); + } + + Set sakaiUserIds = new HashSet(); + if(calendarItem != null && calendarItem.getSourceType() != null && calendarItem.getSourceType().getAlwaysAccessPermission() != null && calendarItem.getSourceType().getAlwaysAccessPermission().length > 0) { + for(String permission : calendarItem.getSourceType().getAlwaysAccessPermission()) { + List 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) */ @@ -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 existingLinks = dao.getSakaiIdsForUserWithNewsLinks(newsItem.getEntityReference()); + if(existingLinks == null) { + existingLinks = new HashSet(); + } + + Set sakaiUserIds = new HashSet(); + if(newsItem != null && newsItem.getSourceType() != null && newsItem.getSourceType().getAlwaysAccessPermission() != null && newsItem.getSourceType().getAlwaysAccessPermission().length > 0) { + for(String permission : newsItem.getSourceType().getAlwaysAccessPermission()) { + List 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) @@ -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());