Skip to content

Commit

Permalink
Merge Mip-119 - Meeds-io/MIPs#119 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
azayati authored May 7, 2024
2 parents 873a6c7 + 133fc0c commit 83c1ed2
Show file tree
Hide file tree
Showing 56 changed files with 2,018 additions and 350 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import io.meeds.news.service.NewsService;
import io.meeds.news.utils.NewsUtils;

import static io.meeds.news.utils.NewsUtils.NewsObjectType.ARTICLE;

public class ActivityNewsProcessor extends BaseActivityProcessorPlugin {

private static final Log LOG = ExoLogger.getLogger(ActivityNewsProcessor.class);
Expand All @@ -58,7 +60,7 @@ public void processActivity(ExoSocialActivity activity) {
News news = (News) activity.getLinkedProcessedEntities().get("news");
if (news == null) {
try {
news = newsService.getNewsById(activity.getTemplateParams().get("newsId"), false);
news = newsService.getNewsArticleById(activity.getTemplateParams().get("newsId"));

RealtimeListAccess<ExoSocialActivity> listAccess = activityManager.getCommentsWithListAccess(activity, true);
news.setCommentsCount(listAccess.getSize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import io.meeds.news.service.NewsService;
import io.meeds.news.utils.NewsUtils;

import static io.meeds.news.utils.NewsUtils.NewsObjectType.ARTICLE;

/**
* A triggered listener class about activity lifecyles. This class is used to
* propagate sharing activity in News elements to let targeted space members to
Expand Down Expand Up @@ -76,8 +78,8 @@ public void shareActivity(ActivityLifeCycleEvent event) {
String newsId = originalActivity.getTemplateParams().get(NEWS_ID);
org.exoplatform.services.security.Identity currentIdentity = ConversationState.getCurrent().getIdentity();
try {
News news = newsService.getNewsById(newsId, currentIdentity, false);
if (news != null) {
News news = newsService.getNewsById(newsId, currentIdentity, false, ARTICLE.name().toLowerCase());
if (news != null && !news.isDeleted()) {
Identity posterIdentity = getIdentity(sharedActivity);
Space space = getSpace(sharedActivity);
newsService.shareNews(news, space, posterIdentity, sharedActivity.getId());
Expand Down
2 changes: 2 additions & 0 deletions content-service/src/main/java/io/meeds/news/model/News.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,6 @@ public class News {
private List<String> targets;

private boolean favorite;

private boolean deleted;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2024 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.news.model;

import org.exoplatform.social.metadata.model.MetadataObject;

public class NewsLatestDraftObject extends MetadataObject {

public NewsLatestDraftObject() {
}

public NewsLatestDraftObject(String objectType, String objectId, String parentObjectId, long spaceId) {
super(objectType, objectId, parentObjectId, spaceId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2024 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.news.model;

import org.exoplatform.social.metadata.model.MetadataObject;

public class NewsPageObject extends MetadataObject {

public NewsPageObject() {
}

public NewsPageObject(String objectType, String objectId, String parentObjectId, long spaceId) {
super(objectType, objectId, parentObjectId, spaceId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2020 - 2024 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.news.model;

import org.exoplatform.social.metadata.model.MetadataObject;

public class NewsPageVersionObject extends MetadataObject {

public NewsPageVersionObject() {
}

public NewsPageVersionObject(String objectType, String objectId, String parentObjectId, Long spaceId) {
super(objectType, objectId, parentObjectId, spaceId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public class NewsTargetObject extends MetadataObject {
public NewsTargetObject() {
}

public NewsTargetObject(String objectType, String objectId, String parentObjectId) {
super(objectType, objectId, parentObjectId);
public NewsTargetObject(String objectType, String objectId, String parentObjectId, Long spaceId) {
super(objectType, objectId, parentObjectId, spaceId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected MessageInfo makeMessage(NotificationContext ctx) {
String contentSpaceName = notification.getValueOwnerParameter(NotificationConstants.CONTENT_SPACE);
String authorAvatarUrl = notification.getValueOwnerParameter(NotificationConstants.AUTHOR_AVATAR_URL);
String baseUrl = PropertyManager.getProperty("gatein.email.domain.url");
String illustrationUrl = baseUrl.concat("/news/images/newsImageDefault.png");
String illustrationUrl = baseUrl.concat("/content/images/newsImageDefault.png");
String activityLink = notification.getValueOwnerParameter(NotificationConstants.ACTIVITY_LINK);
String context = notification.getValueOwnerParameter(NotificationConstants.CONTEXT);

Expand Down Expand Up @@ -150,6 +150,7 @@ protected MessageInfo makeMessage(NotificationContext ctx) {
templateContext.put("FIRST_NAME", encoder.encode(receiver.getProfile().getProperty(Profile.FIRST_NAME).toString()));
// Footer
templateContext.put("FOOTER_LINK", LinkProviderUtils.getRedirectUrl("notification_settings", receiver.getRemoteId()));
templateContext.put("COMPANY_LINK", LinkProviderUtils.getBaseUrl());
String subject = TemplateUtils.processSubject(templateContext);
String body = TemplateUtils.processGroovy(templateContext);
// binding the exception throws by processing template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;

import static io.meeds.news.utils.NewsUtils.NewsObjectType.ARTICLE;

@Path("v1/news")
@Tag(name = "v1/news", description = "Managing news")
public class NewsRestResourcesV1 implements ResourceContainer, Startable {
Expand Down Expand Up @@ -158,7 +160,7 @@ public void stop() {
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("users")
@Operation(summary = "Create a news", method = "POST", description = "This creates the news if the authenticated user is a member of the space or a spaces super manager. The news is created in draft status, unless the publicationState property is set to 'published'.")
@Operation(summary = "Create a news", method = "POST", description = "This creates the news if the authenticated user is a member of the space or a spaces super manager. The news is created in draft status, unless the publicationState property is set to 'posted'.")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "News created"),
@ApiResponse(responseCode = "400", description = "Invalid query input"),
@ApiResponse(responseCode = "401", description = "User not authorized to create the news"),
Expand Down Expand Up @@ -238,6 +240,10 @@ public Response updateNews(@Parameter(description = "News id", required = true)
@Parameter(description = "News object type to be updated", required = false)
@QueryParam("type")
String newsObjectType,
@Parameter(description = "News update action type to be done", required = false)
@Schema(defaultValue = "content")
@QueryParam("newsUpdateType")
String newsUpdateType,
@RequestBody(description = "News object to be updated", required = true)
News updatedNews) {

Expand All @@ -261,11 +267,11 @@ public Response updateNews(@Parameter(description = "News id", required = true)
news.setTargets(updatedNews.getTargets());
news.setAudience(updatedNews.getAudience());

news = newsService.updateNews(news, currentIdentity.getUserId(), post, updatedNews.isPublished(), newsObjectType);
news = newsService.updateNews(news, currentIdentity.getUserId(), post, updatedNews.isPublished(), newsObjectType, newsUpdateType);

return Response.ok(news).build();
} catch (IllegalAccessException e) {
LOG.warn("User '{}' is not autorized to update news", currentIdentity.getUserId(), e);
LOG.warn("User '{}' is not authorized to update news", currentIdentity.getUserId(), e);
return Response.status(Response.Status.UNAUTHORIZED).entity(e.getMessage()).build();
} catch (Exception e) {
LOG.error("Error when updating the news " + id, e);
Expand Down Expand Up @@ -303,7 +309,7 @@ public Response deleteNews(@Context
currentIdentity,
false,
isDraft ? NewsObjectType.DRAFT.name().toLowerCase()
: NewsObjectType.ARTICLE.name().toLowerCase());
: ARTICLE.name().toLowerCase());
if (news == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
Expand Down Expand Up @@ -403,7 +409,7 @@ public Response getNewsById(@Context
}
org.exoplatform.services.security.Identity currentIdentity = ConversationState.getCurrent().getIdentity();
News news = newsService.getNewsById(id, currentIdentity, editMode, newsObjectType);
if (news == null) {
if (news == null || news.isDeleted()) {
return Response.status(Response.Status.NOT_FOUND).build();
}
Locale userLocale = LocalizationFilter.getCurrentLocale();
Expand Down Expand Up @@ -464,7 +470,7 @@ public Response markNewsAsRead(@Context
return Response.status(Response.Status.BAD_REQUEST).build();
}
org.exoplatform.services.security.Identity currentIdentity = ConversationState.getCurrent().getIdentity();
News news = newsService.getNewsById(id, currentIdentity, false);
News news = newsService.getNewsById(id, currentIdentity, false, ARTICLE.name().toLowerCase());
if (news == null) {
return Response.status(Response.Status.NOT_FOUND).build();
}
Expand Down Expand Up @@ -679,7 +685,7 @@ public Response getNewsByActivityId(@Parameter(description = "Activity id", requ
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("users")
@Operation(summary = "Schedule a news", method = "POST", description = "This schedules the news if the authenticated user is a member of the space or a spaces super manager. The news is created in staged status, after reaching a date of publication startPublishedDate, the publicationState property is set to 'published'.")
@Operation(summary = "Schedule a news", method = "POST", description = "This schedules the news if the authenticated user is a member of the space or a spaces super manager. The news is created in staged status, after reaching a date of publication startPublishedDate, the publicationState property is set to 'posted'.")
@ApiResponses(value = { @ApiResponse(responseCode = "200", description = "News scheduled"),
@ApiResponse(responseCode = "400", description = "Invalid query input"),
@ApiResponse(responseCode = "401", description = "User not authorized to schedule the news"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private Document getDocument(String id) {
LOG.debug("Index document for news id={}", id);
News news = null;
try {
news = newsService.getNewsById(id, false);
news = newsService.getNewsArticleById(id);
} catch (Exception e) {
LOG.error("Error when getting the news " + id, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public interface NewsService {
* @return updated News
* @throws Exception
*/
News updateNews(News news, String updater, Boolean post, boolean publish, String newsObjectType) throws Exception;
News updateNews(News news, String updater, Boolean post, boolean publish, String newsObjectType, String newsUpdateType) throws Exception;

/**
* Delete news
Expand Down Expand Up @@ -163,6 +163,14 @@ News getNewsById(String newsId,
boolean editMode,
String newsObjectType) throws IllegalAccessException;

/**
* Retrives a news identified by its technical identifier
*
* @param newsId {@link News} identifier
* @return {@link News} if found else null
*/
News getNewsArticleById(String newsId);

/**
* Get all news
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ void deleteTargetByName(String targetName,

/**
* Gets the {@link List} of {@link News} targets linked to a given
* {@link News} id
* {@link News}
*
* @param newsId {@link News} identifier of {@link News} targets to be
* @param news {@link News} for which targets to be
* retrieved
* @return {@link List} of {@link News} targets by {@link News} id
* @return {@link List} of {@link News} targets by {@link News} news object
*/
List<String> getTargetsByNewsId(String newsId);
List<String> getTargetsByNews(News news);

/**
* Gets the {@link List} of {@link News} target items by a given target name.
Expand Down Expand Up @@ -105,9 +105,9 @@ void deleteTargetByName(String targetName,
* Delete the {@link List} of {@link News} targets linked to a given
* {@link News} id
*
* @param newsId {@link News} identifier of {@link News} to delete targets
* @param news {@link News} for which targets to be deleted
*/
void deleteNewsTargets(String newsId);
void deleteNewsTargets(News news);

/**
* Create news target
Expand Down
Loading

0 comments on commit 83c1ed2

Please sign in to comment.