diff --git a/.classpath b/.classpath index 5b0cb7b..c35f92b 100644 --- a/.classpath +++ b/.classpath @@ -1,19 +1,27 @@ - + - + + + + + - + + + + + @@ -31,5 +39,5 @@ - + diff --git a/.project b/.project index d5b1692..50f52f0 100644 --- a/.project +++ b/.project @@ -55,5 +55,6 @@ org.eclipse.wst.common.project.facet.core.nature org.eclipse.wst.jsdt.core.jsNature com.google.gwt.eclipse.core.gwtNature + com.liferay.ide.core.liferayNature diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 7397c4c..350a0b1 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -3,6 +3,7 @@ + uses diff --git a/pom.xml b/pom.xml index 6e6277c..9abc508 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ org.gcube.portlets.user gcube-loggedin war - 3.0.0-SNAPSHOT + 3.1.0-SNAPSHOT gCube Environment Home Portlet diff --git a/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinService.java b/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinService.java index 728e0d2..7f46c2d 100644 --- a/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinService.java +++ b/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinService.java @@ -13,4 +13,7 @@ public interface LoggedinService extends RemoteService { VObject getSelectedRE(String portalURL); String saveVREDescription(String toSave); + + boolean isLeaveButtonAvailable(String currentUrl); + String removeUserFromVRE(); } diff --git a/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinServiceAsync.java b/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinServiceAsync.java index 30335ad..fac6eb5 100644 --- a/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinServiceAsync.java +++ b/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/LoggedinServiceAsync.java @@ -11,4 +11,7 @@ public interface LoggedinServiceAsync { void getSelectedRE(String portalURL, AsyncCallback callback); void saveVREDescription(String toSave, AsyncCallback callback); + void isLeaveButtonAvailable(String currentUrl, + AsyncCallback callback); + void removeUserFromVRE(AsyncCallback callback); } diff --git a/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/ui/AboutView.java b/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/ui/AboutView.java index 1f55b3f..47f0a6f 100644 --- a/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/ui/AboutView.java +++ b/src/main/java/org/gcube/portlets/user/gcubeloggedin/client/ui/AboutView.java @@ -1,19 +1,32 @@ package org.gcube.portlets.user.gcubeloggedin.client.ui; +import org.gcube.portlets.user.gcubeloggedin.client.LoggedinService; import org.gcube.portlets.user.gcubeloggedin.client.LoggedinServiceAsync; import org.gcube.portlets.user.gcubeloggedin.shared.VObject; +import org.gcube.portlets.user.gcubewidgets.client.elements.Span; +import org.gcube.portlets.widgets.sessionchecker.client.CheckSession; +import com.github.gwtbootstrap.client.ui.AlertBlock; import com.github.gwtbootstrap.client.ui.Button; import com.github.gwtbootstrap.client.ui.Heading; import com.github.gwtbootstrap.client.ui.Hero; import com.github.gwtbootstrap.client.ui.Image; +import com.github.gwtbootstrap.client.ui.constants.AlertType; +import com.github.gwtbootstrap.client.ui.constants.ButtonType; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; +import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; +import com.google.gwt.user.client.Window; +import com.google.gwt.user.client.Window.Location; +import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTML; +import com.google.gwt.user.client.ui.HasAlignment; +import com.google.gwt.user.client.ui.InlineHTML; +import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.ui.Widget; public class AboutView extends Composite { @@ -21,7 +34,17 @@ public class AboutView extends Composite { private static int MAX_CHAR_DESC = 400; private static String SEE_LESS = "See less"; private static String SEE_MORE = "See more"; + private Button leaveVreButton = new Button("Leave Group"); + private AlertBlock alertBlockOnLeave = new AlertBlock(); + // more options label to show the other ones (if present) + final Button showMoreOptions = new Button("Other options ..."); + private static final String leaveAlertMessage = "Are you sure you want to leave this group? " + + "By leaving this group you will no longer receive updates and lose the workspace folder related to the group."; + // panel for leave group option + private VerticalPanel leaveVREOption = new VerticalPanel(); + + private final LoggedinServiceAsync service = GWT.create(LoggedinService.class); private static AboutViewUiBinder uiBinder = GWT .create(AboutViewUiBinder.class); @@ -32,6 +55,7 @@ public class AboutView extends Composite { initWidget(uiBinder.createAndBindUi(this)); } + private String vreDescription; @UiField Image vreImage; @UiField Heading vreName; @@ -60,6 +84,41 @@ public class AboutView extends Composite { editButton.setVisible(true); } mod = new EditDescriptionModal(vobj.getName(), vobj.getDescription()); + + service.isLeaveButtonAvailable(Location.getHref(), new AsyncCallback() { + + @Override + public void onSuccess(Boolean result) { + leaveVREOption.clear(); + leaveVREOption.setHorizontalAlignment(HasAlignment.ALIGN_LEFT); + if(result) + addLeaveVREButton(); + showMoreOptions.setVisible(result); + } + + @Override + public void onFailure(Throwable caught) { + leaveVREOption.clear(); + } + }); + + + showMoreOptions.setType(ButtonType.LINK); + // handler + showMoreOptions.addClickHandler(new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + // hide the button itself + showMoreOptions.setVisible(false); + // show other options + leaveVREOption.setVisible(true); + } + }); + mainPanel.add(showMoreOptions); + mainPanel.add(leaveVREOption); + + // hide options but askManagersOption + leaveVREOption.setVisible(false); } boolean open = false; @UiHandler("seeMore") @@ -80,7 +139,71 @@ public class AboutView extends Composite { void onEditButton(ClickEvent e) { mod.show(); } + private void addLeaveVREButton(){ + + // add leave VRE button + leaveVreButton.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + // show alert block + alertBlockOnLeave.setVisible(true); + } + }); + + // Add Cancel and Confirm Leave buttons + Span cancel = new Span("Cancel"); + Span confirmLeave = new Span("Confirm Leave"); + cancel.setStyleName("cancel-leave-button"); + confirmLeave.setStyleName("cancel-leave-button"); + + // add to main panel + alertBlockOnLeave.setHTML(leaveAlertMessage + "

"); + alertBlockOnLeave.add(cancel); + alertBlockOnLeave.add(new InlineHTML(" or ")); + alertBlockOnLeave.add(confirmLeave); + alertBlockOnLeave.setType(AlertType.WARNING); + alertBlockOnLeave.setHeading("WARNING!"); + alertBlockOnLeave.setClose(false); + alertBlockOnLeave.setVisible(false); + leaveVREOption.add(alertBlockOnLeave); + leaveVREOption.add(leaveVreButton); + + // add handlers + cancel.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event) { + + // just hide alertBlock + alertBlockOnLeave.setVisible(false); + } + }); + + confirmLeave.addClickHandler(new ClickHandler() { + + @Override + public void onClick(ClickEvent event){ + service.removeUserFromVRE(new AsyncCallback() { + @Override + public void onSuccess(String result) { + if (result != null) + Location.assign(result); + else + CheckSession.showLogoutDialog(); + + } + @Override + public void onFailure(Throwable caught) { + Window.alert("We're sorry we couldn't reach the server, try again later ... " + caught.getMessage()); + } + }); + + } + }); + } /** diff --git a/src/main/java/org/gcube/portlets/user/gcubeloggedin/server/LoggedinServiceImpl.java b/src/main/java/org/gcube/portlets/user/gcubeloggedin/server/LoggedinServiceImpl.java index 9d551b2..1de0f16 100644 --- a/src/main/java/org/gcube/portlets/user/gcubeloggedin/server/LoggedinServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/gcubeloggedin/server/LoggedinServiceImpl.java @@ -1,13 +1,14 @@ package org.gcube.portlets.user.gcubeloggedin.server; import java.util.ArrayList; -import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.SessionManager; +import org.gcube.common.portal.PortalContext; +import org.gcube.common.portal.mailing.EmailNotification; import org.gcube.portal.custom.scopemanager.scopehelper.ScopeHelper; import org.gcube.portlets.user.gcubeloggedin.client.LoggedinService; import org.gcube.portlets.user.gcubeloggedin.shared.VObject; @@ -17,9 +18,6 @@ import org.gcube.portlets.user.gcubewidgets.server.ScopeServiceImpl; import org.gcube.vomanagement.usermanagement.GroupManager; import org.gcube.vomanagement.usermanagement.RoleManager; import org.gcube.vomanagement.usermanagement.UserManager; -import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; -import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; -import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault; import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager; import org.gcube.vomanagement.usermanagement.impl.LiferayRoleManager; import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; @@ -30,6 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.gwt.user.server.rpc.RemoteServiceServlet; +import com.liferay.portal.service.UserLocalServiceUtil; /** * The server side implementation of the RPC service. @@ -106,9 +105,9 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi _log.trace("CURRENT ORG SET IN SESSION: " + currSite.getGroupName()); - long nowInMillis = new Date().getTime(); + String name = currSite.getGroupName(); - String logoURL = "/image/layout_set_logo?img_id="+currSite.getLogoId()+"&t="+nowInMillis; + String logoURL = gm.getGroupLogoURL(currSite.getLogoId()); String desc = ""; //set the description for the vre if (currSite.getDescription() != null) @@ -190,6 +189,127 @@ public class LoggedinServiceImpl extends RemoteServiceServlet implements Loggedi } return null; } + @Override + public boolean isLeaveButtonAvailable(String portalURL) { + if(isWithinPortal()){ + String friendlyURL = ScopeServiceImpl.extractOrgFriendlyURL(portalURL); + GroupManager gm = new LiferayGroupManager(); + GCubeGroup currSite = null; + try { + List groups = gm.listGroups(); + for (GCubeGroup g : groups) { + if (g.getFriendlyURL().compareTo(friendlyURL) == 0) { + long groupId = g.getGroupId(); + String scopeToSet = gm.getInfrastructureScope(groupId); + getASLSession().setScope(scopeToSet); + _log.info("GOT Selected Research Environment: " + scopeToSet); + currSite = g; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + Boolean isMandatory = false; + try{ + isMandatory = (Boolean) gm.readCustomAttr(currSite.getGroupId(), org.gcube.vomanagement.usermanagement.model.CustomAttributeKeys.MANDATORY.getKeyName()); + }catch(Exception e){ + _log.error("Unable to evaluate if the leave button can be added for the current group " + currSite.getGroupName(), e); + } + _log.debug("Is Leave button available in vre " + currSite.getGroupName() + " ? " + isMandatory); + return !isMandatory; + }else return true; + } + /** + *@return the redirect url if everything goes ok, null otherwise + */ + @Override + public String removeUserFromVRE() { + String username = getASLSession().getUsername(); + if (username.compareTo("test.user") == 0) + return null; + _log.debug("Going to remove user from the current Group: " + getCurrentGroupID() + ". Username is: " + username); + UserManager userM = new LiferayUserManager(); + try { + userM.dismissUserFromGroup(getCurrentGroupID(), userM.getUserId(username)); + sendUserUnregisteredNotification(username, getASLSession().getScope(), + PortalContext.getConfiguration().getGatewayURL(getThreadLocalRequest()), + PortalContext.getConfiguration().getGatewayName(getThreadLocalRequest())); + return "/"; + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + /** + * Get the current group ID + * + * @return the current group ID or null if an exception is thrown + * @throws Exception + * @throws CurrentGroupRetrievalException + */ + private long getCurrentGroupID(){ + GroupManager groupM = new LiferayGroupManager(); + ASLSession session = getASLSession(); + _log.debug("The current group NAME is --> " + session.getGroupName()); + try { + return groupM.getGroupId(session.getGroupName()); + } catch (Exception e) { + e.printStackTrace(); + } + return 0; + } + /** + * + * @return true if you're running into the portal, false if in development + */ + private boolean isWithinPortal() { + try { + UserLocalServiceUtil.getService(); + return true; + } + catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) { + _log.trace("Development Mode ON"); + return false; + } + } + /** + * + * @param scope . + * @param optionalMessage . + */ + public void sendUserUnregisteredNotification(String username, String scope, String portalbasicurl, String gatewayName) { + ArrayList adminEmails = getAdministratorsEmails(scope); + UserManager um = new LiferayUserManager(); + GCubeUser currUser = null; + try { + currUser = um.getUserByUsername(username); + } catch (Exception e) { + + } + String name = currUser.getFirstName(); + String lastname = currUser.getLastName(); + StringBuffer body = new StringBuffer(); + body.append("

Dear manager of "+ scope +",
this email message was automatically generated by " + portalbasicurl +" to inform you that "); + body.append("

"); + body.append("

"); + body.append(""+name + " " + lastname +" has left the following environment: "); + body.append("

"); + body.append("" + scope+""); + body.append("
"); + body.append("
"); + body.append("Username: " + username); + body.append("
"); + body.append("e-mail: " + currUser.getEmail()); + body.append("

"); + + String[] allMails = new String[adminEmails.size()]; + + adminEmails.toArray(allMails); + + EmailNotification mailToAdmin = new EmailNotification(allMails , "Unregistration from VRE", body.toString(), getThreadLocalRequest()); + + mailToAdmin.sendEmail(); + } } diff --git a/src/main/webapp/WEB-INF/portlet.xml b/src/main/webapp/WEB-INF/portlet.xml index 9afe0e6..ed2ef1f 100644 --- a/src/main/webapp/WEB-INF/portlet.xml +++ b/src/main/webapp/WEB-INF/portlet.xml @@ -3,7 +3,7 @@ Loggedin - Environment Home + About org.gcube.portlets.user.gcubeloggedin.server.portlet.LoggedinPortlet view-jsp @@ -14,9 +14,9 @@ text/html - Environment Home - Environment Home - Environment Home + About + About + Environment Home About administrator