Skip to content

Commit

Permalink
TODOs Management
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.

Signed-off-by: Nikolas Sepos <[email protected]>
  • Loading branch information
Nikolas Sepos committed Apr 25, 2019
1 parent 4414cfd commit 1676398
Show file tree
Hide file tree
Showing 19 changed files with 461 additions and 31 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 @@ -895,4 +895,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 @@ -58,6 +58,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 @@ -125,6 +126,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 ADDED_ATTACHMENTS = "added_attachments";
Expand Down Expand Up @@ -333,6 +338,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
103 changes: 103 additions & 0 deletions frontend/sw360-portlet/src/main/webapp/html/admin/todos/add.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<%--
~ Copyright Siemens AG, 2013-2017. 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
--%>
<%@ page import="org.eclipse.sw360.portal.common.PortalConstants" %>
<%@include file="/html/init.jsp"%>
<%-- the following is needed by liferay to display error messages--%>
<%@include file="/html/utils/includes/errorKeyToMessage.jspf"%>
<portlet:defineObjects />
<liferay-theme:defineObjects />

<%@ page import="javax.portlet.PortletRequest" %>
<%@ page import="com.liferay.portlet.PortletURLFactoryUtil" %>
<%@ page import="org.eclipse.sw360.datahandler.thrift.licenses.Todo" %>


<jsp:useBean id="todo" class="org.eclipse.sw360.datahandler.thrift.licenses.Todo" scope="request" />



<portlet:actionURL var="addURL" name="addTodo">
</portlet:actionURL>


<link rel="stylesheet" href="<%=request.getContextPath()%>/css/sw360.css">
<link rel="stylesheet" href="<%=request.getContextPath()%>/webjars/jquery-ui/themes/base/jquery-ui.min.css">
<link rel="stylesheet" href="<%=request.getContextPath()%>/webjars/jquery-confirm2/dist/jquery-confirm.min.css">
<script src="<%=request.getContextPath()%>/webjars/jquery/dist/jquery.min.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/webjars/jquery-validation/dist/jquery.validate.min.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/webjars/jquery-validation/dist/additional-methods.min.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/webjars/jquery-confirm2/dist/jquery-confirm.min.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/webjars/jquery-ui/jquery-ui.min.js"></script>


<div id="where" class="content1">
<p class="pageHeader"><span class="pageHeaderBigSpan"></span>
</p>
</div>

<div id="editField" class="content2">

<form id="todoAddForm" name="todoAddForm" action="<%=addURL%>" method="post" >
<table class="table info_table" id="todoAddTable">
<col width="30%">
<col width="60%">
<col width="10%">
<thead>
<tr>
<th colspan="3" class="headlabel">Add TODO</th>
</tr>
</thead>
<tbody>
<tr>
<td width="30%">
<label class="textlabel stackedLabel mandatory" for="todoTitle">Title</label>
<input id="todoTitle" type="text" required class="toplabelledInput" placeholder="Enter TODO Title" name="<portlet:namespace/><%=Todo._Fields.TITLE%>"/>
</td>

<td width="50%">
<label class="textlabel stackedLabel mandatory" for="todoText">Text</label>
<textarea name="<portlet:namespace/><%=Todo._Fields.TEXT%>" id="todoText" cols="50"rows="10" required class="toplabelledInput"></textarea>
</td>

<td width="10%">
<label class="textlabel stackedLabel mandatory" for="todoValidForProject">Valid For Projects</label>
<input id="todoValidForProject" type="checkbox" class="toplabelledInput" name="<portlet:namespace/><%=Todo._Fields.VALID_FOR_PROJECT%>"/>
</td>
</tr>

</tbody>
</table>
<input type="submit" value="Add Todo" class="addButton">
<input type="button" value="Cancel" onclick="cancel()" class="cancelButton">
</form>


</div>

<script>
function cancel() {
var baseUrl = '<%= PortletURLFactoryUtil.create(request, portletDisplay.getId(), themeDisplay.getPlid(), PortletRequest.RENDER_PHASE) %>';
var portletURL = Liferay.PortletURL.createURL( baseUrl )
.setParameter('<%=PortalConstants.PAGENAME%>','<%=PortalConstants.PAGENAME_VIEW%>')
window.location = portletURL.toString();
}
var contextpath;
$( document ).ready(function() {
contextpath = '<%=request.getContextPath()%>';
$('#todoAddForm').validate({
ignore: [],
invalidHandler: invalidHandlerShowErrorTab
});
});
</script>
Loading

0 comments on commit 1676398

Please sign in to comment.