Skip to content

Commit

Permalink
feat(licenses): add support for project-only obligations
Browse files Browse the repository at this point in the history
This change introduces a new portlet for managing TODOs under the Admin
menu. There are 2 views. One for listing TODOs saved in the database and
one for adding a new one. In the listing view, the delete action is also
available but can only be executed by users with SW360_ADMIN rights and
above.

This new PrivatePages.lar includes the TODOs management portlet.

Signed-off-by: Nikolas Sepos <[email protected]>
  • Loading branch information
Nikolas Sepos authored and maxhbr committed Jul 24, 2019
1 parent 0401d13 commit c4452fc
Show file tree
Hide file tree
Showing 19 changed files with 459 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,11 @@ public RequestSummary importAllSpdxLicenses(User user) throws TException {
return handler.importAllSpdxLicenses(user);
}

@Override
public RequestStatus deleteTodo(String id, User user) throws TException {
assertId(id);
assertUser(user);
return handler.deleteTodo(id, user);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.eclipse.sw360.datahandler.thrift.moderation.ModerationRequest;
import org.eclipse.sw360.datahandler.thrift.users.RequestedAction;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.users.UserGroup;
import org.eclipse.sw360.licenses.tools.SpdxConnector;

import org.apache.log4j.Logger;
Expand All @@ -43,7 +44,6 @@
import static org.eclipse.sw360.datahandler.common.SW360Assert.assertNotNull;
import static org.eclipse.sw360.datahandler.permissions.PermissionUtils.makePermission;
import static org.eclipse.sw360.datahandler.thrift.ThriftValidate.*;
import static org.eclipse.sw360.datahandler.thrift.users.UserGroup.CLEARING_ADMIN;

/**
* Class for accessing the CouchDB database
Expand Down Expand Up @@ -222,7 +222,7 @@ private void fillLicenseForOrganisation(String organisation, License license) {
* @return ID of the added todo.
*/
public String addTodo(@NotNull Todo todo, User user) throws SW360Exception {
if (!PermissionUtils.isUserAtLeast(CLEARING_ADMIN, user)){
if (!PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)){
return null;
}
prepareTodo(todo);
Expand Down Expand Up @@ -533,7 +533,7 @@ private List<LicenseType> getLicenseTypesFromLicenses(List<License> licenses) {
}

public List<RiskCategory> addRiskCategories(List<RiskCategory> riskCategories, User user) throws SW360Exception {
if (!PermissionUtils.isUserAtLeast(CLEARING_ADMIN, user)){
if (!PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)){
return null;
}
for (RiskCategory riskCategory : riskCategories) {
Expand All @@ -547,7 +547,7 @@ public List<RiskCategory> addRiskCategories(List<RiskCategory> riskCategories, U
}

public List<Risk> addRisks(List<Risk> risks, User user) throws SW360Exception {
if (!PermissionUtils.isUserAtLeast(CLEARING_ADMIN, user)){
if (!PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)){
return null;
}
for (Risk risk : risks) {
Expand All @@ -561,7 +561,7 @@ public List<Risk> addRisks(List<Risk> risks, User user) throws SW360Exception {
}

public List<LicenseType> addLicenseTypes(List<LicenseType> licenseTypes, User user) {
if (!PermissionUtils.isUserAtLeast(CLEARING_ADMIN, user)){
if (!PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)){
return null;
}
final List<DocumentOperationResult> documentOperationResults = licenseTypeRepository.executeBulk(licenseTypes);
Expand Down Expand Up @@ -605,7 +605,7 @@ public List<License> addOrOverwriteLicenses(List<License> licenses, User user, b
}

public List<Obligation> addObligations(List<Obligation> obligations, User user) throws SW360Exception {
if (!PermissionUtils.isUserAtLeast(CLEARING_ADMIN, user)){
if (!PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)){
return null;
}
for (Obligation obligation : obligations) {
Expand All @@ -619,7 +619,7 @@ public List<Obligation> addObligations(List<Obligation> obligations, User user)
}

public List<Todo> addTodos(List<Todo> todos, User user) throws SW360Exception {
if (!PermissionUtils.isUserAtLeast(CLEARING_ADMIN, user)){
if (!PermissionUtils.isUserAtLeast(UserGroup.CLEARING_ADMIN, user)){
return null;
}
for (Todo todo : todos) {
Expand Down Expand Up @@ -897,4 +897,18 @@ public RequestSummary importAllSpdxLicenses(User user) {
.setTotalElements(spdxIds.size())
.setRequestStatus(RequestStatus.SUCCESS);
}

public RequestStatus deleteTodo(String id, User user) throws SW360Exception {
Todo todo = todoRepository.get(id);
assertNotNull(todo);

// Remove the license if the user is allowed to do it by himself
if (PermissionUtils.isUserAtLeast(UserGroup.SW360_ADMIN, user)) {
todoRepository.remove(todo);
return RequestStatus.SUCCESS;
} else {
log.error(user + " does not have the permission to delete todo.");
return RequestStatus.ACCESS_DENIED;
}
}
}
Binary file modified frontend/configuration/PrivatePages.lar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class PortalConstants {
public static final String PAGENAME_DETAIL = "detail";
public static final String PAGENAME_VIEW = "view";
public static final String PAGENAME_IMPORT = "import";
public static final String PAGENAME_ADD = "add";
public static final String PAGENAME_EDIT = "edit";
public static final String PAGENAME_ACTION = "action";
public static final String PAGENAME_DUPLICATE = "duplicate";
Expand Down Expand Up @@ -127,6 +128,10 @@ public class PortalConstants {
public static final String VENDOR_ID = "vendorId";
public static final String VENDOR_LIST = "vendorList";

//! Specialized keys for todos
public static final String TODO_LIST = "todoList";
public static final String TODO_ID = "todoId";

//! Specialized keys for attachments
public static final String ATTACHMENTS = "attachments";
public static final String SPDX_ATTACHMENTS = "spdxAttachments";
Expand Down Expand Up @@ -343,6 +348,9 @@ public class PortalConstants {
// vendor actions
public static final String REMOVE_VENDOR = "remove_vendor";

// todo actions
public static final String REMOVE_TODO = "removeTodo";

// user actions
public static final String USER_PREFIX = "user";
public static final String USER_SEARCH = USER_PREFIX + "search";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Copyright Siemens AG, 2013-2015. Part of the SW360 Portal Project.
*
* SPDX-License-Identifier: EPL-1.0
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.sw360.portal.portlets.admin;

import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import org.eclipse.sw360.datahandler.permissions.PermissionUtils;
import org.eclipse.sw360.datahandler.thrift.RequestStatus;
import org.eclipse.sw360.datahandler.thrift.licenses.LicenseService;
import org.eclipse.sw360.datahandler.thrift.licenses.Todo;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.users.UserGroup;
import org.eclipse.sw360.portal.common.UsedAsLiferayAction;
import org.eclipse.sw360.portal.portlets.Sw360Portlet;
import org.eclipse.sw360.portal.portlets.components.ComponentPortletUtils;
import org.eclipse.sw360.portal.users.UserCacheHolder;

import javax.portlet.*;
import java.io.IOException;
import java.util.Collections;
import java.util.List;

import static org.eclipse.sw360.portal.common.PortalConstants.*;

/**
* Todo portlet implementation
*
* @author [email protected]
*/
public class TodoPortlet extends Sw360Portlet {

private static final Logger log = Logger.getLogger(TodoPortlet.class);


//! Serve resource and helpers
@Override
public void serveResource(ResourceRequest request, ResourceResponse response) {

final String id = request.getParameter("id");
final User user = UserCacheHolder.getUserFromRequest(request);

LicenseService.Iface licenseClient = thriftClients.makeLicenseClient();


try {
RequestStatus status = licenseClient.deleteTodo(id, user);
renderRequestStatus(request,response, status);
} catch (TException e) {
log.error("Error deleting todo", e);
renderRequestStatus(request,response, RequestStatus.FAILURE);
}
}


//! VIEW and helpers
@Override
public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException {


String pageName = request.getParameter(PAGENAME);
if (PAGENAME_ADD.equals(pageName)) {
include("/html/admin/todos/add.jsp", request, response);
} else {
prepareStandardView(request);
super.doView(request, response);
}
}

private void prepareStandardView(RenderRequest request) {
List<Todo> todoList;
try {
final User user = UserCacheHolder.getUserFromRequest(request);
LicenseService.Iface licenseClient = thriftClients.makeLicenseClient();

todoList = licenseClient.getTodos();

} catch (TException e) {
log.error("Could not get Todos from backend ", e);
todoList = Collections.emptyList();
}

request.setAttribute(TODO_LIST, todoList);
}

@UsedAsLiferayAction
public void addTodo(ActionRequest request, ActionResponse response) {

final Todo todo = new Todo();
ComponentPortletUtils.updateTodoFromRequest(request, todo);

try {
LicenseService.Iface licenseClient = thriftClients.makeLicenseClient();
final User user = UserCacheHolder.getUserFromRequest(request);

licenseClient.addTodo(todo, user);
} catch (TException e) {
log.error("Error adding todo", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.eclipse.sw360.datahandler.common.SW360Utils;
import org.eclipse.sw360.datahandler.thrift.*;
import org.eclipse.sw360.datahandler.thrift.components.*;
import org.eclipse.sw360.datahandler.thrift.licenses.Todo;
import org.eclipse.sw360.datahandler.thrift.users.RequestedAction;
import org.eclipse.sw360.datahandler.thrift.users.User;
import org.eclipse.sw360.datahandler.thrift.vendors.Vendor;
Expand Down Expand Up @@ -148,6 +149,12 @@ public static void updateVendorFromRequest(PortletRequest request, Vendor vendor
setFieldValue(request, vendor, Vendor._Fields.URL);
}

public static void updateTodoFromRequest(PortletRequest request, Todo todo) {
setFieldValue(request, todo, Todo._Fields.TITLE);
setFieldValue(request, todo, Todo._Fields.TEXT);
setFieldValue(request, todo, Todo._Fields.VALID_FOR_PROJECT);
}

private static void updateLinkedReleaseFromRequest(PortletRequest request, Map<String, ReleaseRelationship> linkedReleases) {
linkedReleases.clear();
String[] ids = request.getParameterValues(Release._Fields.RELEASE_ID_TO_RELATIONSHIP.toString() + ReleaseLink._Fields.ID.toString());
Expand Down Expand Up @@ -186,6 +193,10 @@ private static void setFieldValue(PortletRequest request, Vendor vendor, Vendor.
PortletUtils.setFieldValue(request, vendor, field, Vendor.metaDataMap.get(field), "");
}

private static void setFieldValue(PortletRequest request, Todo todo, Todo._Fields field) {
PortletUtils.setFieldValue(request, todo, field, Todo.metaDataMap.get(field), "");
}

public static RequestStatus deleteRelease(PortletRequest request, Logger log) {
String releaseId = request.getParameter(PortalConstants.RELEASE_ID);
if (releaseId != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private static boolean isFieldRelevant(Todo._Fields field) {
case REVISION:
case TYPE:
case OBLIGATION_DATABASE_IDS:
case TODO_ID:
case TITLE:
case DEVELOPMENT_STRING:
case DISTRIBUTION_STRING:
case WHITELIST:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<portlet id="licenses"/>
<portlet id="components"/>
<portlet id="vendors"/>
<portlet id="todos"/>
<portlet id="projects"/>
<portlet id="search"/>
<portlet id="users"/>
Expand Down
11 changes: 11 additions & 0 deletions frontend/sw360-portlet/src/main/webapp/WEB-INF/liferay-portlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@
<header-portlet-javascript>/js/main.js</header-portlet-javascript>
</portlet>

<portlet>
<portlet-name>todos</portlet-name>
<icon>/icon.png</icon>
<instanceable>false</instanceable>
<private-request-attributes>false</private-request-attributes>
<header-portlet-css>/css/main.css</header-portlet-css>
<header-portlet-css>/css/print.css</header-portlet-css>
<header-portlet-css>/css/tooltips.css</header-portlet-css>
<header-portlet-javascript>/js/main.js</header-portlet-javascript>
</portlet>

<portlet>
<portlet-name>projects</portlet-name>
<icon>/icon.png</icon>
Expand Down
25 changes: 25 additions & 0 deletions frontend/sw360-portlet/src/main/webapp/WEB-INF/portlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,31 @@
</security-role-ref>
</portlet>

<portlet>
<portlet-name>todos</portlet-name>
<display-name>TODOs</display-name>
<portlet-class>
org.eclipse.sw360.portal.portlets.admin.TodoPortlet
</portlet-class>
<init-param>
<name>view-template</name>
<value>/html/admin/todos/view.jsp</value>
</init-param>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>TODOs</title>
<short-title>TODOs</short-title>
<keywords/>
</portlet-info>
<security-role-ref>
<role-name>administrator</role-name>
</security-role-ref>
</portlet>

<portlet>
<portlet-name>signup</portlet-name>
<display-name>Sign-Up</display-name>
Expand Down
Loading

0 comments on commit c4452fc

Please sign in to comment.