Skip to content

Commit

Permalink
Merge pull request #542 from bact/add-compliance-ui
Browse files Browse the repository at this point in the history
Add ntia-conformance-checker compliance selector to UI
  • Loading branch information
goneall authored Dec 27, 2024
2 parents 253f512 + 60ca978 commit bf7998a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 38 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ gunicorn==22.0.0
selenium==3.14.1
django-oauth-toolkit==1.5.0
django-rest-framework-social-oauth2==1.1.0
spdx-tools==0.8.2
ntia-conformance-checker==1.1.0
spdx-tools==0.8.3
ntia-conformance-checker==3.0.2
-e git+https://github.com/spdx/[email protected]#egg=spdx-license-matcher
18 changes: 9 additions & 9 deletions src/app/core.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"""This file contains the core logic used in the SPDX Online Tools' APP and API"""

import json

from django.http.response import JsonResponse
import jpype
import os
import sys
Expand All @@ -11,7 +8,7 @@
from django.core.files.storage import FileSystemStorage
from django.conf import settings

from json import dumps, loads
from json import dumps
from time import time
from traceback import format_exc
from urllib.parse import urljoin
Expand Down Expand Up @@ -56,7 +53,7 @@ def license_compare_helper(request):
erroroccurred = False
warningoccurred = False
if (len(request.FILES.getlist("files")) < 2):
context_dict["error"] = "Please select atleast 2 files"
context_dict["error"] = "Please select at least 2 files"
result['status'] = 404
result['context'] = context_dict
return result
Expand Down Expand Up @@ -178,23 +175,23 @@ def license_compare_helper(request):
""" If no files uploaded"""
if (request.is_ajax()):
filelist.append("Files not selected.")
errorlist.append("Please select atleast 2 files.")
errorlist.append("Please select at least 2 files.")
ajaxdict["files"] = filelist
ajaxdict["type"] = "error"
ajaxdict["errors"] = errorlist
response = dumps(ajaxdict)
result['status'] = 404
result['response'] = response
return result
context_dict["error"] = "Select atleast two files"
context_dict["error"] = "Select at least two files"
context_dict["type"] = "error"
result['status'] = 404
result['context'] = context_dict
return result

def ntia_check_helper(request):
"""
A helper function to check the ntia elements in a given file in various formats.
A helper function to check the NTIA elements in a given file in various formats.
"""
ajaxdict = dict()
context_dict = {}
Expand All @@ -209,8 +206,11 @@ def ntia_check_helper(request):
)
filename = fs.save(utils.removeSpecialCharacters(myfile.name), myfile)
uploaded_file_url = fs.url(filename).replace("%20", " ")
""" Call the python SBOM Checker """
""" Get other request parameters """
# compliance = request.POST.get("compliance", "ntia") # Default: "ntia"
""" Call the Python SBOM Checker """
schecker = SbomChecker(str(settings.APP_DIR + uploaded_file_url))
# schecker = SbomChecker(str(settings.APP_DIR + uploaded_file_url), compliance=compliance) # Post-3.0.2
oldStdout = sys.stdout
tempstdout = StringIO()
sys.stdout = tempstdout
Expand Down
56 changes: 29 additions & 27 deletions src/app/templates/app/ntia_conformance_checker.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,46 @@
{% block body1 %}
<div id="messages" class="messages">
</div>
<p class ="lead"> {{ error }}</p>
<p class ="lead">{{ error }}</p>
<div class="panel panel-default">
<div class="panel-heading"> <p class="lead">Tag-Value, RDF, JSON, Spreadsheet, XML SPDX Document</p> </div>
<div class="panel-body">
<form id="checkform" enctype="multipart/form-data" class="form-horizontal" method="post">
{% csrf_token %}
<div class = "form-group">
&nbsp; File Type &nbsp;
<select name="format" id="format">
<option value="0" data-value="0" selected="">-</option>
<option value="XLSX">XLSX Spreadsheet</option>
<option value="XLS">XLS Spreadsheet</option>
<option value="RDFXML">RDF/XML</option>
<option value="TAG">Tag/Value</option>
<option value="JSON">JSON</option>
<option value="YAML">YAML</option>
<option value="XML">XML</option>
</select>
</div>
<div id="drop-area" class="container">
<h4>Upload file using the button or by dragging and dropping onto the dashed region </h4>
<input type="file" id="file" onchange="handleFiles(this.files)">
<label class="button" for="file">Select file</label>
<p class="file-name">No file selected</p>
</div>
</form>
<form id="checkform" enctype="multipart/form-data" class="form-horizontal" method="post">
{% csrf_token %}
<div class = "form-group">
&nbsp; File Type &nbsp;
<select name="format" id="format">
<option value="0" data-value="0" selected="">-</option>
<option value="RDFXML">RDF/XML</option>
<option value="TAG">Tag/Value</option>
<option value="JSON">JSON</option>
<option value="XML">XML</option>
</select>
</div>
<div class = "form-group">
&nbsp; Compliance &nbsp;
<select name="compliance" id="compliance">
<option value="ntia" selected="">NTIA Minimum Elements</option>
</select>
</div>
<div id="drop-area" class="container">
<h4>Upload file using the button or by dragging and dropping onto the dashed region </h4>
<input type="file" id="file" onchange="handleFiles(this.files)">
<label class="button" for="file">Select file</label>
<p class="file-name">No file selected</p>
</div>
</form>
<hr>
<button id="checkbutton" name="checkbutton" class="btn btn-md btn-info" type="submit" disabled="true">Check NTIA's Required Elements</button>
<button id="checkbutton" name="checkbutton" class="btn btn-md btn-info" type="submit" disabled="true">Check Required Elements</button>
{% include "app/modal.html" %}

</div>

{% endblock %}

{% block script_block %}

<script type="text/javascript">
/* Javascript to handel drag and drop */
/* JavaScript to handle drag and drop */
let dropArea = document.getElementById('drop-area');
var selected_file = "";
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
Expand Down Expand Up @@ -85,7 +87,7 @@ <h4>Upload file using the button or by dragging and dropping onto the dashed reg
([...files]).forEach(checkFile)
}

function checkFile(file){
function checkFile(file) {
if(file){
$(".file-name").html("<b>Selected File: </b>"+file.name);
$("#checkbutton").prop('disabled', false);
Expand Down

0 comments on commit bf7998a

Please sign in to comment.