Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
changes on deletion policy
Browse files Browse the repository at this point in the history
* a component can only be deleted if it contains no releases
* Frontend checks whether releases are present and disables delete function
* backend checks again
  • Loading branch information
heydenreich committed Sep 12, 2016
1 parent db3180e commit 5e1dafb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ public RequestStatus deleteComponent(String id, User user) throws SW360Exception
assertNotNull(component);

final Set<String> releaseIds = component.getReleaseIds();
if (releaseIds!=null && releaseIds.size()>0) return RequestStatus.IN_USE;
if (checkIfInUse(releaseIds)) return RequestStatus.IN_USE;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
~ which accompanies this distribution, and is available at
~ http://www.eclipse.org/legal/epl-v10.html
--%>

<%@include file="/html/init.jsp" %>
<%@ taglib prefix="sw360" uri="/WEB-INF/customTags.tld" %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,11 @@
<core_rt:if test="${not componentDivAddMode}">
<input type="button" class="addButton" onclick="deleteConfirmed('' +
'Do you really want to delete the component <b><sw360:out value="${component.name}"/></b> ?' +
'<core_rt:if test="${not empty component.attachments or not empty component.releases}" ><br/><br/>The component <b><sw360:out value="${component.name}"/></b> contains<br/><ul></core_rt:if>' +
'<core_rt:if test="${not empty component.releases}" ><li><sw360:out value="${component.releasesSize}"/> linked releases</li></core_rt:if>' +
'<core_rt:if test="${not empty component.attachments}" ><li><sw360:out value="${component.attachmentsSize}"/> attachments</li></core_rt:if>' +
'<core_rt:if test="${not empty component.attachments or not empty component.releases}" ></ul></core_rt:if>', deleteComponent)"
'<core_rt:if test="${not empty component.attachments}" ><br/><br/>The component <b><sw360:out value="${component.name}"/></b>contains<br/><ul><li><sw360:out value="${component.attachmentsSize}"/> attachments</li></ul></core_rt:if>'
, deleteComponent)"
value="Delete <sw360:out value="${component.name}"/> "
<core_rt:if test="${usingComponents.size()>0 or usingProjects.size()>0}"> disabled="disabled" title="Deletion is disabled as the component is used." </core_rt:if>
<core_rt:if test="${component.releasesSize>0}"> disabled="disabled" title="Deletion is disabled as the component contains releases." </core_rt:if>
>
</core_rt:if>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
});
</core_rt:forEach>

oTable = $('#releasesTable').dataTable({
oTable = $('#releasesTable').DataTable({
"sPaginationType": "full_numbers",
"aaData": result,
"aoColumns": [
Expand All @@ -70,7 +70,7 @@
{"sTitle": "Clearing state"},
{"sTitle": "Clearing report"},
{"sTitle": "Mainline state"},
{"sTitle": "Action"}
{"sTitle": "Actions"}
]
});

Expand All @@ -79,7 +79,7 @@

}

//This can not be document ready function as liferay definitions need to be loaded first
<%--This can not be document ready function as liferay definitions need to be loaded first--%>
$(window).load(function () {
createClearingTable();
});
Expand All @@ -95,14 +95,14 @@
<portlet:namespace/>releaseId: id
},
success: function (data) {
if (data.result == 'SUCCESS')
if (data.result == 'SUCCESS') {
oTable.row('#' + id).remove().draw();
}
else if (data.result == 'SENT_TO_MODERATOR') {
$.alert("You may not delete the release, but a request was sent to a moderator!");
} else if (data.result == 'IN_USE') {
$.alert("The release is used by another component (release) or project");
}
else {
$.alert("I could not delete the release, since it is used by another component (release) or project");
} else {
$.alert("I could not delete the release!");
}
},
Expand Down
25 changes: 14 additions & 11 deletions frontend/sw360-portlet/src/main/webapp/html/components/view.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@
$('#componentsTable_last').hide();
}
function deleteComponent(id, name, linkedReleasesSize, attachmentsSize) {
function deleteComponent(id, name, numberOfReleases, attachmentsSize) {
function deleteComponentInternal() {
jQuery.ajax({
type: 'POST',
Expand All @@ -287,15 +286,18 @@
data: {
<portlet:namespace/>componentid: id
},
success: function (data) {
if (data.result == 'SUCCESS') {
oTable.row('#' + id).remove().draw();
}
else if (data.result == 'SENT_TO_MODERATOR') {
$.alert("You may not delete the component, but a request was sent to a moderator!");
}
else {
$.alert("I could not delete the component!");
else if (data.result == 'IN_USE') {
$.alert("I could not delete the component, since it is in use.");
} else {
$.alert("I could not delete the component.");
}
},
error: function () {
Expand All @@ -304,14 +306,15 @@
});
}
var confirmMessage = "Do you really want to delete the component " + name + " ?";
confirmMessage += (attachmentsSize > 0 || linkedReleasesSize > 0) ? "<br/><br/>The component " + name + " contains<br/><ul>" : "";
confirmMessage += (linkedReleasesSize > 0) ? "<li>" + linkedReleasesSize + " linked releases</li>" : "";
confirmMessage += (attachmentsSize > 0) ? "<li>" + attachmentsSize + " attachments</li>" : "";
confirmMessage += (attachmentsSize > 0 || linkedReleasesSize > 0) ? "</ul>" : "";
deleteConfirmed(confirmMessage, deleteComponentInternal);
if (numberOfReleases > 0) {
$.alert("The component cannot be deleted, since it contains releases. Please delete the releases first.");
} else {
var confirmMessage = "Do you really want to delete the component " + name + " ?";
confirmMessage += (attachmentsSize > 0) ? "<br/><br/>The component " + name + " contains<br/><ul><li>" + attachmentsSize + " attachments</li></ul>" : "";
deleteConfirmed(confirmMessage, deleteComponentInternal);
}
}
</script>

<link rel="stylesheet" href="<%=request.getContextPath()%>/css/sw360.css">
Expand Down
9 changes: 4 additions & 5 deletions frontend/sw360-portlet/src/main/webapp/html/projects/view.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,12 @@
$('#exportbutton').click(exportExcel);
$('.filterInput').on('input', function() {
$('#exportExcelButton').prop('disabled', true);
//when filters are actually applied, page is refreshed and exportExcelButton enabled automatically
<%--when filters are actually applied, page is refreshed and exportExcelButton enabled automatically--%>
});
});
function useSearch(buttonId) {
//we only want to search names starting with the value in the search box
<%-- we only want to search names starting with the value in the search box--%>
var val = $.fn.dataTable.util.escapeRegex($('#' + buttonId).val());
oTable.columns(0).search('^' + val, true).draw();
}
Expand Down Expand Up @@ -337,7 +337,7 @@
fillClearingFormAndOpenDialog(projectId);
}
function deleteProject(projectId, name) {
function deleteProject(projectId, name, linkedProjectsSize, linkedReleasesSize, attachmentsSize) {
function deleteProjectInternal() {
jQuery.ajax({
Expand All @@ -354,7 +354,7 @@
else if (data.result == 'SENT_TO_MODERATOR') {
$.alert("You may not delete the project, but a request was sent to a moderator!");
} else if (data.result == 'IN_USE') {
$.alert("The project is used by another project!");
$.alert("The project cannot be deleted, since it is used by another project!");
}
else {
$.alert("I could not delete the project!");
Expand All @@ -366,7 +366,6 @@
});
}
}
var confirmMessage = "Do you really want to delete the project " + name + " ?";
confirmMessage += (linkedProjectsSize > 0 || linkedReleasesSize > 0 || attachmentsSize > 0) ? "<br/><br/>The project " + name + " contains<br/><ul>" : "";
Expand Down

0 comments on commit 5e1dafb

Please sign in to comment.