Skip to content

Commit

Permalink
fix: fix publish article from empty note default home page - EXO-7304…
Browse files Browse the repository at this point in the history
…1 - Meeds-io/MIPs#161 (#313)

prior to this change, when try to publish newly created default note
home page, an exception is thrown as the note is auto created without
specifying the author.
This PR ensures to set the poster as author during the publish process.
  • Loading branch information
hakermi authored and exo-swf committed Nov 23, 2024
1 parent d3f67a0 commit c206ebd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,20 +238,21 @@ public News createNews(News news, Identity currentIdentity) throws Exception {

@Override
public News postNews(News news, String poster) throws Exception {
if (news.getPublicationState().equals(STAGED) || news.getSchedulePostDate() != null) {
if (news == null || poster == null || poster.isBlank()) {
throw new IllegalArgumentException("News and poster cannot be null or empty.");
}

if (STAGED.equals(news.getPublicationState()) || news.getSchedulePostDate() != null) {
news = postScheduledArticle(news);
} else if (!news.isFromDraft() && noteService.getNoteById(news.getId()) != null) {
news = createArticleFromExistingPage(news, poster);
} else {
news = createNewsArticlePage(news, poster);
}
postNewsActivity(news);
sendNotification(poster, news, NotificationConstants.NOTIFICATION_CONTEXT.POST_NEWS);
if (news.isPublished()) {
publishNews(news, poster);

if (news != null) {
postProcessing(news, poster);
}
NewsUtils.broadcastEvent(NewsUtils.POST_NEWS_ARTICLE, news.getId(), news);// Gamification
NewsUtils.broadcastEvent(NewsUtils.POST_NEWS, news.getAuthor(), news);// Analytics
return news;
}

Expand Down Expand Up @@ -1179,6 +1180,23 @@ public void deleteDraftArticle(String draftArticleId, String draftArticleCreator
public List<String> getArticleLanguages(String articleId, boolean withDrafts) throws WikiException {
return noteService.getPageAvailableTranslationLanguages(Long.parseLong(articleId), withDrafts);
}

private void postProcessing(News news, String poster) throws Exception {
if (news.getAuthor() == null) {
news.setAuthor(poster);
}

postNewsActivity(news);
sendNotification(poster, news, NotificationConstants.NOTIFICATION_CONTEXT.POST_NEWS);

if (news.isPublished()) {
publishNews(news, poster);
}

// Broadcast events for gamification and analytics
NewsUtils.broadcastEvent(NewsUtils.POST_NEWS_ARTICLE, news.getId(), news);
NewsUtils.broadcastEvent(NewsUtils.POST_NEWS, news.getAuthor(), news);
}

private void buildNewArticleProperties(News article,
Page articlePage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,11 @@ public void testPostNews() throws Exception {
anyMap(),
anyLong(),
anyBoolean());

clearInvocations(activityManager);
newsArticlePage.setAuthor(null);
newsService.createNews(newsArticle, identity);
verify(activityManager, times(1)).saveActivityNoReturn(any(), any());
}

@Test
Expand Down

0 comments on commit c206ebd

Please sign in to comment.