Skip to content

Commit

Permalink
feat: Remove space name from note url when copying note link and inse…
Browse files Browse the repository at this point in the history
…rting note - EXO-74772 - Meeds-io/MIPs#161 (#1172)
  • Loading branch information
azayati authored and hakermi committed Nov 28, 2024
1 parent 202949a commit 72de25b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 61 deletions.
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 @@ -1438,8 +1438,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
47 changes: 11 additions & 36 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,7 +45,6 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
Expand Down Expand Up @@ -84,11 +83,7 @@
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.WebAppController;
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 Down Expand Up @@ -605,40 +600,20 @@ public static String getRestContextName() {
return PortalContainer.getCurrentRestContextName();
}

public static String getPageUrl(Page page){
String spaceUri = getSpacesURI(page);
StringBuilder spaceUrl = new StringBuilder("/portal");
spaceUrl.append(spaceUri);
spaceUrl.append("/notes/");
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("/notes/");
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
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 @@ -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

0 comments on commit 72de25b

Please sign in to comment.