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

Merge EXO-74728_EXO-74772_EXO-73720 in develop exo #1178

Merged
merged 3 commits into from
Oct 17, 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
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,8 @@ public NoteToExport getNoteToExport(NoteToExport note, int exportId) throws Wiki

public String processNotesLinkForExport(NoteToExport note) throws WikiException {
String content = note.getContent();
String noteLinkprefix = "class=\"noteLink\" href=\"(?:.*?/|)(\\d+)";
String noteLinkprefix = "class=\"noteLink\" href=\"(?:.*?/)?(\\d+)\"";

String contentUpdated = content;
Map<String, String> urlToReplaces = new HashMap<>();
Pattern pattern = Pattern.compile(noteLinkprefix);
Expand All @@ -480,7 +481,7 @@ public String processNotesLinkForExport(NoteToExport note) throws WikiException
String noteParams = IMAGE_URL_REPLACEMENT_PREFIX + linkedNote.getWikiType() + IMAGE_URL_REPLACEMENT_SUFFIX
+ IMAGE_URL_REPLACEMENT_PREFIX + linkedNote.getWikiOwner() + IMAGE_URL_REPLACEMENT_SUFFIX
+ IMAGE_URL_REPLACEMENT_PREFIX + linkedNote.getName() + IMAGE_URL_REPLACEMENT_SUFFIX;
urlToReplaces.put(matchedLink + "\"", "class=\"noteLink\" href=\"" + noteParams + "\"");
urlToReplaces.put(matchedLink, "class=\"noteLink\" href=\"" + noteParams + "\"");
}
}
if (!urlToReplaces.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1436,8 +1436,8 @@ public Page getNoteByIdAndLang(Long pageId, Identity userIdentity, String source
page.setMetadatas(retrieveMetadataItems(pageId + "-" + lang, userIdentity.getUserId()));
}
}
if (publishedVersion == null && lang != null) {
//no version with lang, set the latest version without lang id
if (page != null && publishedVersion == null && lang != null) {
//no version with lang, set the latest version id without lang
publishedVersion = dataStorage.getPublishedVersionByPageIdAndLang(pageId, null);
page.setLatestVersionId(publishedVersion == null ? null : publishedVersion.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ public Response importNote(@Parameter(description = "Note id", required = true)
log.error("User does not have move permissions on the note {}", noteId, e);
return Response.status(Response.Status.UNAUTHORIZED).build();
} catch (Exception ex) {
log.warn("Failed to export note {} ", noteId, ex);
log.warn("Failed to import note {} ", noteId, ex);
return Response.status(HTTPStatus.INTERNAL_ERROR).cacheControl(cc).build();
}
}
Expand Down
81 changes: 27 additions & 54 deletions notes-service/src/main/java/org/exoplatform/wiki/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,17 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import io.meeds.notes.notifications.plugin.MentionInNoteNotificationPlugin;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.exoplatform.commons.api.notification.NotificationContext;
import org.exoplatform.commons.api.notification.model.PluginKey;
import org.exoplatform.commons.notification.impl.NotificationContextImpl;
import org.exoplatform.social.core.identity.provider.SpaceIdentityProvider;
import org.exoplatform.social.core.storage.api.IdentityStorage;
import org.exoplatform.social.core.utils.MentionUtils;
import org.exoplatform.social.notification.LinkProviderUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.suigeneris.jrcs.diff.DifferentiationFailedException;

import org.exoplatform.commons.api.notification.NotificationContext;
import org.exoplatform.commons.api.notification.model.PluginKey;
import org.exoplatform.commons.diff.DiffResult;
import org.exoplatform.commons.diff.DiffService;
import org.exoplatform.commons.notification.impl.NotificationContextImpl;
import org.exoplatform.commons.utils.CommonsUtils;
import org.exoplatform.commons.utils.PageList;
import org.exoplatform.container.ExoContainer;
Expand All @@ -84,18 +77,18 @@
import org.exoplatform.services.security.MembershipEntry;
import org.exoplatform.social.core.identity.model.Identity;
import org.exoplatform.social.core.identity.provider.OrganizationIdentityProvider;
import org.exoplatform.social.core.identity.provider.SpaceIdentityProvider;
import org.exoplatform.social.core.manager.IdentityManager;
import org.exoplatform.social.core.space.SpaceApplication;
import org.exoplatform.social.core.space.SpaceTemplate;
import org.exoplatform.social.core.space.SpaceUtils;
import org.exoplatform.social.core.space.model.Space;
import org.exoplatform.social.core.space.spi.SpaceService;
import org.exoplatform.social.core.space.spi.SpaceTemplateService;
import org.exoplatform.web.WebAppController;
import org.exoplatform.social.core.storage.api.IdentityStorage;
import org.exoplatform.social.core.utils.MentionUtils;
import org.exoplatform.social.notification.LinkProviderUtils;
import org.exoplatform.web.application.RequestContext;
import org.exoplatform.web.controller.QualifiedName;
import org.exoplatform.web.controller.router.Router;
import org.exoplatform.web.controller.router.URIWriter;
import org.exoplatform.web.url.navigation.NavigationResource;
import org.exoplatform.web.url.navigation.NodeURL;
import org.exoplatform.webui.application.WebuiRequestContext;
Expand All @@ -114,9 +107,9 @@
import org.exoplatform.wiki.service.search.SearchResult;
import org.exoplatform.wiki.service.search.WikiSearchData;

import io.meeds.notes.notifications.plugin.MentionInNoteNotificationPlugin;
import io.meeds.notes.service.NotePageViewService;
import io.meeds.social.cms.service.CMSService;
import jakarta.servlet.http.HttpServletRequest;

public class Utils {

Expand Down Expand Up @@ -612,48 +605,28 @@ public static String getRestContextName() {
return PortalContainer.getCurrentRestContextName();
}

public static String getPageUrl(Page page){
String appName= page.getAppName();
if(StringUtils.isEmpty(appName) && StringUtils.startsWith(page.getWikiOwner(), SpaceUtils.SPACE_GROUP)){
appName = getWikiAppNameInSpace(page.getWikiOwner());
} else {
appName = "notes";
}
String spaceUri = getSpacesURI(page);
StringBuilder spaceUrl = new StringBuilder("/portal");
spaceUrl.append(spaceUri);
spaceUrl.append("/");
spaceUrl.append(appName);
spaceUrl.append("/");
if (!StringUtils.isEmpty(page.getId())) {
spaceUrl.append(page.getId());
}
return spaceUrl.toString();
}

public static String getSpacesURI(Page page) {
public static String getPageUrl(Page page) {
try {
QualifiedName REQUEST_HANDLER = QualifiedName.create("gtn", "handler");
QualifiedName REQUEST_SITE_TYPE = QualifiedName.create("gtn", "sitetype");
QualifiedName REQUEST_SITE_NAME = QualifiedName.create("gtn", "sitename");
QualifiedName PATH = QualifiedName.create("gtn", "path");
SpaceService spaceService = CommonsUtils.getService(SpaceService.class);
WebAppController webAppController = CommonsUtils.getService(WebAppController.class);
Router router = webAppController.getRouter();
SpaceService spaceService = CommonsUtils.getService(SpaceService.class);
Space space = spaceService.getSpaceByGroupId(page.getWikiOwner());
if(space==null){
return "";
if (space != null) {
StringBuilder spaceUrl = new StringBuilder("/portal/s/");
spaceUrl.append(space.getId());
spaceUrl.append("/");
String appName = page.getAppName();
if (StringUtils.isEmpty(appName) && StringUtils.startsWith(page.getWikiOwner(), SpaceUtils.SPACE_GROUP)) {
appName = getWikiAppNameInSpace(page.getWikiOwner());
} else {
appName = "notes";
}
spaceUrl.append(appName);
spaceUrl.append("/");
if (!StringUtils.isEmpty(page.getId())) {
spaceUrl.append(page.getId());
}
return spaceUrl.toString();
}
Map<QualifiedName, String> qualifiedName = new HashedMap();
qualifiedName.put(REQUEST_HANDLER, "portal");
qualifiedName.put(REQUEST_SITE_TYPE, "group");

StringBuilder urlBuilder = new StringBuilder();
qualifiedName.put(REQUEST_SITE_NAME, space.getGroupId());
qualifiedName.put(PATH, space.getPrettyName());
router.render(qualifiedName, new URIWriter(urlBuilder));
return(urlBuilder.toString());

return "";
} catch (Exception e) {
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@

import java.util.Date;

import org.exoplatform.wiki.WikiException;
import org.exoplatform.wiki.model.Page;
import org.exoplatform.wiki.service.NoteService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -37,9 +34,9 @@
import org.exoplatform.container.xml.PropertiesParam;
import org.exoplatform.services.security.IdentityConstants;
import org.exoplatform.social.metadata.MetadataService;
import org.exoplatform.wiki.jpa.dao.PageDAO;
import org.exoplatform.wiki.jpa.entity.PageEntity;
import org.exoplatform.wiki.jpa.entity.WikiEntity;
import org.exoplatform.wiki.WikiException;
import org.exoplatform.wiki.model.Page;
import org.exoplatform.wiki.service.NoteService;

@RunWith(MockitoJUnitRunner.class)
public class WikiPageIndexingServiceConnectorTest {
Expand Down
13 changes: 0 additions & 13 deletions notes-webapp/src/main/webapp/javascript/eXo/wiki/notesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,6 @@ export function restoreNoteVersion(note,version) {
});
}

export function getPathByNoteOwner(note, noteAppName) {
if (!noteAppName) {
noteAppName = 'notes';
}
if (note.wikiType === 'group' && note?.url) {
const spaceName = note.wikiOwner.split('/spaces/')[1];
const spaceDisplayName = note.url.split(`/portal/g/:spaces:${spaceName}/`)[1].split('/')[0];
return `${eXo.env.portal.context}/g/:spaces:${spaceName}/${spaceDisplayName}/${noteAppName}/${note.id}`;
} else {
return `${eXo.env.portal.context}/${eXo.env.portal.portalName}/notes/${note.id}`;
}
}

export function deleteNotes(note) {
return fetch(`${notesConstants.PORTAL}/${notesConstants.PORTAL_REST}/notes/note/${note.id}`, {
credentials: 'include',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,8 @@ export default {
this.noteId = data.id;
this.addParamToUrl('noteId', this.noteId);
this.originalNote = structuredClone(data);
const notePath = this.$notesService.getPathByNoteOwner(data, this.appName).replace(/ /g, '_');
// delete draft note
this.deleteDraftNote(draftNote, notePath);
this.deleteDraftNote(draftNote, this.note?.url);
this.displayMessage({
type: 'success',
message: this.$t('notes.save.success.message'),
Expand Down Expand Up @@ -577,9 +576,8 @@ export default {
if (this.webPageUrl) {
return this.webPageUrl;
} else {
const notePath = this.$notesService.getPathByNoteOwner(note, this.appName).replace(/ /g, '_');
this.draftSavingStatus = '';
return `${notePath}?translation=${this.selectedLanguage || 'original'}`;
return `${note.url}?translation=${this.selectedLanguage || 'original'}`;
}
},
saveNoteDraft(update) {
Expand Down Expand Up @@ -704,7 +702,7 @@ export default {
.catch(e => console.error('Error when deleting draft note', e));
}
},
deleteDraftNote(draftNote, notePath) {
deleteDraftNote(draftNote, noteUrl) {
if (!draftNote) {
draftNote = this.note;
}
Expand All @@ -713,7 +711,7 @@ export default {
return this.$notesService.deleteDraftNote(draftNote).then(() => {
this.draftSavingStatus = '';
//re-initialize data
if (!notePath) {
if (!noteUrl) {
this.note = {
id: '',
title: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<div
v-else>
<v-btn
class="btn-primary primary pa-0 me-2"
class="btn-primary primary pa-0"
width="42"
height="36"
min-width="42"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,9 @@ export default {
if (data?.jsonList?.length) {
this.noteChildren = data?.jsonList;
}
else {
this.noteChildren = [];
}
});
},
openNoteChild(item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default {
},
copyLink() {
const inputTemp = $('<input>');
const path = window.location.href;
const path = `${window.location.origin}${this.note.url}`;
$('body').append(inputTemp);
inputTemp.val(path).select();
document.execCommand('copy');
Expand Down