Skip to content

Commit

Permalink
feat: Implement hide author advanced publication settings option - EX…
Browse files Browse the repository at this point in the history
…O-72746 -  Meeds-io/MIPs#161 (#1196)

Implement hide author advanced publication settings option

fix: Unable to update hideReaction property in case of existing translation versions - EXO-72747 - Meeds-io/MIPs#161 (#1199)

Unable to update hideReaction/hideAuthor property in case of existing translation
versions
  • Loading branch information
hakermi committed Nov 8, 2024
1 parent 94bdf7a commit fbe41eb
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ public class NotePageProperties implements Serializable {

private NoteFeaturedImage featuredImage;

private boolean hideAuthor;

private boolean isDraft;

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class PagePropertiesEntity implements Serializable {
private String summary;

private FeaturedImageEntity featuredImage;

private boolean hideAuthor;

private boolean isDraft;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static NotePageProperties toNotePageProperties(PagePropertiesEntity pageP
return new NotePageProperties(pagePropertiesEntity.getNoteId(),
pagePropertiesEntity.getSummary(),
toNoteFeaturedImage(pagePropertiesEntity.getFeaturedImage()),
pagePropertiesEntity.isHideAuthor(),
pagePropertiesEntity.isDraft());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.exoplatform.social.core.space.model.Space;
import org.exoplatform.social.core.space.spi.SpaceService;
import org.exoplatform.social.metadata.MetadataService;
import org.exoplatform.social.metadata.model.MetadataItem;
import org.exoplatform.social.metadata.model.MetadataKey;
import org.exoplatform.social.metadata.model.MetadataType;
import org.exoplatform.wiki.WikiException;
Expand All @@ -51,23 +52,26 @@

import java.io.ByteArrayInputStream;
import java.util.*;
import java.util.stream.Collectors;

/**
* Utility class to convert JPA entity objects
*/
public class EntityConverter {

private static final Log LOG = ExoLogger.getLogger(EntityConverter.class);
private static final Log LOG = ExoLogger.getLogger(EntityConverter.class);

private static SpaceService spaceService;
private static SpaceService spaceService;

private static MetadataService metadataService;
private static MetadataService metadataService;

public static final MetadataType NOTES_METADATA_TYPE = new MetadataType(1001, "notes");
public static final MetadataType NOTES_METADATA_TYPE = new MetadataType(1001, "notes");

public static final MetadataKey NOTES_METADATA_KEY = new MetadataKey(NOTES_METADATA_TYPE.getName(),
Utils.NOTES_METADATA_OBJECT_TYPE,
0);
public static final MetadataKey NOTES_METADATA_KEY = new MetadataKey(NOTES_METADATA_TYPE.getName(),
Utils.NOTES_METADATA_OBJECT_TYPE,
0);

private static final List<String> ORIGINAL_SHARED_PROPERTIES = List.of("hideReaction", "hideAuthor");

public static Wiki convertWikiEntityToWiki(WikiEntity wikiEntity) {
Wiki wiki = null;
Expand Down Expand Up @@ -147,7 +151,7 @@ public static Page convertPageEntityToPage(PageEntity pageEntity) {
}
return page;
}

public static void buildNotePageMetadata(Page note, boolean isDraft) {
if (note == null) {
return;
Expand All @@ -158,6 +162,7 @@ public static void buildNotePageMetadata(Page note, boolean isDraft) {
if (note.getLang() != null) {
noteId = noteId + "-" + note.getLang();
}
Map<String, String> originalNoteSharedProperties = getOriginalNoteSharedProperties(note, space.getId());
NoteMetadataObject noteMetadataObject = new NoteMetadataObject(isDraft ? "noteDraftPage" : "notePage",
noteId,
note.getParentPageId(),
Expand All @@ -167,40 +172,13 @@ public static void buildNotePageMetadata(Page note, boolean isDraft) {
.findFirst()
.ifPresent(metadataItem -> {
if (!MapUtils.isEmpty(metadataItem.getProperties())) {
buildPageProperties(metadataItem.getProperties(), note);
buildPageProperties(metadataItem.getProperties(), originalNoteSharedProperties, note);
}
});

}
}

private static void buildPageProperties(Map<String, String> properties, Page note) {
NotePageProperties notePageProperties = new NotePageProperties();
NoteFeaturedImage noteFeaturedImage = new NoteFeaturedImage();
notePageProperties.setNoteId(Long.parseLong(note.getId()));
notePageProperties.setSummary(properties.get(NoteServiceImpl.SUMMARY_PROP));
noteFeaturedImage.setId(Long.valueOf(properties.getOrDefault(NoteServiceImpl.FEATURED_IMAGE_ID, "0")));
noteFeaturedImage.setLastUpdated(Long.valueOf(properties.getOrDefault(NoteServiceImpl.FEATURED_IMAGE_UPDATED_DATE, "0")));
noteFeaturedImage.setAltText(properties.get(NoteServiceImpl.FEATURED_IMAGE_ALT_TEXT));
notePageProperties.setDraft(note.isDraftPage());
notePageProperties.setFeaturedImage(noteFeaturedImage);
note.setProperties(notePageProperties);
}

private static SpaceService getSpaceService() {
if (spaceService == null) {
spaceService = CommonsUtils.getService(SpaceService.class);
}
return spaceService;
}

private static MetadataService getMetadataService() {
if (metadataService == null) {
metadataService = CommonsUtils.getService(MetadataService.class);
}
return metadataService;
}

public static List<PermissionEntry> convertPermissionEntitiesToPermissionEntries(List<PermissionEntity> permissionEntities,
List<PermissionType> filteredPermissionTypes) {
List<PermissionEntry> permissionEntries = new ArrayList<>();
Expand Down Expand Up @@ -586,4 +564,58 @@ public static List<PageHistory> toPageHistoryVersions(List<PageVersionEntity> pa
public static List<DraftPage> toDraftPages(List<DraftPageEntity> draftPageEntities) {
return draftPageEntities.stream().map(EntityConverter::convertDraftPageEntityToDraftPage).toList();
}

private static Map<String, String> getOriginalNoteSharedProperties(Page note, String spaceId) {
if (note.getLang() == null || note.isDraftPage()) {
return new HashMap<>();
}
NoteMetadataObject originalNoteMetadataObject = new NoteMetadataObject("notePage",
note.getId(),
note.getParentPageId(),
Long.parseLong(spaceId));
List<MetadataItem> metadataItems = getMetadataService().getMetadataItemsByMetadataAndObject(NOTES_METADATA_KEY,
originalNoteMetadataObject);
Map<String, String> originalNoteSharedProperties = new HashMap<>();
if (!CollectionUtils.isEmpty(metadataItems)) {
originalNoteSharedProperties = metadataItems.getFirst().getProperties();
}
return originalNoteSharedProperties.entrySet()
.stream()
.filter(entry -> ORIGINAL_SHARED_PROPERTIES.contains(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}

private static void buildPageProperties(Map<String, String> properties,
Map<String, String> originalNoteSharedProperties,
Page note) {
Map<String, String> finalProperties = new HashMap<>(properties);
finalProperties.putAll(originalNoteSharedProperties);
NotePageProperties notePageProperties = new NotePageProperties();
NoteFeaturedImage noteFeaturedImage = new NoteFeaturedImage();
notePageProperties.setNoteId(Long.parseLong(note.getId()));
notePageProperties.setSummary(finalProperties.get(NoteServiceImpl.SUMMARY_PROP));
notePageProperties.setHideAuthor(Boolean.parseBoolean(finalProperties.getOrDefault(NoteServiceImpl.HIDE_AUTHOR_PROP,
"false")));
noteFeaturedImage.setId(Long.valueOf(finalProperties.getOrDefault(NoteServiceImpl.FEATURED_IMAGE_ID, "0")));
noteFeaturedImage.setLastUpdated(Long.valueOf(finalProperties.getOrDefault(NoteServiceImpl.FEATURED_IMAGE_UPDATED_DATE,
"0")));
noteFeaturedImage.setAltText(finalProperties.get(NoteServiceImpl.FEATURED_IMAGE_ALT_TEXT));
notePageProperties.setDraft(note.isDraftPage());
notePageProperties.setFeaturedImage(noteFeaturedImage);
note.setProperties(notePageProperties);
}

private static SpaceService getSpaceService() {
if (spaceService == null) {
spaceService = CommonsUtils.getService(SpaceService.class);
}
return spaceService;
}

private static MetadataService getMetadataService() {
if (metadataService == null) {
metadataService = CommonsUtils.getService(MetadataService.class);
}
return metadataService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public class NoteServiceImpl implements NoteService {

public static final String SUMMARY_PROP = "summary";

public static final String HIDE_AUTHOR_PROP = "hideAuthor";

public static final String FEATURED_IMAGE_ID = "featuredImageId";

public static final String FEATURED_IMAGE_UPDATED_DATE = "featuredImageUpdatedDate";
Expand Down Expand Up @@ -1753,6 +1755,7 @@ public NotePageProperties saveNoteMetadata(NotePageProperties notePageProperties
properties = metadataItem.getProperties();
}
properties.put(SUMMARY_PROP, notePageProperties.getSummary());
properties.put(HIDE_AUTHOR_PROP, String.valueOf(notePageProperties.isHideAuthor()));
if (featuredImageId != null) {
properties.put(FEATURED_IMAGE_ID, String.valueOf(featuredImageId));
properties.put(FEATURED_IMAGE_UPDATED_DATE, String.valueOf(new Date().getTime()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,14 @@ public void testRemoveOrphanDraftPagesByParentPage() throws Exception {
}

private Page createTestNoteWithVersionLang(String name, String lang, Identity user) throws Exception {
Wiki portalWiki = getOrCreateWiki(wService, PortalConfig.PORTAL_TYPE, "testPortal");
identityManager.getOrCreateUserIdentity("root");
Space space = new Space();
space.setDisplayName("test");
space.setPrettyName("test");
space.setRegistration(Space.OPEN);
space.setVisibility(Space.PUBLIC);
space = spaceService.createSpace(space, "root");
Wiki portalWiki = getOrCreateWiki(wService, PortalConfig.PORTAL_TYPE, space.getGroupId());
Page note = noteService.createNote(portalWiki, "Home", new Page(name, name), user);
note.setLang(lang);
note.setTitle("language title");
Expand Down Expand Up @@ -997,6 +1004,31 @@ public void testGetDraftsOfWiki() throws Exception {
draftPage.setParentPageId(note2.getId());
noteService.createDraftForExistPage(draftPage, note, null, new Date().getTime(), "root");
assertEquals(2, noteService.getDraftsOfWiki(portalWiki.getOwner(), portalWiki.getType(), portalWiki.getWikiHome().getName()).size());
}

public void testSaveHideAuthorProperty() throws Exception {
Identity user = new Identity("user");
Page note = createTestNoteWithVersionLang("testMetadataHideAuthor", null, user);

this.bindMockedUploadService();

NotePageProperties notePageProperties = createNotePageProperties(Long.parseLong(note.getId()), "alt text", "summary test");
notePageProperties.setHideAuthor(true);
NotePageProperties properties = noteService.saveNoteMetadata(notePageProperties, null, 1L);
assertEquals("summary test", properties.getSummary());
assertTrue(properties.isHideAuthor());

note.setLang("en");
note.setTitle("en title");
note.setContent("en content");
noteService.createVersionOfNote(note, user.getUserId());
notePageProperties = createNotePageProperties(Long.parseLong(note.getId()), "alt text en", "summary test en");
notePageProperties.setHideAuthor(false);
noteService.saveNoteMetadata(notePageProperties, "en", 1L);

// when fetch version language metadata properties we should return the original
// note properties values in case of shared original properties values
note = noteService.getNoteByIdAndLang(Long.valueOf(note.getId()), "en");
assertTrue(note.getProperties().isHideAuthor());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ notes.publication.endTime.label=End time
notes.publication.settings.update.success=Publication settings updated successfully
notes.publication.settings.update.error=Error while updating publication settings
notes.publication.schedule.publish.now.tooltip=By scheduling only a end date you will publish now
notes.publication.advanced.option.label=Advanced options
notes.publication.hide.author.label=Hide author

popup.confirm=Confirm
popup.msg.confirmation=Confirmation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ notes.publication.endTime.label=Heure de fin
notes.publication.settings.update.success=Les paramétres de publication ont été mis \u00E0 jour avec succés
notes.publication.settings.update.error=Erreur lors de la mise \u00E0 jour des paramétres de publication
notes.publication.schedule.publish.now.tooltip=En programmant uniquement une date de fin vous allez publier de suite
notes.publication.advanced.option.label=Options avancées
notes.publication.hide.author.label=Masquer l'auteur

popup.confirm=Confirmer
popup.msg.confirmation=Confirmation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@
}"
ref="scheduleOption"
@updated="updatedScheduleSettings" />
<note-publication-advanced-option
:edit-mode="editMode"
:is-publishing="isPublishing"
:saved-advanced-settings="{
hideAuthor: currentAdvancedSettings?.hideAuthor
}"
ref="advancedOption"
@update="updateAdvancedSettings"/>
</div>
</v-scroll-y-transition>
</div>
Expand Down Expand Up @@ -208,8 +216,10 @@ export default {
post: true
},
scheduleSettings: {},
advancedSettings: {},
currentPublicationSettings: {},
currentScheduleSettings: {}
currentScheduleSettings: {},
currentAdvancedSettings: {}
};
},
props: {
Expand Down Expand Up @@ -287,10 +297,16 @@ export default {
}
},
methods: {
updateAdvancedSettings(settings) {
this.advancedSettings = structuredClone(settings);
this.publicationSettings.advancedSettings = this.advancedSettings;
this.noteObject.properties.hideAuthor = this.advancedSettings?.hideAuthor;
},
updatedPublicationSettings(settings) {
this.publicationSettings = structuredClone({
post: this.publicationSettings.post,
scheduleSettings: this.publicationSettings.scheduleSettings
scheduleSettings: this.publicationSettings.scheduleSettings,
advancedSettings: this.publicationSettings.advancedSettings
});
this.publicationSettings.publish = settings?.publish;
this.publicationSettings.selectedTargets = settings?.selectedTargets;
Expand Down Expand Up @@ -321,26 +337,20 @@ export default {
open(noteObject) {
this.noteObject = noteObject;
if (this.editMode) {
this.publicationSettings.post = this.noteObject?.activityPosted;

this.scheduleSettings.schedule = !!this.noteObject?.schedulePostDate || !!this.noteObject?.scheduleUnpublishDate;
this.scheduleSettings.editScheduleAction = this.scheduleSettings.schedule && 'schedule' || null;
this.scheduleSettings.postDate = this.noteObject?.schedulePostDate;
this.scheduleSettings.unpublishDate = this.noteObject?.scheduleUnpublishDate;
this.publicationSettings.scheduleSettings = this.scheduleSettings;

this.publicationSettings.publish = this.noteObject?.published;
this.publicationSettings.selectedTargets = this.noteObject?.targets;
this.publicationSettings.selectedAudience = this.noteObject?.audience;
this.cloneScheduleSettings();
this.cloneAdvancedSettings();
this.clonePublicationSettings();
}
this.currentScheduleSettings = structuredClone(this.scheduleSettings);
this.currentAdvancedSettings = structuredClone(this.advancedSettings);
this.currentPublicationSettings = structuredClone(this.publicationSettings);
this.cloneProperties();
this.$refs.publicationDrawer.open();
this.toggleExpand();
setTimeout(() => {
this.$refs?.publishOption?.initSettings();
this.$refs?.scheduleOption?.initSettings();
this.$refs?.advancedOption?.initSettings();
}, 200);
this.$refs.propertiesForm?.initProperties();
},
Expand All @@ -351,6 +361,23 @@ export default {
}, 50);
}
},
cloneAdvancedSettings() {
this.advancedSettings.hideAuthor = this.noteObject?.properties?.hideAuthor;
},
clonePublicationSettings() {
this.publicationSettings.post = this.noteObject?.activityPosted;
this.publicationSettings.scheduleSettings = this.scheduleSettings;
this.publicationSettings.advancedSettings = this.advancedSettings;
this.publicationSettings.publish = this.noteObject?.published;
this.publicationSettings.selectedTargets = this.noteObject?.targets;
this.publicationSettings.selectedAudience = this.noteObject?.audience;
},
cloneScheduleSettings() {
this.scheduleSettings.schedule = !!this.noteObject?.schedulePostDate || !!this.noteObject?.scheduleUnpublishDate;
this.scheduleSettings.editScheduleAction = this.scheduleSettings.schedule && 'schedule' || null;
this.scheduleSettings.postDate = this.noteObject?.schedulePostDate;
this.scheduleSettings.unpublishDate = this.noteObject?.scheduleUnpublishDate;
},
cloneProperties() {
this.currentNoteProperties = structuredClone(
this.noteObject?.id &&
Expand All @@ -368,6 +395,7 @@ export default {
cancelChanges() {
this.$refs?.publishOption?.cancelChanges();
this.$refs?.scheduleOption?.cancelChanges();
this.$refs?.advancedOption?.cancelChanges();
},
reset() {
setTimeout(() => {
Expand Down
Loading

0 comments on commit fbe41eb

Please sign in to comment.