From 499703699a1361cf7f577efcb02a97e50cb2d1ff Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Mon, 6 Jul 2015 13:11:58 +0000 Subject: [PATCH] made notification to members option configurable as default, see Feature #121 git-svn-id: https://svn.research-infrastructures.eu/d4science/gcube/trunk/portlets/user/share-updates@117026 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 4 +- distro/changelog.xml | 7 ++- pom.xml | 2 +- .../client/view/ShareUpdateForm.java | 53 +++++++++++-------- .../server/ShareUpdateServiceImpl.java | 20 +++++-- .../shareupdates/shared/UserSettings.java | 15 +++++- 6 files changed, 69 insertions(+), 32 deletions(-) diff --git a/.classpath b/.classpath index 2d35416..a59a67b 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + @@ -31,5 +31,5 @@ - + diff --git a/distro/changelog.xml b/distro/changelog.xml index 160cb42..ae9320b 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,4 +1,8 @@ + + made notification to members option configurable as default, see Feature #121 + Integrated gwt-bootstrap and revised css @@ -7,7 +11,8 @@ Added Client scope handler, to set the scope from the client - and help preventing the browser back button cache problem + and help preventing the browser back button cache problem + diff --git a/pom.xml b/pom.xml index 8b77e91..8c91834 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.gcube.portlets.user share-updates war - 1.7.0-SNAPSHOT + 1.8.0-SNAPSHOT gCube Share Updates Portlet diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/client/view/ShareUpdateForm.java b/src/main/java/org/gcube/portlets/user/shareupdates/client/view/ShareUpdateForm.java index feaf5ac..d6903ba 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/client/view/ShareUpdateForm.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/client/view/ShareUpdateForm.java @@ -20,6 +20,7 @@ import org.gcube.portlets.widgets.fileupload.client.view.UploadProgressPanel; import org.jsonmaker.gwt.client.Jsonizer; import com.google.gwt.core.client.GWT; +import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Style.Display; import com.google.gwt.dom.client.Style.Unit; import com.google.gwt.dom.client.Style.Visibility; @@ -30,7 +31,6 @@ import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiFactory; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; -import com.google.gwt.user.client.Element; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Button; @@ -46,7 +46,6 @@ import com.google.gwt.user.client.ui.Widget; /** * * @author Massimiliano Assante - * @version 1.2 Nov 2012 * */ public class ShareUpdateForm extends Composite { @@ -59,13 +58,13 @@ public class ShareUpdateForm extends Composite { final PageBusAdapter pageBusAdapter = new PageBusAdapter(); // the label for all Vres/channels private final static String ALL_VRES = "Share with: your Virtual Research Environments"; - + protected final static String SHARE_UPDATE_TEXT = "Share an update or a link, use “@” to mention and “#” to add a topic"; protected final static String ERROR_UPDATE_TEXT = "Looks like empty to me!"; public final static String NO_TEXT_FILE_SHARE = "_N0_73X7_SH4R3_"; private final static String LISTBOX_LEVEL = " - "; - - + + public static final String loading = GWT.getModuleBaseURL() + "../images/avatarLoader.gif"; public static final String avatar_default = GWT.getModuleBaseURL() + "../images/Avatar_default.png"; public static final String attach = GWT.getModuleBaseURL() + "../images/attach.png"; @@ -75,7 +74,7 @@ public class ShareUpdateForm extends Composite { */ private String uploadedFilePathOnServer; private String uploadedFileNameOnServer; - + private HandlerManager eventBus = new HandlerManager(null); private static ShareUpdateFormUiBinder uiBinder = GWT @@ -110,10 +109,10 @@ public class ShareUpdateForm extends Composite { @UiField SuperPosedTextArea shareTextArea; @UiField - ListBox privacyLevel = new ListBox(false); - + ListBox privacyLevel = new ListBox(); + @UiField - ListBox notifyListbox = new ListBox(false); + ListBox notifyListbox = new ListBox(); private UserInfo myUserInfo; @@ -131,18 +130,18 @@ public class ShareUpdateForm extends Composite { } }); } - + public ShareUpdateForm() { initWidget(uiBinder.createAndBindUi(this)); singleton = this; bind(); avatarImage.setUrl(loading); shareTextArea.setText(SHARE_UPDATE_TEXT); - + attachButton.getElement().getStyle().setDisplay(Display.INLINE); attachButton.setHTML("    "); - - + + shareupdateService.getUserSettings(new AsyncCallback() { public void onFailure(Throwable caught) { avatarImage.setSize("60px", "60px"); @@ -155,6 +154,9 @@ public class ShareUpdateForm extends Composite { avatarImage.setSize("60px", "60px"); avatarImage.setUrl(myUserInfo.getAvatarId()); String singleVREName = ""; + + boolean notificationEmail = userSettings.isNotificationViaEmailEnabled(); + if (myUserInfo.getOwnVREs().size() > 1) { privacyLevel.addItem(ALL_VRES, PrivacyLevel.VRES.toString()); for (String vreId : myUserInfo.getOwnVREs().keySet()) @@ -171,9 +173,14 @@ public class ShareUpdateForm extends Composite { privacyLevel.addItem("Share with: Everyone", PrivacyLevel.PORTAL.toString()); //change css if deployed in VRE scope if (!userSettings.isInfrastructure()) { - mainPanel.addStyleName("framed"); - notifyListbox.addItem("Share with: " + singleVREName); - notifyListbox.addItem("Share with: " + singleVREName+" + Notification to members"); + mainPanel.addStyleName("framed"); + if (notificationEmail) { + notifyListbox.addItem("Share with: " + singleVREName+" + Notification to members"); + notifyListbox.addItem("Share with: " + singleVREName); + } else { + notifyListbox.addItem("Share with: " + singleVREName); + notifyListbox.addItem("Share with: " + singleVREName+" + Notification to members"); + } notifyListbox.setVisible(true); } else @@ -181,7 +188,7 @@ public class ShareUpdateForm extends Composite { } }); } - + /** Used by UiBinder to instantiate UploadProgressView */ @UiFactory UploadProgressPanel instatiateProgressView() { @@ -213,7 +220,7 @@ public class ShareUpdateForm extends Composite { public static native void fileBrowse(Element el) /*-{ el.click(); }-*/; - + @UiHandler("submitButton") void onClick(ClickEvent e) { @@ -229,7 +236,7 @@ public class ShareUpdateForm extends Composite { } myUserInfo = result.getUserInfo(); String toShare = shareTextArea.getText().trim(); - + //We allow to post a file without writing nothing in the sharing textarea if (myLinkPreviewer != null && myLinkPreviewer.isSharingFile() && (toShare.equals(SHARE_UPDATE_TEXT) || toShare.equals(ERROR_UPDATE_TEXT) || toShare.equals("")) ) { toShare = NO_TEXT_FILE_SHARE; @@ -280,7 +287,7 @@ public class ShareUpdateForm extends Composite { } LinkPreview preview2Share = new LinkPreview(linkTitle, linkDescription, linkUrl, linkHost, null); boolean notifyGroup = notifyListbox.getSelectedIndex() > 0; - + shareupdateService.share(toShare, FeedType.TWEET, getPrivacyLevel(), vreId, preview2Share, linkUrlThumbnail, mentionedUsers, fileName, filePath, notifyGroup, new AsyncCallback() { public void onFailure(Throwable caught) { submitButton.setEnabled(true); @@ -395,7 +402,7 @@ public class ShareUpdateForm extends Composite { final Button close = new Button("Try Again"); final HTML reportIssue = new HTML("" + "Report the issue"); - + close.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { @@ -403,7 +410,7 @@ public class ShareUpdateForm extends Composite { preview.remove(hp); } }); - + hp.setVerticalAlignment(HasAlignment.ALIGN_MIDDLE); hp.add(close); hp.add(reportIssue); @@ -419,7 +426,7 @@ public class ShareUpdateForm extends Composite { uploadedFilePathOnServer = absolutePathOnServer; uploadedFileNameOnServer = fileName; submitButton.setEnabled(true); - + } }); } diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java index 6c1fa09..71055d2 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/server/ShareUpdateServiceImpl.java @@ -28,7 +28,9 @@ import org.gcube.contentmanagement.blobstorage.service.IClient; import org.gcube.contentmanager.storageclient.wrapper.AccessType; import org.gcube.contentmanager.storageclient.wrapper.MemoryType; import org.gcube.contentmanager.storageclient.wrapper.StorageClient; +import org.gcube.portal.custom.communitymanager.OrganizationManager; import org.gcube.portal.custom.communitymanager.OrganizationsUtil; +import org.gcube.portal.custom.communitymanager.impl.OrganizationManagerImpl; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; import org.gcube.portal.databook.server.DatabookStore; @@ -116,7 +118,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar } public String getDevelopmentUser() { String user = TEST_USER; -// user = "massimiliano.assante"; + user = "massimiliano.assante"; return user; } /** @@ -272,16 +274,20 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar String thumbnailURL = "images/Avatar_default.png"; if (isWithinPortal() && username.compareTo(TEST_USER) != 0) { - com.liferay.portal.model.UserModel user = UserLocalServiceUtil.getUserByScreenName(OrganizationsUtil.getCompany().getCompanyId(), username); + long companyId = OrganizationsUtil.getCompany().getCompanyId(); + com.liferay.portal.model.UserModel user = UserLocalServiceUtil.getUserByScreenName(companyId, username); + Organization currOrg = OrganizationLocalServiceUtil.getOrganization(session.getGroupId()); thumbnailURL = "/image/user_male_portrait?img_id="+user.getPortraitId(); fullName = user.getFirstName() + " " + user.getLastName(); email = user.getEmailAddress(); ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY); + String accountURL = themeDisplay.getURLMyAccount().toString(); HashMap vreNames = getUserVreNames(username); UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, user.getEmailAddress(), accountURL, true, isAdmin(), vreNames); - UserSettings toReturn = new UserSettings(userInfo, 0, session.getScopeName(), isInfrastructureScope()); + + UserSettings toReturn = new UserSettings(userInfo, 0, session.getScopeName(), isInfrastructureScope(), isNotificationViaEmailEnabled(username, currOrg)); return toReturn; } else { @@ -291,7 +297,7 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar //fakeVreNames.put("/gcube/devNext/NexNext","NexNext"); UserInfo user = new UserInfo(session.getUsername(), fullName, thumbnailURL, email, "fakeAccountUrl", true, false, fakeVreNames); - return new UserSettings(user, 0, session.getScopeName(), false); + return new UserSettings(user, 0, session.getScopeName(), false, true); } } catch (Exception e) { @@ -299,6 +305,12 @@ public class ShareUpdateServiceImpl extends RemoteServiceServlet implements Shar } return new UserSettings(); } + + private boolean isNotificationViaEmailEnabled(String username, Organization currOrg) { + final String ATTR_TO_CHECK = "PostNotificationViaEmail"; + return OrganizationManagerImpl.get().readOrganizationCustomAttribute(username, currOrg, ATTR_TO_CHECK); + } + /** * generate a preview of the file, upload the file on the storage and shorts the link */ diff --git a/src/main/java/org/gcube/portlets/user/shareupdates/shared/UserSettings.java b/src/main/java/org/gcube/portlets/user/shareupdates/shared/UserSettings.java index 6200aa8..d052306 100644 --- a/src/main/java/org/gcube/portlets/user/shareupdates/shared/UserSettings.java +++ b/src/main/java/org/gcube/portlets/user/shareupdates/shared/UserSettings.java @@ -10,17 +10,30 @@ public class UserSettings implements Serializable { private int refreshingTimeInMillis; private String currentScope; boolean isInfrastructure; + boolean isNotificationViaEmailEnabled; public UserSettings() { super(); } + public UserSettings(UserInfo userInfo, int refreshingTimeInMillis, - String currentScope, boolean isInfrastructure) { + String currentScope, boolean isInfrastructure, + boolean isNotificationViaEmailEnabled) { super(); this.userInfo = userInfo; this.refreshingTimeInMillis = refreshingTimeInMillis; this.currentScope = currentScope; this.isInfrastructure = isInfrastructure; + this.isNotificationViaEmailEnabled = isNotificationViaEmailEnabled; } + + public boolean isNotificationViaEmailEnabled() { + return isNotificationViaEmailEnabled; + } + + public void setNotificationViaEmailEnabled(boolean isNotificationViaEmailEnabled) { + this.isNotificationViaEmailEnabled = isNotificationViaEmailEnabled; + } + public UserInfo getUserInfo() { return userInfo; }