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
  • Loading branch information
azayati committed Oct 16, 2024
1 parent 451cdd6 commit a1c44c3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 80 deletions.
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
83 changes: 26 additions & 57 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,51 +605,27 @@ 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) {
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");
public static String getPageUrl(Page page) {
SpaceService spaceService = CommonsUtils.getService(SpaceService.class);
WebAppController webAppController = CommonsUtils.getService(WebAppController.class);
Router router = webAppController.getRouter();
Space space = spaceService.getSpaceByGroupId(page.getWikiOwner());
if(space==null){
return "";
Space space = spaceService.getSpaceByGroupId(page.getWikiOwner());
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";
}
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());

} catch (Exception e) {
return "";
spaceUrl.append(appName);
spaceUrl.append("/");
if (!StringUtils.isEmpty(page.getId())) {
spaceUrl.append(page.getId());
}
return spaceUrl.toString();
}
return "";
}

public static String getWikiAppNameInSpace(String spaceGroupId) {
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 a1c44c3

Please sign in to comment.