Skip to content

Commit

Permalink
SAK-46120 Lessons show notifications when comments added (sakaiprojec…
Browse files Browse the repository at this point in the history
…t#12898)

Co-authored-by: Earle Nietzel <[email protected]>
  • Loading branch information
adrianfish and ern authored Sep 26, 2024
1 parent 0ca9167 commit a07a023
Show file tree
Hide file tree
Showing 56 changed files with 200 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5503,8 +5503,6 @@
# ###############################
# Rubrics
# ###############################
# The secret shared between Sakai and the rubrics service to secure JWTs
rubrics.integration.token-secret=12345678900909091234

# Allows the instructors to export a rubric to PDF
# Default: true
Expand Down
4 changes: 0 additions & 4 deletions docker/deploy/config/sakai.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@ hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
[email protected]=jdbc:mysql://mysql:3306/sakai?useUnicode=true&characterEncoding=UTF-8
[email protected]=select 1 from DUAL
[email protected]=TRANSACTION_READ_COMMITTED

## Rubrics
rubrics.integration.token-secret=12345678900909091234

4 changes: 0 additions & 4 deletions docker/deploy/secrets/security.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,3 @@
####
[email protected]=sakai
[email protected]=examplepassword

# Rubrics secret token
####
rubrics.integration.token-secret=12345678900909091234
4 changes: 0 additions & 4 deletions docker/dev/CONFIG/sakai/sakai.nosearch.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,3 @@ [email protected]=1025
# the entrypoint script.
####
search.enable=false

# Rubrics secret token
####
rubrics.integration.token-secret=12345678900909091234
5 changes: 0 additions & 5 deletions docker/dev/CONFIG/sakai/sakai.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,3 @@ elasticsearch.discovery.zen.ping.multicast.enabled=false
elasticsearch.transport.tcp.port=9300
elasticsearch.discovery.zen.ping.unicast.hosts=127.0.0.1:9300
search.indexNamespace=sakai_search_index


# Rubrics secret token
####
rubrics.integration.token-secret=12345678900909091234
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,10 @@
public class FunctionManagerComponent implements FunctionManager
{
/** List of security functions. */
protected List<String> m_registeredFunctions = new Vector<String>();
protected List<String> m_registeredFunctions = new Vector<>();

/** List of user-mutable security functions. */
protected List<String> m_registeredUserMutableFunctions = new Vector<String>();


/**********************************************************************************************************************************************************************************************************************************************************
* Dependencies and their setter methods
*********************************************************************************************************************************************************************************************************************************************************/

/**********************************************************************************************************************************************************************************************************************************************************
* Init and Destroy
*********************************************************************************************************************************************************************************************************************************************************/
protected List<String> m_registeredUserMutableFunctions = new Vector<>();

/**
* Final initialization, once all dependencies are set.
Expand All @@ -73,17 +64,13 @@ public void destroy()
* Work interface methods: FunctionMananger
*********************************************************************************************************************************************************************************************************************************************************/

/**
* {@inheritDoc}
*/
@Override
public void registerFunction(String function)
{
registerFunction(function, false);
}

/**
* {@inheritDoc}
*/
@Override
public void registerFunction(String function, boolean userMutable) {
if (function == null) return;

Expand All @@ -94,20 +81,16 @@ public void registerFunction(String function, boolean userMutable) {
}
}

/**
* {@inheritDoc}
*/
@Override
public List<String> getRegisteredFunctions()
{
return new Vector<String>(m_registeredFunctions);
return new Vector<>(m_registeredFunctions);
}

/**
* {@inheritDoc}
*/
@Override
public List<String> getRegisteredFunctions(String prefix)
{
List<String> rv = new Vector<String>();
List<String> rv = new Vector<>();

for (String function : m_registeredFunctions)
{
Expand All @@ -120,19 +103,15 @@ public List<String> getRegisteredFunctions(String prefix)
return rv;
}

/**
* {@inheritDoc}
*/
@Override
public List<String> getRegisteredUserMutableFunctions() {
return new Vector<String>(m_registeredUserMutableFunctions);
return new Vector<>(m_registeredUserMutableFunctions);
}

/**
* {@inheritDoc}
*/
@Override
public List<String> getRegisteredUserMutableFunctions(String prefix) {

List<String> rv = new Vector<String>();
List<String> rv = new Vector<>();

for (String function : m_registeredUserMutableFunctions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,17 @@ public void update(Observable o, final Object arg) {
try {
UserNotificationHandler handler = handlerMap.get(event);
if (handler != null) {
Optional<List<UserNotificationData>> result = handler.handleEvent(e);
if (result.isPresent()) {
result.get().forEach(bd -> {
handler.handleEvent(e).ifPresent(notifications -> {

notifications.forEach(bd -> {
UserNotification un = doInsert(from, bd.getTo(), event, ref, bd.getTitle(),
bd.getSiteId(), e.getEventTime(), finalDeferred, bd.getUrl(), bd.getCommonToolId());
if (!finalDeferred && this.pushEnabled) {
un.setTool(bd.getCommonToolId());
push(decorateNotification(un));
}
});
}
});
} else if (SiteService.EVENT_SITE_PUBLISH.equals(event)) {
final String siteId = pathParts[2];

Expand Down
11 changes: 11 additions & 0 deletions lessonbuilder/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-kernel-api</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>sakai-kernel-util</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand All @@ -43,4 +47,11 @@
<artifactId>hibernate-core</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${basedir}/src/resources</directory>
</resource>
</resources>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -958,3 +958,5 @@ simplepage.advanced.content.items = Advanced Content Items
simplepage.layout.elements = Layout Elements
simplepage.max-file-upload-size=The upload size limit of
simplepage.max-file-upload-size-save=MB has been exceeded. Remove one or more files below to proceed. Other files may be uploaded assuming the total file size does not exceed this limit.

lessons_comment=Lessons Comment
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sakaiproject.lessonbuildertool.api;
package org.sakaiproject.lessonbuildertool.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import javax.annotation.Resource;

import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.event.api.Event;
import org.sakaiproject.lessonbuildertool.api.LessonBuilderConstants;
import org.sakaiproject.lessonbuildertool.api.LessonBuilderEvents;
import org.sakaiproject.lessonbuildertool.SimplePage;
import org.sakaiproject.lessonbuildertool.SimplePageComment;
import org.sakaiproject.lessonbuildertool.model.SimplePageToolDao;
import org.sakaiproject.messaging.api.UserNotificationData;
import org.sakaiproject.messaging.api.AbstractUserNotificationHandler;
import org.sakaiproject.messaging.api.UserNotificationHandler;
import org.sakaiproject.user.api.User;
import org.sakaiproject.util.ResourceLoader;

import org.springframework.stereotype.Component;

import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class AddLessonsCommentUserNotificationHandler extends AbstractUserNotificationHandler {
@Setter
public class AddLessonsCommentUserNotificationHandlerImpl implements UserNotificationHandler {

@Resource(name = "org.sakaiproject.lessonbuildertool.model.SimplePageToolDao")
private ResourceLoader resourceLoader;
private SimplePageToolDao simplePageToolDao;
private SecurityService securityService;

@Override
public List<String> getHandledEvents() {
Expand Down Expand Up @@ -70,7 +72,7 @@ public Optional<List<UserNotificationData>> handleEvent(Event e) {
for (User receiver : receivers) {
String to = receiver.getId();
if (!to.equals(from)) {
bhEvents.add(new UserNotificationData(from, to, context, "title", url, LessonBuilderConstants.TOOL_ID));
bhEvents.add(new UserNotificationData(from, to, context, resourceLoader.getString("lessons_comment"), url, LessonBuilderConstants.TOOL_ID));
done.add(to);
}
}
Expand All @@ -85,7 +87,7 @@ public Optional<List<UserNotificationData>> handleEvent(Event e) {
for (SimplePageComment c : comments) {
String to = c.getAuthor();
if (!to.equals(from) && !done.contains(to)) {
bhEvents.add(new UserNotificationData(from, to, context, "title", url, LessonBuilderConstants.TOOL_ID));
bhEvents.add(new UserNotificationData(from, to, context, resourceLoader.getString("lessons_comment"), url, LessonBuilderConstants.TOOL_ID));
done.add(to);
}
}
Expand All @@ -96,7 +98,7 @@ public Optional<List<UserNotificationData>> handleEvent(Event e) {

return Optional.of(bhEvents);
} catch (NumberFormatException nfe) {
log.error("Caught number format exception whilst handling events", nfe);
log.warn("Caught number format exception whilst handling events: {}", nfe.toString());
}

return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,25 +692,16 @@ public boolean saveItem(final Object o, List<String>elist, String nowriteerr, bo
updateStudentPage(o);
}

TransactionSynchronizationManager.registerSynchronization(
new TransactionSynchronizationAdapter() {

@Override
public void afterCommit() {

if (o instanceof SimplePageItem) {
SimplePageItem item = (SimplePageItem)o;
eventTrackingService.post(eventTrackingService.newEvent(LessonBuilderEvents.ITEM_CREATE, "/lessonbuilder/item/" + item.getId(), true));
} else if (o instanceof SimplePage) {
SimplePage page = (SimplePage)o;
eventTrackingService.post(eventTrackingService.newEvent(LessonBuilderEvents.PAGE_CREATE, "/lessonbuilder/page/" + page.getPageId(), true));
} else if (o instanceof SimplePageComment) {
SimplePageComment comment = (SimplePageComment)o;
eventTrackingService.post(eventTrackingService.newEvent(LessonBuilderEvents.COMMENT_CREATE, "/lessonbuilder/comment/" + comment.getId(), true));
}
}
}
);
if (o instanceof SimplePageItem) {
SimplePageItem item = (SimplePageItem)o;
eventTrackingService.post(eventTrackingService.newEvent(LessonBuilderEvents.ITEM_CREATE, "/lessonbuilder/item/" + item.getId(), true));
} else if (o instanceof SimplePage) {
SimplePage page = (SimplePage)o;
eventTrackingService.post(eventTrackingService.newEvent(LessonBuilderEvents.PAGE_CREATE, "/lessonbuilder/page/" + page.getPageId(), true));
} else if (o instanceof SimplePageComment) {
SimplePageComment comment = (SimplePageComment)o;
eventTrackingService.post(eventTrackingService.newEvent(LessonBuilderEvents.COMMENT_CREATE, "/lessonbuilder/comment/" + comment.getId(), true));
}

return true;
} catch (org.springframework.dao.DataIntegrityViolationException e) {
Expand Down
Loading

0 comments on commit a07a023

Please sign in to comment.