Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NewsArticlesUpgrade plugin user access rights issues - EXO-75949 #266

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data-upgrade-news/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<name>eXo Add-on:: Data Upgrade Add-on - NEWS</name>

<properties>
<exo.test.coverage.ratio>0.76</exo.test.coverage.ratio>
<exo.test.coverage.ratio>0.74</exo.test.coverage.ratio>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void processUpgrade(String oldVersion, String newVersion) {
List<String> newsArticlesNodesUUIDs = new ArrayList<String>();
while (newsIterator.hasNext()) {
Node newsArticleNode = newsIterator.next();
if (!getBooleanProperty(newsArticleNode, "exo:archived")) {
if (!newsNodeIgnored(newsArticleNode)) {
newsArticlesNodesUUIDs.add(newsArticleNode.getUUID());
} else {
newsArticleNode.remove();
Expand Down Expand Up @@ -260,8 +260,8 @@ public boolean shouldProceedToUpgrade(String newVersion,
return shouldUpgrade;
}

public int manageNewsArticles(List<String> newsArticlesNodesUUIDs, SessionProvider sessionProvider) throws Exception {
int notMigratedNewsArticlesCount = 0;
public int manageNewsArticles(List<String> newsArticlesNodesUUIDs, SessionProvider sessionProvider) {
int notMigratedNewsArticlesCountByTransaction = 0;
for (String newsArticleNodeUUID : newsArticlesNodesUUIDs) {
News article = null;
News draftArticle = null;
Expand Down Expand Up @@ -317,7 +317,7 @@ public int manageNewsArticles(List<String> newsArticlesNodesUUIDs, SessionProvid
// upgrade the drafts of not existing articles
/* attachments will not be migrated for drafts */
properties.setDraft(true);
news.setProperties(properties);
news.setProperties(properties);
draftArticle = newsService.createDraftArticleForNewPage(news,
space.getGroupId(),
news.getAuthor(),
Expand Down Expand Up @@ -362,48 +362,61 @@ public int manageNewsArticles(List<String> newsArticlesNodesUUIDs, SessionProvid
newsArticleNode = session.getNodeByUUID(newsArticleNodeUUID);
setArticleIllustration(pageVersion.getParent(), article.getSpaceId(), publishedNode, "notePage");
setArticleAttachments(pageVersion.getId(), publishedNode);
/* upgrade news id for news targets and favorite metadatata items */
// upgrade news id for news targets and favorite metadatata items
setArticleMetadatasItems(article.getId(), newsArticleNodeUUID);

setArticleActivities(article, publishedNode);
setArticleViews(article, newsArticleNode);
Page publishedPage = noteService.getNoteById(article.getId());

// upgrade the drafts of existing articles
/* attachments will not be migrated for drafts */
properties.setDraft(true);
news.setProperties(properties);
News draftForExistingArticle = newsService.createDraftForExistingPage(news,
news.getAuthor(),
publishedPage,
news.getCreationDate().getTime(),
space);
DraftPage draftPage = noteService.getDraftNoteById(draftForExistingArticle.getId(),
draftForExistingArticle.getAuthor());
session = sessionProvider.getSession(
repositoryService.getCurrentRepository()
.getConfiguration()
.getDefaultWorkspaceName(),
repositoryService.getCurrentRepository());
newsArticleNode = session.getNodeByUUID(newsArticleNodeUUID);
setArticleIllustration(draftPage, draftForExistingArticle.getSpaceId(), newsArticleNode, "noteDraftPage");
// set the update and the created date
setArticleCreateAndUpdateDate(article.getId(), article.getSpaceId(), newsArticleNode);
// upgrade the drafts of existing articles
/* attachments will not be migrated for drafts */
if (spaceService.isMember(news.getSpaceId(), news.getDraftUpdaterUserName())) {
Page publishedPage = noteService.getNoteById(article.getId());
properties.setDraft(true);
news.setProperties(properties);
News draftForExistingArticle = newsService.createDraftForExistingPage(news,
news.getAuthor(),
publishedPage,
news.getCreationDate().getTime(),
space);
DraftPage draftPage = noteService.getDraftNoteById(draftForExistingArticle.getId(),
draftForExistingArticle.getAuthor());
session = sessionProvider.getSession(
repositoryService.getCurrentRepository()
.getConfiguration()
.getDefaultWorkspaceName(),
repositoryService.getCurrentRepository());
newsArticleNode = session.getNodeByUUID(newsArticleNodeUUID);
setArticleIllustration(draftPage, draftForExistingArticle.getSpaceId(), newsArticleNode, "noteDraftPage");
}
}
}
newsArticleNode.remove();
session.save();
LOG.info("Success migrating news article with id '{}' and title '{}'", newsArticleNodeUUID, news.getTitle());
} catch (Exception e) {
notMigratedNewsArticlesCount++;
notMigratedNewsArticlesCountByTransaction++;
LOG.warn("Error migrating news article with id '{}'. Continue to migrate other items", newsArticleNodeUUID, e);
if (article != null) {
newsService.deleteArticle(article, article.getAuthor());
setArticleMetadatasItems(newsArticleNodeUUID, article.getId());
} else if (draftArticle != null) {
newsService.deleteDraftArticle(draftArticle.getId(), draftArticle.getAuthor());
try {
if (article != null) {
newsService.deleteArticle(article, article.getAuthor());
setArticleMetadatasItems(newsArticleNodeUUID, article.getId());
} else if (draftArticle != null) {
newsService.deleteDraftArticle(draftArticle.getId(), draftArticle.getAuthor());
}
} catch (Exception exception) {
if (article != null) {
LOG.warn("The not migrated news article with id '{}' is not deleted, to be deleted manually.", article.getId());
}
else if (draftArticle != null) {
LOG.warn("The not migrated news draft article with id '{}' is not deleted, to be deleted manually.", draftArticle.getId());
}
}
}
}
return notMigratedNewsArticlesCount;
return notMigratedNewsArticlesCountByTransaction;
}

private News convertNewsNodeToNewEntity(Node newsNode, Node newsVersionNode) throws Exception {
Expand All @@ -419,6 +432,9 @@ private News convertNewsNodeToNewEntity(Node newsNode, Node newsVersionNode) thr
sanitizedBody = sanitizedBody.replaceAll("&#64;", "@");
news.setBody(MentionUtils.substituteUsernames(portalOwner, sanitizedBody));
news.setAuthor(getStringProperty(newsNode, "exo:author"));
if (newsVersionNode == null) {
news.setDraftUpdaterUserName(getStringProperty(newsNode, "exo:newsLastModifier"));
}
news.setSpaceId(getStringProperty(newsNode, "exo:spaceId"));
news.setAudience(getStringProperty(newsNode, "exo:audience"));
news.setPublicationState((getStringProperty(newsNode, StageAndVersionPublicationConstant.CURRENT_STATE).equals("published")
Expand Down Expand Up @@ -580,8 +596,7 @@ private void setArticleViews(News article, Node newsNode) throws RepositoryExcep
}
}

private void setArticleAttachments(String articleId,
Node newsNode) throws RepositoryException {
private void setArticleAttachments(String articleId, Node newsNode) throws RepositoryException {
if (newsNode.hasProperty("exo:attachmentsIds")) {
Property attachmentsIdsProperty = newsNode.getProperty("exo:attachmentsIds");
for (Value value : attachmentsIdsProperty.getValues()) {
Expand Down Expand Up @@ -659,4 +674,17 @@ private void setArticleCreateAndUpdateDate(String articleId, String spaceId, Nod
metadataService.updateMetadataItem(articleMetaData, articleMetaData.getCreatorId());
}
}
}

private boolean newsNodeIgnored(Node newsNode) throws Exception {
if (getBooleanProperty(newsNode, "exo:archived")) {
return true;
}
if (getStringProperty(newsNode, "publication:currentState").equals("draft")
&& !newsNode.hasProperty(AuthoringPublicationConstant.LIVE_REVISION_PROP)) {
String author = getStringProperty(newsNode, "exo:author");
String spaceId = getStringProperty(newsNode, "exo:spaceId");
return !spaceService.isMember(spaceId, author);
}
return false;
}
}
Loading