Added moderation checks when consuming Moderation Link. Implemented

closable tabs
This commit is contained in:
Francesco Mangiacrapa 2022-05-05 11:48:33 +02:00
parent d3954ecd71
commit b3d62d9a3d
5 changed files with 50 additions and 4 deletions

View File

@ -123,9 +123,7 @@ public class CkanContentModeratorCheckConfigs {
};
timer.scheduleRepeating(500);
}
}
/**

View File

@ -36,7 +36,7 @@
<b:Label ui:field="orderInfo" type="DEFAULT" addStyleNames="{style.margin-top-12}"></b:Label>
</b:Nav>
<b:Nav alignment="RIGHT">
<b:NavLink ui:field="closeAllTabs">Close All Tabs
<b:NavLink ui:field="closeAllTabs" visible="false">Close All Tabs
</b:NavLink>
</b:Nav>
</b:Navbar>

View File

@ -3,14 +3,17 @@ package org.gcube.portlets.widgets.ckancontentmoderator.client.ui;
import java.util.ArrayList;
import java.util.List;
import org.gcube.portlets.widgets.ckancontentmoderator.client.resources.ContentModeratorWidgetResources;
import org.gcube.portlets.widgets.ckancontentmoderator.client.ui.util.UtilFunct;
import com.github.gwtbootstrap.client.ui.Icon;
import com.github.gwtbootstrap.client.ui.Tab;
import com.github.gwtbootstrap.client.ui.TabPanel;
import com.github.gwtbootstrap.client.ui.constants.IconType;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.Style.Cursor;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.LoadEvent;
@ -18,6 +21,7 @@ import com.google.gwt.event.dom.client.LoadHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
@ -87,6 +91,26 @@ public class MainTabPanel extends Composite {
public void onLoad(LoadEvent event) {
tab.setIcon(IconType.BOOK);
setNoSpinner(tab);
Icon icon = new Icon(IconType.REMOVE);
icon.setTitle("Close this tab");
icon.getElement().getStyle().setCursor(Cursor.POINTER);
ClickHandler clickHandler = new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
try {
mainTabPanel.remove(tab);
results.remove(tab);
mainTabPanel.selectTab(results.size() - 1);
}catch (Exception e) {
//silent
}
}
};
icon.addDomHandler(clickHandler, ClickEvent.getType());
tab.addDecorate(icon);
}
});
}

View File

@ -35,4 +35,6 @@
.as_simple_link {
background: none !important;
border: none !important;
padding: 0 !important;
margin: 0 !important;
}

View File

@ -248,20 +248,42 @@ public class CkanContentModeratorServiceImpl extends RemoteServiceServlet implem
String scope = setContexts();
DataCatalogueImpl catalogueImpl = CatalogueCMSFactory.getFactory().getCatalogueImplPerScope(scope);
GCubeUser user = GcubeContextUtil.getCurrentUser(this.getThreadLocalRequest());
boolean moderationCheckPassed = false;
if (user != null) {
CkanDataset ckanDataset = catalogueImpl.getDataset(itemName, user.getUsername());
ds = null;
if (ckanDataset != null) {
ds = toPatchedCatalogueDataset(ckanDataset, catalogueImpl.getCatalogueUrl());
Boolean userModerator = isModeratorRoleAssigned();
moderationCheckPassed = userModerator?true:false;
LOG.info("Moderation check: is the user a Moderator? "+moderationCheckPassed);
//The user is not a Moderator, yes otherwise
if(!moderationCheckPassed) {
String datasetAuthorMail = ds.getAuthorEmail();
String userMail = user.getEmail();
if(datasetAuthorMail!=null && userMail!=null && datasetAuthorMail.compareTo(userMail)==0) {
//The user is the owner of the dataset, so he/she can view the dataset (moderation check passed)
moderationCheckPassed = true;
}
LOG.info("Moderation check: is the user the owner of the dataset? "+moderationCheckPassed);
}
}
}
if(!moderationCheckPassed) {
LOG.info("Moderation ckeck not passed, returning null");
ds = null;
}
} catch (Exception e) {
LOG.error("Error occurred on reading item for name: " + itemName, e);
throw e;
}
LOG.info("returning: " + ds);
LOG.info("getItemForName "+itemName+", returning: " + ds);
return ds;
}