-
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
4 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
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,73 @@ | ||
package io.meeds.news.plugin; | ||
|
||
import io.meeds.news.model.News; | ||
import io.meeds.news.service.NewsService; | ||
import io.meeds.news.utils.NewsUtils; | ||
import jakarta.annotation.PostConstruct; | ||
import org.exoplatform.commons.exception.ObjectNotFoundException; | ||
import org.exoplatform.container.ExoContainerContext; | ||
import org.exoplatform.services.security.Identity; | ||
import org.exoplatform.services.security.IdentityRegistry; | ||
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 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
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