diff --git a/src/app/templates/app/submit_new_license.html b/src/app/templates/app/submit_new_license.html
index 24d07e50..b134f669 100644
--- a/src/app/templates/app/submit_new_license.html
+++ b/src/app/templates/app/submit_new_license.html
@@ -459,11 +459,23 @@
}
}
else{
- var warningMessage = "Please note that there was a problem opening the issue for the SPDX legal team. Please email spdx-legal@lists.spdx.org with SPDX ID for the license you are submitting";
- $("#messages").html('
× Warning! '+ warningMessage +'
');
- setTimeout(function() {
- $("#messages").html("");
- }, 7000);
+ var errorMessage = 'Error occured while submitting the license. Please contact spdx-legal@lists.spdx.org with SPDX ID for submitting the license. Would you like to submit this problem to github so that the developers can look at it?';
+ $("#modal-header").removeClass("yellow-modal green-modal");
+ $("#modal-header").addClass("red-modal");
+ $(".modal-footer").html(` Yes No `);
+ $("#modal-body").html(errorMessage);
+ $("#myModal").modal({
+ backdrop: 'static',
+ keyboard: true,
+ show: true
+ });
+ $(document).on('click','button#submiterrorissue', function(event){
+ $("#myModal").modal("hide");
+ makeIssue(data);
+ });
+ $(document).on('click','button#no', function(event){
+ $("#myModal").modal("hide");
+ });
}
$("#fullname").val("");
$("#shortIdentifier").val("");
@@ -549,7 +561,7 @@
success: function (data) {
var githubCode = data.statusCode;
if(githubCode == '201'){
- var successMessage = 'The issue "' + msg + '" has been successfully submitted.';
+ var successMessage = 'The issue has been successfully submitted.';
$("#messages").html('× Success! '+ successMessage +'
');
setTimeout(function() {
$("#messages").html("");
diff --git a/src/app/utils.py b/src/app/utils.py
index 9c686bc4..f24e2023 100644
--- a/src/app/utils.py
+++ b/src/app/utils.py
@@ -12,23 +12,31 @@
# limitations under the License.
import base64
+import datetime
import json
import logging
import re
import socket
+import os
import xml.etree.cElementTree as ET
+from django.template import context
import redis
import requests
from django.conf import settings
+from django.http import HttpResponse,JsonResponse
+from django.urls import reverse
from spdx_license_matcher.build_licenses import build_spdx_licenses
from spdx_license_matcher.computation import (checkTextStandardLicense,
get_close_matches,
getListedLicense)
from spdx_license_matcher.difference import get_similarity_percent
from spdx_license_matcher.utils import get_spdx_license_text
+from social_django.models import UserSocialAuth
+
from app.models import User, UserID, LicenseRequest, LicenseNamespace
+from app.generateXml import generateLicenseXml
from src.secret import getRedisHost
@@ -354,6 +362,26 @@ def createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseCommen
return r.status_code
+def createErrorIssue(occured_at, made_by, error_message, licenseID, licenseName, license_text, token):
+ """ View for creating an GitHub issue
+ with the complete Error Report to the
+ SPDX Online tools repository.
+ """
+
+ body = """
+ **1.** Occured At: {0}
+ **2.** Made By: {1}
+ **3.** Error Message: {2}
+ **4.** License Text: {3}
+ """.format(occured_at, made_by, error_message, license_text)
+ title = "Error Report - {0}/{1}".format(licenseID, licenseName)
+ payload = {'title' : title, 'body': body}
+ headers = {'Authorization': 'token ' + token}
+ url = "{0}/issues".format(settings.ERROR_ISSUE_REPO_URL)
+ r = requests.post(url, data=json.dumps(payload), headers=headers)
+ return r.status_code
+
+
def postToGithub(message, encodedContent, filename):
""" Function to create a new file on with encodedContent
"""
@@ -575,3 +603,59 @@ def formatToContentType(to_format):
return "application/xml"
else :
return ".invalid"
+
+
+def handle_issue_request(request):
+ """Handles the issue create request view"""
+ ajaxdict = {}
+
+ if request.user.is_authenticated:
+ user = request.user
+ try:
+ github_login = user.social_auth.get(provider='github')
+ token = github_login.extra_data["access_token"]
+ licenseText = request.POST['inputLicenseText']
+ licenseName = request.POST['licenseName']
+ licenseIdentifier = request.POST['licenseIdentifier']
+ data = {}
+
+ if request.POST.get('error',None):
+ occured_at = datetime.datetime.now(datetime.timezone.utc).strftime("%Y%m%d")
+ made_by = github_login.extra_data['login']
+ error_message = request.POST['error']
+ statusCode = createErrorIssue(occured_at, made_by, error_message, licenseIdentifier, licenseName, licenseText, token)
+ else:
+ licenseAuthorName = request.POST['licenseAuthorName']
+ licenseOsi = request.POST['licenseOsi']
+ licenseSourceUrls = request.POST.getlist('licenseSourceUrls')
+ licenseExamples = request.POST.getlist('exampleUrl')
+ licenseHeader = request.POST['licenseHeader']
+ licenseComments = request.POST['comments']
+ userEmail = request.POST['userEmail']
+ licenseNotes = request.POST['licenseNotes']
+ listVersionAdded = request.POST['listVersionAdded']
+ matchId = request.POST['matchIds']
+ diffUrl = request.POST['diffUrl']
+ msg = request.POST.get('msg', None)
+ urlType = NORMAL
+ xml = generateLicenseXml(licenseOsi, licenseIdentifier, licenseName,
+ listVersionAdded, licenseSourceUrls, licenseHeader, licenseNotes, licenseText)
+ now = datetime.datetime.now()
+ licenseRequest = LicenseRequest(licenseAuthorName=licenseAuthorName, fullname=licenseName, shortIdentifier=licenseIdentifier,
+ submissionDatetime=now, userEmail=userEmail, notes=licenseNotes, xml=xml)
+ licenseRequest.save()
+ licenseRequestId = licenseRequest.id
+ serverUrl = request.build_absolute_uri('/')
+ licenseRequestUrl = os.path.join(serverUrl, reverse('license-requests')[1:], str(licenseRequestId))
+ statusCode = createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType, matchId, diffUrl, msg)
+ data['statusCode'] = str(statusCode)
+ return JsonResponse(data)
+
+ except UserSocialAuth.DoesNotExist:
+ """ User not authenticated with GitHub """
+ if (request.is_ajax()):
+ ajaxdict["type"] = "auth_error"
+ ajaxdict["data"] = "Please login using GitHub to use this feature."
+ response = json.dumps(ajaxdict)
+ return HttpResponse(response,status=401)
+ return HttpResponse("Please login using GitHub to use this feature.",status=401)
diff --git a/src/app/views.py b/src/app/views.py
index eba4b4b5..17c12630 100644
--- a/src/app/views.py
+++ b/src/app/views.py
@@ -191,10 +191,9 @@ def submitNewLicense(request):
""" Other errors raised """
logger.error(str(format_exc()))
if (request.is_ajax()):
- ajaxdict["type"] = "error"
- ajaxdict["data"] = "Unexpected error, please email the SPDX technical workgroup that the following error has occurred: " + format_exc()
- response = dumps(ajaxdict)
- return HttpResponse(response,status=500)
+ ajaxdict['error'] = str(format_exc())
+ ajaxdict['inputlicensetext'] = request.POST['text']
+ return JsonResponse(ajaxdict)
return HttpResponse("Unexpected error, please email the SPDX technical workgroup that the following error has occurred: " + format_exc(), status=500)
else:
email=""
@@ -1093,55 +1092,13 @@ def issue(request):
""" View that handles create issue request """
if request.user.is_authenticated:
if request.method=="POST":
- context_dict = {}
- ajaxdict = {}
try:
- if request.user.is_authenticated:
- user = request.user
- try:
- github_login = user.social_auth.get(provider='github')
- token = github_login.extra_data["access_token"]
- licenseAuthorName = request.POST['licenseAuthorName']
- licenseName = request.POST['licenseName']
- licenseIdentifier = request.POST['licenseIdentifier']
- licenseOsi = request.POST['licenseOsi']
- licenseSourceUrls = request.POST.getlist('licenseSourceUrls')
- licenseExamples = request.POST.getlist('exampleUrl')
- licenseHeader = request.POST['licenseHeader']
- licenseComments = request.POST['comments']
- licenseText = request.POST['inputLicenseText']
- userEmail = request.POST['userEmail']
- licenseNotes = request.POST['licenseNotes']
- listVersionAdded = request.POST['listVersionAdded']
- matchId = request.POST['matchIds']
- diffUrl = request.POST['diffUrl']
- msg = request.POST.get('msg', None)
- urlType = utils.NORMAL
- data = {}
- xml = generateLicenseXml(licenseOsi, licenseIdentifier, licenseName,
- listVersionAdded, licenseSourceUrls, licenseHeader, licenseNotes, licenseText)
- now = datetime.datetime.now()
- licenseRequest = LicenseRequest(licenseAuthorName=licenseAuthorName, fullname=licenseName, shortIdentifier=licenseIdentifier,
- submissionDatetime=now, userEmail=userEmail, notes=licenseNotes, xml=xml)
- licenseRequest.save()
- licenseRequestId = licenseRequest.id
- serverUrl = request.build_absolute_uri('/')
- licenseRequestUrl = os.path.join(serverUrl, reverse('license-requests')[1:], str(licenseRequestId))
- statusCode = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType, matchId, diffUrl, msg)
- data['statusCode'] = str(statusCode)
- return JsonResponse(data)
- except UserSocialAuth.DoesNotExist:
- """ User not authenticated with GitHub """
- if (request.is_ajax()):
- ajaxdict["type"] = "auth_error"
- ajaxdict["data"] = "Please login using GitHub to use this feature."
- response = dumps(ajaxdict)
- return HttpResponse(response,status=401)
- return HttpResponse("Please login using GitHub to use this feature.",status=401)
+ utils.handle_issue_request(request)
except:
""" Other errors raised """
logger.error(str(format_exc()))
if (request.is_ajax()):
+ ajaxdict = {}
ajaxdict["type"] = "error"
ajaxdict["data"] = "Unexpected error, please email the SPDX technical workgroup that the following error has occurred: " + format_exc()
response = dumps(ajaxdict)
diff --git a/src/src/settings.py b/src/src/settings.py
index f598ab57..8161eff9 100644
--- a/src/src/settings.py
+++ b/src/src/settings.py
@@ -33,6 +33,9 @@
NAMESPACE_PROD_REPO_URL = 'https://api.github.com/repos/spdx/{0}'.format(NAMESPACE_REPO_NAME)
NAMESPACE_REPO_URL = NAMESPACE_DEV_REPO_URL
+ERROR_ISSUE_REPO_NAME = "spdx-online-tools"
+ERROR_ISSUE_REPO_URL = 'https://api.github.com/repos/spdx/{0}'.format(ERROR_ISSUE_REPO_NAME)
+
# Settings for license request diff image repo
DIFF_REPO_WITH_OWNER = getDiffRepoWithOwner()
DIFF_REPO_GIT_TOKEN = getDiffRepoGitToken()