-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement Notes/Content insert image option - EXO-74754 - Meeds…
…-io/MIPs#145 (#312) Implement notes/content insert image option.
- Loading branch information
Showing
5 changed files
with
228 additions
and
7 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
content-service/src/main/java/io/meeds/news/plugin/ArticlePageVersionAttachmentPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/** | ||
* 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.plugin; | ||
|
||
import io.meeds.news.model.News; | ||
import io.meeds.news.service.NewsService; | ||
import jakarta.annotation.PostConstruct; | ||
import org.exoplatform.commons.exception.ObjectNotFoundException; | ||
import org.exoplatform.services.security.Identity; | ||
import org.exoplatform.social.attachment.AttachmentPlugin; | ||
import org.exoplatform.social.attachment.AttachmentService; | ||
import org.exoplatform.wiki.model.PageVersion; | ||
import org.exoplatform.wiki.service.NoteService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static io.meeds.news.utils.NewsUtils.NewsObjectType.ARTICLE; | ||
|
||
@Component | ||
public class ArticlePageVersionAttachmentPlugin extends AttachmentPlugin { | ||
|
||
@Autowired | ||
private AttachmentService attachmentService; | ||
|
||
@Autowired | ||
private NewsService newsService; | ||
|
||
@Autowired | ||
private NoteService noteService; | ||
|
||
public static final String OBJECT_TYPE = "articlePageVersion"; | ||
|
||
@PostConstruct | ||
public void init() { | ||
attachmentService.addPlugin(this); | ||
} | ||
|
||
@Override | ||
public String getObjectType() { | ||
return OBJECT_TYPE; | ||
} | ||
|
||
@Override | ||
public boolean hasAccessPermission(Identity identity, String articleVersionId) throws ObjectNotFoundException { | ||
PageVersion pageVersion = noteService.getPageVersionById(Long.parseLong(articleVersionId)); | ||
News news = newsService.getNewsArticleById(pageVersion.getParent().getId()); | ||
return news != null && newsService.canViewNews(news, identity.getUserId()); | ||
} | ||
|
||
@Override | ||
public boolean hasEditPermission(Identity identity, String articleVersionId) throws ObjectNotFoundException { | ||
News news = null; | ||
try { | ||
PageVersion pageVersion = noteService.getPageVersionById(Long.parseLong(articleVersionId)); | ||
news = newsService.getNewsById(pageVersion.getParent().getId(), identity, false, ARTICLE.name()); | ||
} catch (IllegalAccessException e) { | ||
return false; | ||
} | ||
return news != null && news.isCanEdit(); | ||
} | ||
|
||
@Override | ||
public long getAudienceId(String s) throws ObjectNotFoundException { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public long getSpaceId(String articleVersionId) throws ObjectNotFoundException { | ||
PageVersion pageVersion = noteService.getPageVersionById(Long.parseLong(articleVersionId)); | ||
News news = newsService.getNewsArticleById(pageVersion.getParent().getId()); | ||
return news != null ? Long.parseLong(news.getSpaceId()) : 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
content-service/src/test/java/io/meeds/news/plugin/ArticleAttachmentPluginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* 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.plugin; | ||
|
||
import io.meeds.news.model.News; | ||
import io.meeds.news.service.NewsService; | ||
import org.exoplatform.social.attachment.AttachmentService; | ||
import org.exoplatform.wiki.model.Page; | ||
import org.exoplatform.wiki.model.PageVersion; | ||
import org.exoplatform.wiki.service.NoteService; | ||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import static io.meeds.news.utils.NewsUtils.NewsObjectType.ARTICLE; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ArticleAttachmentPluginTest { | ||
|
||
@Mock | ||
private NoteService noteService; | ||
|
||
@Mock | ||
private NewsService newsService; | ||
|
||
@Mock | ||
private AttachmentService attachmentService; | ||
|
||
@InjectMocks | ||
private ArticlePageVersionAttachmentPlugin plugin; | ||
|
||
@Before | ||
public void setUp() { | ||
plugin.init(); | ||
} | ||
|
||
@Test | ||
public void testGetObjectType() { | ||
Assert.assertEquals("articlePageVersion", plugin.getObjectType()); | ||
} | ||
|
||
@Test | ||
public void testHasAccessPermission() throws Exception { | ||
org.exoplatform.services.security.Identity userIdentity = mock(org.exoplatform.services.security.Identity.class); | ||
PageVersion pageVersion = mock(PageVersion.class); | ||
Page page = mock(Page.class); | ||
News news = mock(News.class); | ||
|
||
when(userIdentity.getUserId()).thenReturn("user123"); | ||
when(noteService.getPageVersionById(anyLong())).thenReturn(pageVersion); | ||
when(pageVersion.getParent()).thenReturn(page); | ||
when(page.getId()).thenReturn("1"); | ||
when(newsService.getNewsArticleById(anyString())).thenReturn(news); | ||
when(newsService.canViewNews(news, userIdentity.getUserId())).thenReturn(true); | ||
|
||
assertTrue(plugin.hasAccessPermission(userIdentity, "1")); | ||
} | ||
|
||
@Test | ||
public void testHasEditPermission() throws Exception { | ||
org.exoplatform.services.security.Identity userIdentity = mock(org.exoplatform.services.security.Identity.class); | ||
PageVersion pageVersion = mock(PageVersion.class); | ||
Page page = mock(Page.class); | ||
News news = mock(News.class); | ||
|
||
when(noteService.getPageVersionById(anyLong())).thenReturn(pageVersion); | ||
when(pageVersion.getParent()).thenReturn(page); | ||
when(page.getId()).thenReturn("1"); | ||
when(newsService.getNewsById("1", userIdentity, false, ARTICLE.name())).thenReturn(news); | ||
when(news.isCanEdit()).thenReturn(true); | ||
|
||
assertTrue(plugin.hasEditPermission(userIdentity, "1")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters