-
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…
- Loading branch information
Showing
5 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
content-service/src/main/java/io/meeds/news/plugin/ArticlePageAttachmentPlugin.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,81 @@ | ||
/** | ||
* 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.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import static io.meeds.news.utils.NewsUtils.NewsObjectType.ARTICLE; | ||
|
||
@Component | ||
public class ArticlePageAttachmentPlugin extends AttachmentPlugin { | ||
|
||
@Autowired | ||
private AttachmentService attachmentService; | ||
|
||
@Autowired | ||
private NewsService newsService; | ||
|
||
public static final String OBJECT_TYPE = "articlePage"; | ||
|
||
@PostConstruct | ||
public void init() { | ||
attachmentService.addPlugin(this); | ||
} | ||
|
||
@Override | ||
public String getObjectType() { | ||
return OBJECT_TYPE; | ||
} | ||
|
||
@Override | ||
public boolean hasAccessPermission(Identity identity, String articleId) throws ObjectNotFoundException { | ||
News news = newsService.getNewsArticleById(articleId); | ||
return news != null && newsService.canViewNews(news, identity.getUserId()); | ||
} | ||
|
||
@Override | ||
public boolean hasEditPermission(Identity identity, String articleId) throws ObjectNotFoundException { | ||
News news = null; | ||
try { | ||
news = newsService.getNewsById(articleId, 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 articleId) throws ObjectNotFoundException { | ||
News news = newsService.getNewsArticleById(articleId); | ||
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
82 changes: 82 additions & 0 deletions
82
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,82 @@ | ||
/** | ||
* 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.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.anyString; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ArticleAttachmentPluginTest { | ||
|
||
@Mock | ||
private NewsService newsService; | ||
|
||
@Mock | ||
private AttachmentService attachmentService; | ||
|
||
@InjectMocks | ||
private ArticlePageAttachmentPlugin plugin; | ||
|
||
@Before | ||
public void setUp() { | ||
plugin.init(); | ||
} | ||
|
||
@Test | ||
public void testGetObjectType() { | ||
Assert.assertEquals("articlePage", plugin.getObjectType()); | ||
} | ||
|
||
@Test | ||
public void testHasAccessPermission() throws Exception { | ||
org.exoplatform.services.security.Identity userIdentity = mock(org.exoplatform.services.security.Identity.class); | ||
News news = mock(News.class); | ||
|
||
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); | ||
News news = mock(News.class); | ||
|
||
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
Oops, something went wrong.