diff --git a/content-service/src/main/java/io/meeds/news/rest/NewsRestResourcesV1.java b/content-service/src/main/java/io/meeds/news/rest/NewsRestResourcesV1.java index 8eaedceb7..1a2ae8803 100644 --- a/content-service/src/main/java/io/meeds/news/rest/NewsRestResourcesV1.java +++ b/content-service/src/main/java/io/meeds/news/rest/NewsRestResourcesV1.java @@ -240,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) { @@ -263,7 +267,7 @@ 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) { diff --git a/content-service/src/main/java/io/meeds/news/service/NewsService.java b/content-service/src/main/java/io/meeds/news/service/NewsService.java index 4eb9db05c..91663f163 100644 --- a/content-service/src/main/java/io/meeds/news/service/NewsService.java +++ b/content-service/src/main/java/io/meeds/news/service/NewsService.java @@ -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 diff --git a/content-service/src/main/java/io/meeds/news/service/impl/NewsServiceImpl.java b/content-service/src/main/java/io/meeds/news/service/impl/NewsServiceImpl.java index 3fa0394c4..759929bc8 100644 --- a/content-service/src/main/java/io/meeds/news/service/impl/NewsServiceImpl.java +++ b/content-service/src/main/java/io/meeds/news/service/impl/NewsServiceImpl.java @@ -21,6 +21,7 @@ import static io.meeds.news.utils.NewsUtils.NewsObjectType.ARTICLE; import static io.meeds.news.utils.NewsUtils.NewsObjectType.LATEST_DRAFT; +import static io.meeds.news.utils.NewsUtils.NewsUpdateType.CONTENT; import java.io.FileInputStream; import java.io.InputStream; @@ -60,6 +61,7 @@ import org.exoplatform.social.core.manager.IdentityManager; import org.exoplatform.social.core.space.model.Space; import org.exoplatform.social.core.space.spi.SpaceService; +import org.exoplatform.social.core.utils.MentionUtils; import org.exoplatform.social.metadata.MetadataService; import org.exoplatform.social.metadata.model.MetadataItem; import org.exoplatform.social.metadata.model.MetadataKey; @@ -94,11 +96,16 @@ import io.meeds.news.service.NewsTargetingService; import io.meeds.news.utils.NewsUtils; import io.meeds.news.utils.NewsUtils.NewsObjectType; +import org.exoplatform.commons.utils.HTMLSanitizer; public class NewsServiceImpl implements NewsService { public static final String NEWS_ARTICLES_ROOT_NOTE_PAGE_NAME = "Articles"; + private static final String HTML_AT_SYMBOL_PATTERN = "@"; + + private static final String HTML_AT_SYMBOL_ESCAPED_PATTERN = "@"; + public static final MetadataType NEWS_METADATA_TYPE = new MetadataType(1000, "news"); public static final String NEWS_METADATA_NAME = "news"; @@ -140,8 +147,8 @@ public class NewsServiceImpl implements NewsService { /** The Constant NEWS_ACTIVITY_POSTED. */ public static final String NEWS_ACTIVITY_POSTED = "activityPosted"; - /** The Constant NEWS_PUBLISH_DATE. */ - public static final String NEWS_PUBLISH_DATE = "publishDate"; + /** The Constant NEWS_PUBLICATION_DATE. */ + public static final String NEWS_PUBLICATION_DATE = "publicationDate"; /** The Constant NEWS_METADATA_PAGE_OBJECT_TYPE. */ public static final String NEWS_METADATA_PAGE_OBJECT_TYPE = "newsPage"; @@ -264,7 +271,7 @@ public News updateNews(News news, String updater, Boolean post, boolean publish) * {@inheritDoc} */ @Override - public News updateNews(News news, String updater, Boolean post, boolean publish, String newsObjectType) throws Exception { + public News updateNews(News news, String updater, Boolean post, boolean publish, String newsObjectType, String newsUpdateType) throws Exception { if (!canEditNews(news, updater)) { throw new IllegalAccessException("User " + updater + " is not authorized to update news"); @@ -279,8 +286,6 @@ public News updateNews(News news, String updater, Boolean post, boolean publish, return updateDraftArticleForNewPage(news, updater); } else if (LATEST_DRAFT.name().toLowerCase().equals(newsObjectType)) { return createOrUpdateDraftForExistingPage(news, updater); - } else if (ARTICLE.name().toLowerCase().equals(newsObjectType)) { - news = updateNewsArticle(news, updaterIdentity); } if (publish != news.isPublished() && news.isCanPublish()) { news.setPublished(publish); @@ -301,6 +306,11 @@ public News updateNews(News news, String updater, Boolean post, boolean publish, sendNotification(updater, news, NotificationConstants.NOTIFICATION_CONTEXT.PUBLISH_NEWS); } } + // update the news article after executing publish and send notification method + // they are need the original news to trait the news audience to exclude space member from notify + if (ARTICLE.name().toLowerCase().equals(newsObjectType)) { + news = updateNewsArticle(news, updaterIdentity, newsUpdateType); + } if (PUBLISHED.equals(news.getPublicationState())) { // Send mention notifs @@ -367,8 +377,8 @@ public void publishNews(News newsToPublish, String publisher) throws Exception { } properties.put(PUBLISHED, String.valueOf(true)); Calendar updateCalendar = Calendar.getInstance(); - Date newsPublishDate = updateCalendar.getTime(); - properties.put(NEWS_PUBLISH_DATE, String.valueOf(newsPublishDate)); + Date newsPublicationDate = updateCalendar.getTime(); + properties.put(NEWS_PUBLICATION_DATE, String.valueOf(newsPublicationDate)); metadataItem.setProperties(properties); String publisherId = identityManager.getOrCreateUserIdentity(publisherIdentity.getUserId()).getId(); metadataService.updateMetadataItem(metadataItem, Long.parseLong(publisherId)); @@ -404,9 +414,12 @@ public void unpublishNews(String newsId, String publisher) throws Exception { Map properties = newsMetadataItem.getProperties(); if (properties != null) { properties.put(PUBLISHED, String.valueOf(false)); - properties.remove(NEWS_PUBLISH_DATE); + properties.remove(NEWS_PUBLICATION_DATE); properties.remove(NEWS_AUDIENCE); } + newsMetadataItem.setProperties(properties); + String publisherId = identityManager.getOrCreateUserIdentity(publisher).getId(); + metadataService.updateMetadataItem(newsMetadataItem, Long.parseLong(publisherId)); } } @@ -915,7 +928,7 @@ private News updateDraftArticleForNewPage(News draftArticle, String draftArticle return null; } - private News buildDraftArticle(String draftArticleId, String currentUserId) throws WikiException, IllegalAccessException { + private News buildDraftArticle(String draftArticleId, String currentUserId) throws Exception { DraftPage draftArticlePage = noteService.getDraftNoteById(draftArticleId, currentUserId); if (draftArticlePage != null) { News draftArticle = new News(); @@ -931,7 +944,13 @@ private News buildDraftArticle(String draftArticleId, String currentUserId) thro if (draftUpdaterIdentity != null && draftUpdaterIdentity.getProfile() != null) { draftArticle.setDraftUpdaterDisplayName(draftUpdaterIdentity.getProfile().getFullName()); } - draftArticle.setBody(draftArticlePage.getContent()); + String portalOwner = CommonsUtils.getCurrentPortalOwner(); + String body = draftArticlePage.getContent(); + String sanitizedBody = HTMLSanitizer.sanitize(body); + sanitizedBody = sanitizedBody.replaceAll(HTML_AT_SYMBOL_ESCAPED_PATTERN, HTML_AT_SYMBOL_PATTERN); + draftArticle.setBody(MentionUtils.substituteUsernames(portalOwner, sanitizedBody)); + draftArticle.setOriginalBody(sanitizedBody); + draftArticle.setPublicationState(DRAFT); Space draftArticleSpace = spaceService.getSpaceByGroupId(draftArticlePage.getWikiOwner()); draftArticle.setSpaceId(draftArticleSpace.getId()); @@ -1018,6 +1037,9 @@ private List buildDraftArticles(NewsFilter filter, Identity currentIdentit // block e.printStackTrace(); return null; + } catch (Exception e) { + e.printStackTrace(); + return null; } }) .toList(); @@ -1469,20 +1491,18 @@ private News createNewsArticlePage(News newsArticle, String newsArticleCreator) return null; } - private News updateNewsArticle(News news, Identity updater) throws Exception { + private News updateNewsArticle(News news, Identity updater, String newsUpdateType) throws Exception { Page existingPage = noteService.getNoteById(news.getId()); if (existingPage != null) { - existingPage.setTitle(news.getTitle()); - existingPage.setContent(news.getBody()); + if (newsUpdateType.equals(CONTENT.name().toLowerCase())) { + existingPage.setTitle(news.getTitle()); + existingPage.setContent(news.getBody()); + } existingPage.setUpdatedDate(Calendar.getInstance().getTime()); existingPage = noteService.updateNote(existingPage); - - // create the version - noteService.createVersionOfNote(existingPage, updater.getUserId()); - PageVersion createdVersion = noteService.getPublishedVersionByPageIdAndLang(Long.parseLong(existingPage.getId()), null); - news.setUpdateDate(createdVersion.getCreatedDate()); - news.setUpdater(createdVersion.getAuthor()); - news.setUpdaterFullName(createdVersion.getAuthorFullName()); + news.setUpdateDate(existingPage.getUpdatedDate()); + news.setUpdater(existingPage.getAuthor()); + news.setUpdaterFullName(existingPage.getAuthorFullName()); String newsArticleUpdaterIdentityId = identityManager.getOrCreateUserIdentity(updater.getUserId()).getId(); @@ -1511,44 +1531,49 @@ private News updateNewsArticle(News news, Identity updater) throws Exception { throw new ObjectNotFoundException("No such news article metadata item exists with id " + news.getId()); } - // create the version metadata item - NewsPageVersionObject newsArticleVersionMetaDataObject = new NewsPageVersionObject(NEWS_METADATA_PAGE_VERSION_OBJECT_TYPE, - createdVersion.getId(), - null); - Map newsArticleVersionMetadataItemProperties = new HashMap<>(); - - String draftNewsId = noteService.getLatestDraftPageByUserAndTargetPageAndLang(Long.parseLong(existingPage.getId()), - updater.getUserId(), - null) - .getId(); - - NewsLatestDraftObject newsLatestDraftObject = new NewsLatestDraftObject(NEWS_METADATA_LATEST_DRAFT_OBJECT_TYPE, - draftNewsId, - existingPage.getId()); - MetadataItem metadataItem = metadataService.getMetadataItemsByMetadataAndObject(NEWS_METADATA_KEY, newsLatestDraftObject) - .stream() - .findFirst() - .orElse(null); - if (metadataItem != null && metadataItem.getProperties() != null && !metadataItem.getProperties().isEmpty()) { - Map properties = metadataItem.getProperties(); - if (properties.containsKey(NEWS_UPLOAD_ID)) { - newsArticleVersionMetadataItemProperties.put(NEWS_UPLOAD_ID, properties.get(NEWS_UPLOAD_ID)); + // create the version + if (newsUpdateType.equals(CONTENT.name().toLowerCase())) { + noteService.createVersionOfNote(existingPage, updater.getUserId()); + PageVersion createdVersion = noteService.getPublishedVersionByPageIdAndLang(Long.parseLong(existingPage.getId()), null); + // create the version metadata item + NewsPageVersionObject newsArticleVersionMetaDataObject = new NewsPageVersionObject(NEWS_METADATA_PAGE_VERSION_OBJECT_TYPE, + createdVersion.getId(), + null); + Map newsArticleVersionMetadataItemProperties = new HashMap<>(); + + String draftNewsId = noteService.getLatestDraftPageByUserAndTargetPageAndLang(Long.parseLong(existingPage.getId()), + updater.getUserId(), + null) + .getId(); + + NewsLatestDraftObject newsLatestDraftObject = new NewsLatestDraftObject(NEWS_METADATA_LATEST_DRAFT_OBJECT_TYPE, + draftNewsId, + existingPage.getId()); + MetadataItem metadataItem = metadataService.getMetadataItemsByMetadataAndObject(NEWS_METADATA_KEY, newsLatestDraftObject) + .stream() + .findFirst() + .orElse(null); + if (metadataItem != null && metadataItem.getProperties() != null && !metadataItem.getProperties().isEmpty()) { + Map properties = metadataItem.getProperties(); + if (properties.containsKey(NEWS_UPLOAD_ID)) { + newsArticleVersionMetadataItemProperties.put(NEWS_UPLOAD_ID, properties.get(NEWS_UPLOAD_ID)); + } + if (properties.containsKey(NEWS_ILLUSTRATION_ID)) { + newsArticleVersionMetadataItemProperties.put(NEWS_ILLUSTRATION_ID, properties.get(NEWS_ILLUSTRATION_ID)); + setArticleIllustration(news, Long.parseLong(properties.get(NEWS_ILLUSTRATION_ID)), ARTICLE.name().toLowerCase()); + } + } else { + throw new ObjectNotFoundException("No such news draft article metadata item exists with id " + draftNewsId); } - if (properties.containsKey(NEWS_ILLUSTRATION_ID)) { - newsArticleVersionMetadataItemProperties.put(NEWS_ILLUSTRATION_ID, properties.get(NEWS_ILLUSTRATION_ID)); - setArticleIllustration(news, Long.parseLong(properties.get(NEWS_ILLUSTRATION_ID)), ARTICLE.name().toLowerCase()); + if (StringUtils.isNotEmpty(news.getSummary())) { + newsArticleVersionMetadataItemProperties.put(NEWS_SUMMARY, news.getSummary()); } - } else { - throw new ObjectNotFoundException("No such news draft article metadata item exists with id " + draftNewsId); - } - if (StringUtils.isNotEmpty(news.getSummary())) { - newsArticleVersionMetadataItemProperties.put(NEWS_SUMMARY, news.getSummary()); - } - metadataService.createMetadataItem(newsArticleVersionMetaDataObject, - NEWS_METADATA_KEY, - newsArticleVersionMetadataItemProperties, - Long.parseLong(newsArticleUpdaterIdentityId)); + metadataService.createMetadataItem(newsArticleVersionMetaDataObject, + NEWS_METADATA_KEY, + newsArticleVersionMetadataItemProperties, + Long.parseLong(newsArticleUpdaterIdentityId)); + } // remove the draft noteService.removeDraftOfNote(existingPage, updater.getUserId()); return news; @@ -1556,13 +1581,17 @@ private News updateNewsArticle(News news, Identity updater) throws Exception { return null; } - private News buildArticle(String newsId) throws WikiException { + private News buildArticle(String newsId) throws Exception { Page articlePage = noteService.getNoteById(newsId); Identity userIdentity = getCurrentIdentity(); String currentUsername = userIdentity == null ? null : userIdentity.getUserId(); if (articlePage != null) { News news = new News(); + news.setId(articlePage.getId()); news.setCreationDate(articlePage.getCreatedDate()); + news.setAuthor(articlePage.getAuthor()); + news.setUpdateDate(articlePage.getUpdatedDate()); + news.setUpdater(articlePage.getAuthor()); // fetch related metadata item properties NewsPageObject newsPageObject = new NewsPageObject(NEWS_METADATA_PAGE_OBJECT_TYPE, articlePage.getId(), null); @@ -1621,11 +1650,11 @@ private News buildArticle(String newsId) throws WikiException { if (properties.containsKey(PUBLISHED) && StringUtils.isNotEmpty(properties.get(PUBLISHED))) { news.setPublished(Boolean.valueOf(properties.get(PUBLISHED))); } - if (properties.containsKey(NEWS_PUBLISH_DATE) && StringUtils.isNotEmpty(properties.get(NEWS_PUBLISH_DATE))) { + if (properties.containsKey(NEWS_PUBLICATION_DATE) && StringUtils.isNotEmpty(properties.get(NEWS_PUBLICATION_DATE))) { try { SimpleDateFormat format = new SimpleDateFormat("E MMM dd HH:mm:ss z yyyy"); - Date date = format.parse(properties.get(NEWS_PUBLISH_DATE)); - news.setPublishDate(date); + Date date = format.parse(properties.get(NEWS_PUBLICATION_DATE)); + news.setPublicationDate(date); } catch (Exception exception) { LOG.warn("failed to parse news published date for article with id " + news.getId()); } @@ -1643,11 +1672,15 @@ private News buildArticle(String newsId) throws WikiException { // fetch the last version of the given lang PageVersion pageVersion = noteService.getPublishedVersionByPageIdAndLang(Long.parseLong(articlePage.getId()), null); - news.setId(articlePage.getId()); news.setTitle(pageVersion.getTitle()); - news.setAuthor(articlePage.getAuthor()); - news.setUpdateDate(pageVersion.getUpdatedDate()); - news.setBody(pageVersion.getContent()); + + String portalOwner = CommonsUtils.getCurrentPortalOwner(); + String body = pageVersion.getContent(); + String sanitizedBody = HTMLSanitizer.sanitize(body); + sanitizedBody = sanitizedBody.replaceAll(HTML_AT_SYMBOL_ESCAPED_PATTERN, HTML_AT_SYMBOL_PATTERN); + news.setBody(MentionUtils.substituteUsernames(portalOwner, sanitizedBody)); + news.setOriginalBody(sanitizedBody); + news.setUpdaterFullName(pageVersion.getAuthorFullName()); if (articlePage.getWikiOwner() != null) { Space space = spaceService.getSpaceByGroupId(articlePage.getWikiOwner()); diff --git a/content-service/src/main/java/io/meeds/news/utils/NewsUtils.java b/content-service/src/main/java/io/meeds/news/utils/NewsUtils.java index 82f561edb..63a337719 100644 --- a/content-service/src/main/java/io/meeds/news/utils/NewsUtils.java +++ b/content-service/src/main/java/io/meeds/news/utils/NewsUtils.java @@ -94,6 +94,11 @@ public enum NewsObjectType { DRAFT, LATEST_DRAFT, ARTICLE; } + public enum NewsUpdateType { + CONTENT, SCHEDULE, POSTING_AND_PUBLISHING + } + + public static void broadcastEvent(String eventName, Object source, Object data) { try { ListenerService listenerService = CommonsUtils.getService(ListenerService.class); diff --git a/content-service/src/test/java/io/meeds/news/rest/NewsRestResourcesV1Test.java b/content-service/src/test/java/io/meeds/news/rest/NewsRestResourcesV1Test.java index ab4576ab8..ec4c0cd51 100644 --- a/content-service/src/test/java/io/meeds/news/rest/NewsRestResourcesV1Test.java +++ b/content-service/src/test/java/io/meeds/news/rest/NewsRestResourcesV1Test.java @@ -20,6 +20,7 @@ package io.meeds.news.rest; import static io.meeds.news.utils.NewsUtils.NewsObjectType.ARTICLE; +import static io.meeds.news.utils.NewsUtils.NewsUpdateType.CONTENT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -365,10 +366,10 @@ public void shouldGetOKWhenUpdatingNewsAndNewsExistsAndUserIsAuthorized() throws updatedNews.setSummary("Updated Summary"); updatedNews.setBody("Updated Body"); updatedNews.setPublicationState("published"); - lenient().when(newsService.updateNews(existingNews, JOHN, false, updatedNews.isPublished(), null)).then(returnsFirstArg()); + lenient().when(newsService.updateNews(existingNews, JOHN, false, updatedNews.isPublished(), null, CONTENT.name().toLowerCase())).then(returnsFirstArg()); // When - Response response = newsRestResourcesV1.updateNews("1", false, null, updatedNews); + Response response = newsRestResourcesV1.updateNews("1", false, null, CONTENT.name().toLowerCase(), updatedNews); // Then assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); @@ -379,10 +380,10 @@ public void shouldGetOKWhenUpdatingNewsAndNewsExistsAndUserIsAuthorized() throws assertEquals("Updated Body", returnedNews.getBody()); assertEquals("published", returnedNews.getPublicationState()); - when(newsRestResourcesV1.updateNews("1", false, null, updatedNews)).thenThrow(IllegalAccessException.class); + when(newsRestResourcesV1.updateNews("1", false, null, CONTENT.name().toLowerCase(), updatedNews)).thenThrow(IllegalAccessException.class); // When - response = newsRestResourcesV1.updateNews("1", false, null, updatedNews); + response = newsRestResourcesV1.updateNews("1", false, null, CONTENT.name().toLowerCase(), updatedNews); // Then assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), response.getStatus()); @@ -396,7 +397,7 @@ public void shouldGetNotFoundWhenUpdatingNewsAndNewsNotExists() throws Exception lenient().when(newsService.getNewsById(anyString(), any(), anyBoolean(), nullable(String.class))).thenReturn(null); // When - Response response = newsRestResourcesV1.updateNews("1", false, null, new News()); + Response response = newsRestResourcesV1.updateNews("1", false, null, CONTENT.name().toLowerCase(), new News()); // Then assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); @@ -597,10 +598,10 @@ public void shouldGetOKWhenUpdatingAndPinNewsAndNewsExistsAndAndUserIsAuthorized currentIdentity.setMemberships(memberships); lenient().when(newsService.getNewsById("id123", currentIdentity, false, null)).thenReturn(existingNews); - lenient().when(newsService.updateNews(existingNews, JOHN, false, updatedNews.isPublished(), null)).then(returnsFirstArg()); + lenient().when(newsService.updateNews(existingNews, JOHN, false, updatedNews.isPublished(), null, CONTENT.name().toLowerCase())).then(returnsFirstArg()); // When - Response response = newsRestResourcesV1.updateNews("id123", false, null, updatedNews); + Response response = newsRestResourcesV1.updateNews("id123", false, null, CONTENT.name().toLowerCase(), updatedNews); // Then assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); @@ -643,7 +644,7 @@ public void shouldGetOKWhenUpdatingAndUnpinNewsAndNewsExistsAndAndUserIsAuthoriz lenient().when(newsService.getNewsById("id123", currentIdentity, false, null)).thenReturn(oldnews); // When - Response response = newsRestResourcesV1.updateNews("id123", false, null, updatedNews); + Response response = newsRestResourcesV1.updateNews("id123", false, null, CONTENT.name().toLowerCase(), updatedNews); // Then assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); @@ -758,7 +759,7 @@ public void shouldGetBadRequestWhenUpdatingNewsAndUpdatedNewsIsNull() throws Exc ConversationState.setCurrent(new ConversationState(currentIdentity)); // When - Response response = newsRestResourcesV1.updateNews("1", false, null, null); + Response response = newsRestResourcesV1.updateNews("1", false, null, CONTENT.name().toLowerCase(), null); // Then assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); diff --git a/content-service/src/test/java/io/meeds/news/service/impl/NewsServiceImplTest.java b/content-service/src/test/java/io/meeds/news/service/impl/NewsServiceImplTest.java index 4fb149aab..afca31d74 100644 --- a/content-service/src/test/java/io/meeds/news/service/impl/NewsServiceImplTest.java +++ b/content-service/src/test/java/io/meeds/news/service/impl/NewsServiceImplTest.java @@ -22,6 +22,7 @@ import static io.meeds.news.service.impl.NewsServiceImpl.NEWS_ACTIVITIES; import static io.meeds.news.service.impl.NewsServiceImpl.NEWS_ARTICLES_ROOT_NOTE_PAGE_NAME; import static io.meeds.news.service.impl.NewsServiceImpl.NEWS_SUMMARY; +import static io.meeds.news.utils.NewsUtils.NewsUpdateType.CONTENT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; @@ -320,7 +321,7 @@ public void testUpdateDraftArticle() throws Exception { expecteddraftPage.setWikiOwner("/space/groupId"); // When, Then - assertThrows(IllegalAccessException.class, () -> newsService.updateNews(news, "john", false, false, "draft")); + assertThrows(IllegalAccessException.class, () -> newsService.updateNews(news, "john", false, false, "draft", CONTENT.name().toLowerCase())); // Given when(spaceService.canRedactOnSpace(space, identity)).thenReturn(true); @@ -331,7 +332,7 @@ public void testUpdateDraftArticle() throws Exception { when(noteService.updateDraftForNewPage(any(DraftPage.class), anyLong())).thenReturn(expecteddraftPage); // When - newsService.updateNews(news, "john", false, false, "draft"); + newsService.updateNews(news, "john", false, false, "draft", CONTENT.name().toLowerCase()); // Then verify(noteService, times(1)).updateDraftForNewPage(eq(expecteddraftPage), anyLong()); @@ -567,7 +568,7 @@ public void testCreateDraftArticleForExistingPage() throws Exception { news.setOriginalBody("body"); // When, Then - assertThrows(IllegalAccessException.class, () -> newsService.updateNews(news, "john", false, false, "draft")); + assertThrows(IllegalAccessException.class, () -> newsService.updateNews(news, "john", false, false, "draft", CONTENT.name().toLowerCase())); // Given when(spaceService.canRedactOnSpace(space, identity)).thenReturn(true); @@ -589,7 +590,7 @@ public void testCreateDraftArticleForExistingPage() throws Exception { anyString())).thenReturn(draftPage); // When - newsService.updateNews(news, "john", false, false, "latest_draft"); + newsService.updateNews(news, "john", false, false, "latest_draft", CONTENT.name().toLowerCase()); // Then verify(noteService, times(1)).createDraftForExistPage(any(DraftPage.class), @@ -659,7 +660,7 @@ public void testUpdateDraftArticleForExistingPage() throws Exception { news.setOriginalBody("body"); // When, Then - assertThrows(IllegalAccessException.class, () -> newsService.updateNews(news, "john", false, false, "draft")); + assertThrows(IllegalAccessException.class, () -> newsService.updateNews(news, "john", false, false, "draft", CONTENT.name().toLowerCase())); // Given when(spaceService.canRedactOnSpace(space, identity)).thenReturn(true); @@ -676,7 +677,7 @@ public void testUpdateDraftArticleForExistingPage() throws Exception { anyString())).thenReturn(draftPage); // When - newsService.updateNews(news, "john", false, false, "latest_draft"); + newsService.updateNews(news, "john", false, false, "latest_draft", CONTENT.name().toLowerCase()); // Then verify(noteService, times(1)).updateDraftForExistPage(any(DraftPage.class), @@ -746,7 +747,7 @@ public void testUpdateNewsArticle() throws Exception { news.setOriginalBody("body"); // When, Then - assertThrows(IllegalAccessException.class, () -> newsService.updateNews(news, "john", false, false, "draft")); + assertThrows(IllegalAccessException.class, () -> newsService.updateNews(news, "john", false, false, "draft", CONTENT.name().toLowerCase())); // Given when(spaceService.canRedactOnSpace(space, identity)).thenReturn(true); @@ -759,7 +760,7 @@ public void testUpdateNewsArticle() throws Exception { when(noteService.updateNote(any(Page.class))).thenReturn(existingPage); // When - newsService.updateNews(news, "john", false, false, "article"); + newsService.updateNews(news, "john", false, false, "article", CONTENT.name().toLowerCase()); // Then verify(noteService, times(1)).updateNote(any(Page.class)); diff --git a/content-webapp/src/main/webapp/js/newsUtils.js b/content-webapp/src/main/webapp/js/newsUtils.js index 484987684..30077e9e5 100644 --- a/content-webapp/src/main/webapp/js/newsUtils.js +++ b/content-webapp/src/main/webapp/js/newsUtils.js @@ -30,4 +30,16 @@ export function convertDate(date) { export function pad(n) { return n < 10 && `0${n}` || n; -} \ No newline at end of file +} + +export const NewsUpdateType = { + CONTENT: 'content', + POSTING_AND_PUBLISHING: 'postingAndPublishing', + SCHEDULE: 'schedule' +}; + +export const NewsObjectType = { + DRAFT: 'draft', + ARTICLE: 'article', + LATEST_DRAFT: 'latest_draft' +}; \ No newline at end of file diff --git a/content-webapp/src/main/webapp/news-details/components/ExoNewsDetails.vue b/content-webapp/src/main/webapp/news-details/components/ExoNewsDetails.vue index e027edaa2..2f2941af6 100644 --- a/content-webapp/src/main/webapp/news-details/components/ExoNewsDetails.vue +++ b/content-webapp/src/main/webapp/news-details/components/ExoNewsDetails.vue @@ -64,6 +64,8 @@