Skip to content

Commit

Permalink
Merge branch 'develop-exo' into task-66028
Browse files Browse the repository at this point in the history
  • Loading branch information
azayati authored Sep 11, 2023
2 parents 9109be2 + c76bda0 commit b522c3c
Show file tree
Hide file tree
Showing 113 changed files with 3,951 additions and 476 deletions.
5 changes: 0 additions & 5 deletions component/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@
<groupId>org.exoplatform.commons</groupId>
<artifactId>commons-comet-service</artifactId>
</dependency>
<!--
Avoid adding deprecated JAR commons-juzu here
that is defined in commons-extensions.war as dependency
to simplify deleting it in one single place, where it's used.
-->

<dependency>
<groupId>org.exoplatform.commons</groupId>
Expand Down
3 changes: 2 additions & 1 deletion component/notification/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<groupId>org.exoplatform.social</groupId>
<version>6.5.x-exo-SNAPSHOT</version>
</parent>
<groupId>org.exoplatform.social</groupId>
<artifactId>social-component-notification</artifactId>
<name>eXo PLF:: Social Notification Component</name>
<description>eXo Social Notification Component</description>
Expand Down Expand Up @@ -58,9 +57,11 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<runOrder>alphabetical</runOrder>
<includes>
<include>**/InitContainerTestSuite.java</include>
<include>**/InitContainerWithSettingsTestSuite.java</include>
<include>**/InitContainerTestSuiteRest.java</include>
</includes>
</configuration>
</plugin>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/**
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2023 Meeds Association [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.meeds.social.notification.rest;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.exoplatform.services.rest.http.PATCH;
import java.util.List;

import javax.annotation.security.RolesAllowed;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.exoplatform.commons.api.notification.model.NotificationInfo;
import org.json.JSONArray;
import org.json.JSONObject;

import org.exoplatform.commons.api.notification.NotificationMessageUtils;
import org.exoplatform.commons.api.notification.model.WebNotificationFilter;
import org.exoplatform.commons.api.notification.service.WebNotificationService;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import org.exoplatform.services.rest.resource.ResourceContainer;
import org.exoplatform.services.security.ConversationState;

/**
* Provides REST Services in order to perform all read/write operations related
* to web notifications.
*/

@Path("notifications/webNotifications")
@Tag(name = "notifications/webNotifications", description = "Manage web notifications")
public class WebNotificationRestService implements ResourceContainer {

private static final Log LOG = ExoLogger.getLogger(WebNotificationRestService.class);

private WebNotificationService webNftService;

public WebNotificationRestService(WebNotificationService webNftService) {
this.webNftService = webNftService;
}

@GET
@RolesAllowed("users")
@Produces(MediaType.APPLICATION_JSON)
@Operation(
summary = "Get notifications list",
description = "This gets the list of the notifications",
method = "GET")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Notifications list returned"),
@ApiResponse(responseCode = "404", description = "Notifications list not found"),
@ApiResponse(responseCode = "500", description = "Internal server error") })
public Response getNotifications() {
int maxItemsInPopover = NotificationMessageUtils.getMaxItemsInPopover();
JSONArray notificationsJsonArray = new JSONArray();
JSONObject response = new JSONObject();
String currentUser = ConversationState.getCurrent().getIdentity().getUserId();
if (currentUser == null) {
return Response.status(Response.Status.UNAUTHORIZED).build();
}
List<String> notifications = webNftService.get(new WebNotificationFilter(currentUser, true), 0, maxItemsInPopover);
for (String notification : notifications) {
JSONObject notificationJsonObject = new JSONObject();
notificationJsonObject.put("notification", notification);
notificationsJsonArray.put(notificationJsonObject);
}
int badge = webNftService.getNumberOnBadge(currentUser);
response.put("notifications", notificationsJsonArray);
response.put("badge", badge);
return Response.ok(response.toString(), MediaType.APPLICATION_JSON).build();
}

@PATCH
@Path("{id}")
@Consumes(MediaType.TEXT_PLAIN)
@RolesAllowed("users")
@Operation(
summary = "Update notification",
description = "Perform some patch operations on notifications",
method = "PATCH")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Notification updated"),
@ApiResponse(responseCode = "400", description = "Invalid query input"),
@ApiResponse(responseCode = "500", description = "Internal server error") })
public Response updateNotifications(@Parameter(description = "notification operation", required = true) String operation,
@Parameter(description = "notification id", required = true) @PathParam("id") String notificationId) {

String currentUser = ConversationState.getCurrent().getIdentity().getUserId();
try {
if (operation == null) {
LOG.warn("Notification operation should be not null");
return Response.status(Response.Status.BAD_REQUEST).build();
}

if (currentUser == null) {
return Response.status(Response.Status.UNAUTHORIZED).build();
}

if (operation.equals("markAsRead")) {
if (notificationId == null) {
return Response.status(Response.Status.BAD_REQUEST).build();
} else {
NotificationInfo notification = webNftService.getNotificationInfo(notificationId);
if (currentUser.equals(notification.getTo())) {
webNftService.markRead(notificationId);
} else {
LOG.warn("User {} is not allowed to mark notification {} as read", currentUser, notificationId);
return Response.status(Response.Status.UNAUTHORIZED).build();

}
}
}

if (operation.equals("hide")) {
if (notificationId == null) {
return Response.status(Response.Status.BAD_REQUEST).build();
} else {
NotificationInfo notification = webNftService.getNotificationInfo(notificationId);
if (currentUser.equals(notification.getTo())) {
webNftService.hidePopover(notificationId);
} else {
LOG.warn("User {} is not allowed to hide notification {}", currentUser, notificationId);
return Response.status(Response.Status.UNAUTHORIZED).build();

}
}
}

if (operation.equals("resetNew")) {
webNftService.resetNumberOnBadge(currentUser);
}

if (operation.equals("markAllAsRead")) {
webNftService.markAllRead(currentUser);
webNftService.resetNumberOnBadge(currentUser);
}
return Response.noContent().build();
} catch (Exception e) {
LOG.error("Error when trying to patch operation {} on notification {} for user {}", operation, notificationId, currentUser, e);
return Response.serverError().build();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2023 Meeds Association [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.meeds.social.notification.rest.model;

public class ChannelActivationChoice {

private String channelId;

private String pluginId;

private boolean allowed;

private boolean active;

private boolean channelActive;

public ChannelActivationChoice(String channelId,
String pluginId,
boolean allowed,
boolean active,
boolean channelActive) {
this.channelId = channelId;
this.pluginId = pluginId;
this.allowed = allowed;
this.active = active;
this.channelActive = channelActive;
}

public String getChannelId() {
return channelId;
}

public void setChannelId(String channelId) {
this.channelId = channelId;
}

public String getPluginId() {
return pluginId;
}

public void setPluginId(String pluginId) {
this.pluginId = pluginId;
}

public boolean isActive() {
return active;
}

public void setActive(boolean active) {
this.active = active;
}

public boolean isAllowed() {
return allowed;
}

public void setAllowed(boolean allowed) {
this.allowed = allowed;
}

public boolean isChannelActive() {
return channelActive;
}

public void setChannelActive(boolean channelActive) {
this.channelActive = channelActive;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2023 Meeds Association [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.meeds.social.notification.rest.model;

public class EmailDigestChoice {
String channelId;

String pluginId;

String value;

boolean channelActive;

public EmailDigestChoice(String channelId,
String pluginId,
String value,
boolean channelActive) {
this.channelId = channelId;
this.pluginId = pluginId;
this.value = value;
this.channelActive = channelActive;
}

public String getChannelId() {
return channelId;
}

public void setChannelId(String channelId) {
this.channelId = channelId;
}

public String getPluginId() {
return pluginId;
}

public void setPluginId(String pluginId) {
this.pluginId = pluginId;
}

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

public boolean isChannelActive() {
return channelActive;
}

public void setChannelActive(boolean channelActive) {
this.channelActive = channelActive;
}

}
Loading

0 comments on commit b522c3c

Please sign in to comment.