From 5caa67c398f153965a38d6c185dba4df6ca348bd Mon Sep 17 00:00:00 2001 From: BanulaMahen Date: Thu, 30 Mar 2023 01:24:33 +0530 Subject: [PATCH 1/6] Fixing the issue #453 --- src/app/migrations/0002_auto_20230330_0034.py | 23 +++++++++++++++++++ src/app/models.py | 1 + .../templates/app/license_information.html | 10 +++++++- src/app/utils.py | 2 +- src/app/views.py | 7 ++++-- 5 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 src/app/migrations/0002_auto_20230330_0034.py diff --git a/src/app/migrations/0002_auto_20230330_0034.py b/src/app/migrations/0002_auto_20230330_0034.py new file mode 100644 index 00000000..fcbeeb87 --- /dev/null +++ b/src/app/migrations/0002_auto_20230330_0034.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.18 on 2023-03-29 19:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='licensenamespace', + name='issueId', + field=models.TextField(default=''), + ), + migrations.AddField( + model_name='licenserequest', + name='issueId', + field=models.TextField(default=''), + ), + ] diff --git a/src/app/models.py b/src/app/models.py index 31decf1f..f555ec5d 100644 --- a/src/app/models.py +++ b/src/app/models.py @@ -36,6 +36,7 @@ class License(models.Model): notes = models.CharField(max_length=255, default="") xml = models.TextField() archive = models.BooleanField(default=False) + issueId = models.TextField(default='') class Meta: abstract = True diff --git a/src/app/templates/app/license_information.html b/src/app/templates/app/license_information.html index e40c7648..28c2dd7f 100644 --- a/src/app/templates/app/license_information.html +++ b/src/app/templates/app/license_information.html @@ -8,7 +8,8 @@

{{ error }}

{% if licenseInformation %} -

{{licenseInformation.fullname}} +

+

{{licenseInformation.fullname}} {% if licenseInformation.archive %} Archived {% endif %} @@ -51,6 +52,13 @@

Text

{{licenseInformation.text|safe}}

+ +

Submission Date

{{licenseInformation.submissionDatetime}}

diff --git a/src/app/utils.py b/src/app/utils.py index 93d14b56..45c9ce98 100644 --- a/src/app/utils.py +++ b/src/app/utils.py @@ -352,7 +352,7 @@ def createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseCommen headers = {'Authorization': 'token ' + token} url = "{0}/issues".format(TYPE_TO_URL_LICENSE[urlType]) r = requests.post(url, data=json.dumps(payload), headers=headers) - return r.status_code + return r.status_code, r.json()["number"] def postToGithub(message, encodedContent, filename): diff --git a/src/app/views.py b/src/app/views.py index 61bf6112..43891955 100644 --- a/src/app/views.py +++ b/src/app/views.py @@ -162,8 +162,9 @@ def submitNewLicense(request): licenseId = licenseRequest.id serverUrl = request.build_absolute_uri('/') licenseRequestUrl = os.path.join(serverUrl, reverse('license-requests')[1:], str(licenseId)) - statusCode = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType) - + statusCode, issueId = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType) + licenseRequest.issueId = issueId + licenseRequest.save() # If the license text matches with either rejected or yet not approved license then return 409 Conflict else: statusCode = 409 @@ -346,6 +347,7 @@ def licenseInformation(request, licenseId): licenseInformation['licenseAuthorName'] = licenseRequest.licenseAuthorName licenseInformation['archive'] = licenseRequest.archive + licenseInformation['issueId'] = licenseRequest.issueId xmlString = licenseRequest.xml data = utils.parseXmlString(xmlString) licenseInformation['osiApproved'] = data['osiApproved'] @@ -1002,6 +1004,7 @@ def licenseRequests(request, license_id=None): """ View for license requests which are not archived returns license_requests.html template """ + print(license_id) context_dict = {} if request.user.is_authenticated: user = request.user From 9ac184bac21de3f6ba17b16dcf05a596b3d6b82c Mon Sep 17 00:00:00 2001 From: BanulaMahen Date: Thu, 30 Mar 2023 01:25:49 +0530 Subject: [PATCH 2/6] Update views.py --- src/app/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/app/views.py b/src/app/views.py index 43891955..282a7471 100644 --- a/src/app/views.py +++ b/src/app/views.py @@ -1004,7 +1004,6 @@ def licenseRequests(request, license_id=None): """ View for license requests which are not archived returns license_requests.html template """ - print(license_id) context_dict = {} if request.user.is_authenticated: user = request.user From a3e40d9a3704a1b3c34823e7771ab93e54233b2d Mon Sep 17 00:00:00 2001 From: BanulaMahen Date: Sat, 1 Apr 2023 14:32:50 +0530 Subject: [PATCH 3/6] IssueID is added to LicenseRequest model insted License Model --- .../0003_remove_licensenamespace_issueid.py | 17 +++++++++++++++++ src/app/models.py | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/app/migrations/0003_remove_licensenamespace_issueid.py diff --git a/src/app/migrations/0003_remove_licensenamespace_issueid.py b/src/app/migrations/0003_remove_licensenamespace_issueid.py new file mode 100644 index 00000000..007f3fcb --- /dev/null +++ b/src/app/migrations/0003_remove_licensenamespace_issueid.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.18 on 2023-04-01 08:58 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('app', '0002_auto_20230330_0034'), + ] + + operations = [ + migrations.RemoveField( + model_name='licensenamespace', + name='issueId', + ), + ] diff --git a/src/app/models.py b/src/app/models.py index f555ec5d..af02c349 100644 --- a/src/app/models.py +++ b/src/app/models.py @@ -36,12 +36,12 @@ class License(models.Model): notes = models.CharField(max_length=255, default="") xml = models.TextField() archive = models.BooleanField(default=False) - issueId = models.TextField(default='') class Meta: abstract = True class LicenseRequest(License): + issueId = models.TextField(default='') def __unicode__(self): return "%s" % (self.fullname) From 8b0b65920c1319405bedd98094b56804e4523cfc Mon Sep 17 00:00:00 2001 From: BanulaMahen Date: Sun, 16 Apr 2023 09:30:24 +0530 Subject: [PATCH 4/6] updating utils.createIssue --- src/api/views.py | 2 +- src/app/views.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api/views.py b/src/api/views.py index d12c9459..6c2187f6 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -313,7 +313,7 @@ def submit_license(request): if 'urlType' in request.POST: # This is present only when executing submit license via tests urlType = request.POST["urlType"] - statusCode = createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseRequestUrl, token, urlType) + statusCode,issueId = createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseRequestUrl, token, urlType) if str(statusCode) == '201': result = "Success! The license request has been successfully submitted." query.result = result diff --git a/src/app/views.py b/src/app/views.py index 282a7471..d8a1486d 100644 --- a/src/app/views.py +++ b/src/app/views.py @@ -988,7 +988,7 @@ def promoteNamespaceRequests(request, license_id=None): if 'urlType' in request.POST: # This is present only when executing submit license via tests urlType = request.POST["urlType"] - statusCode = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType) + statusCode,issueId = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType) return_tuple = (statusCode, licenseRequest) statusCode = return_tuple[0] if statusCode == 201: @@ -1163,7 +1163,7 @@ def issue(request): 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) + statusCode,issueId = 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: From b4a5988b770a5d3eb9c1c19e4edfdafed98f5d5e Mon Sep 17 00:00:00 2001 From: BanulaMahen Date: Sun, 16 Apr 2023 09:54:10 +0530 Subject: [PATCH 5/6] Formatting --- src/api/views.py | 3 ++- src/app/views.py | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/api/views.py b/src/api/views.py index 6c2187f6..d06ce438 100644 --- a/src/api/views.py +++ b/src/api/views.py @@ -313,7 +313,8 @@ def submit_license(request): if 'urlType' in request.POST: # This is present only when executing submit license via tests urlType = request.POST["urlType"] - statusCode,issueId = createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseRequestUrl, token, urlType) + statusCode, issueId = createIssue(licenseAuthorName, licenseName, licenseIdentifier, + licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseRequestUrl, token, urlType) if str(statusCode) == '201': result = "Success! The license request has been successfully submitted." query.result = result diff --git a/src/app/views.py b/src/app/views.py index d8a1486d..23a141b2 100644 --- a/src/app/views.py +++ b/src/app/views.py @@ -162,7 +162,8 @@ def submitNewLicense(request): licenseId = licenseRequest.id serverUrl = request.build_absolute_uri('/') licenseRequestUrl = os.path.join(serverUrl, reverse('license-requests')[1:], str(licenseId)) - statusCode, issueId = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType) + statusCode, issueId = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, + licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType) licenseRequest.issueId = issueId licenseRequest.save() # If the license text matches with either rejected or yet not approved license then return 409 Conflict @@ -988,7 +989,8 @@ def promoteNamespaceRequests(request, license_id=None): if 'urlType' in request.POST: # This is present only when executing submit license via tests urlType = request.POST["urlType"] - statusCode,issueId = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType) + statusCode, issueId = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, + licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType) return_tuple = (statusCode, licenseRequest) statusCode = return_tuple[0] if statusCode == 201: @@ -1163,7 +1165,9 @@ def issue(request): licenseRequestId = licenseRequest.id serverUrl = request.build_absolute_uri('/') licenseRequestUrl = os.path.join(serverUrl, reverse('license-requests')[1:], str(licenseRequestId)) - statusCode,issueId = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, token, urlType, matchId, diffUrl, msg) + statusCode, issueId = 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: From becb2631e3de4b116488f7504407c6bcd8ef48e9 Mon Sep 17 00:00:00 2001 From: BanulaMahen Date: Sun, 16 Apr 2023 10:03:40 +0530 Subject: [PATCH 6/6] Formatting --- src/app/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/views.py b/src/app/views.py index 23a141b2..993aabb6 100644 --- a/src/app/views.py +++ b/src/app/views.py @@ -1165,9 +1165,9 @@ def issue(request): licenseRequestId = licenseRequest.id serverUrl = request.build_absolute_uri('/') licenseRequestUrl = os.path.join(serverUrl, reverse('license-requests')[1:], str(licenseRequestId)) - statusCode, issueId = utils.createIssue(licenseAuthorName, licenseName, licenseIdentifier, - licenseComments, licenseSourceUrls, licenseHeader, licenseOsi, licenseExamples, licenseRequestUrl, - token, urlType, matchId, diffUrl, msg) + statusCode, issueId = 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: