diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index dad854e6..64605350 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,9 +1,58 @@ -This project tracks patch provenance and licensing using the -[Developer Certificate of Origin][DCO] and Signed-off-by tags -initially developed by the Linux kernel project. Because the -documentation for this procedure is licensed under the GPLv2, we have -chosen not to include it in our project directly. Instead, please see -[SubmittingPatches][], which is stored in an external repository. - -[DCO]: developer-certificate-of-origin -[SubmittingPatches]: https://github.com/wking/signed-off-by/blob/a52266b0dd55b0424ab682dc636bef6bc76e3c0d/Documentation/SubmittingPatches +# Contributing to SPDX Online Tools + +Thank you for considering contributing to SPDX Online Tools! This document will provide you with information about how to contribute to this project. + +# Before you contribute to the SPDX Online Tools + +Please familiarize yourself with the SPDX Online Tools and its supporting documentation, so that you understand the pertinent context around the list itself: + +- [Working of the Tool](https://github.com/spdx/spdx-online-tools/wiki/Online-SPDX-Tool,-Google-Summer-of-Code-2017) + +- [SPDX License List Matching Guidelines](https://spdx.org/spdx-license-list/matching-guidelines) provides guidelines to be used for the purposes of matching licenses and license exceptions against those included on the SPDX License List. + +- [SPDX Specification](https://spdx.org/specifications): It is helpful to be familiar with certain sections of the SPDX Specification that use or deal with the SPDX License List. In particular: sub-sections related to license information in Section 3, 4, and 6; Appendices II, IV, and V. + +# Join the mailing list and our bi-weekly calls + +The SPDX License List is maintained by the SPDX Legal Team. Work and discussion is primarily done via: + +- **join the mailing list**: Please introduce yourself and let us know a bit about your interest in SPDX! The mailing list is our traditional form of communication. Join the mailing list, see archive, and manage your subscription at [lists.spdx.org](https://lists.spdx.org/g/Spdx-legal). +- **join the bi-weekly calls**: Bi-weekly conference call info is sent prior to the calls via the mailing list. If you join the mailing list, you should get a recurring invite at the beginning of each calendar year. Meeting minutes for the calls are in the [SPDX meetings repo](https://github.com/spdx/meetings/tree/main/legal); historical meeting minutes can be found at http://wiki.spdx.org/ + +# Working of the tool + +It works exactly how the java tools works except it takes minimum input from the user and do the rest from those input. There are 4 tools in the online tool : + +1. _Validation_ - To verify and validate valid SPDX tag/value file and rdf file. +2. _Conversion_ - To convert from one SPDX format to another. +3. _Comparison_ - To compare multiple SPDX RDF file and return the result as an excel sheet. +4. _Check License_ – To compares license text to the SPDX listed licenses + +**Validation:** +The user inputs a file and upload it to the server. Then the Django app through JPype calls the java tool jar file and run the verify function and return the result as Success or Error. Success shows that the file is valid as per the latest SPDX specifications. Error shows that the file is either an invalid file format or an invalid Tag/value or RDF file. If it’s the later one, it shows the line no. of the error or the XML tag that file have missed. + +**Comparison:** +This tool has 2 types of file input method. The user can select the file one by one if the files are in different folder or select them all at once if they are all in the same folder. +After the files are uploaded, they are first verified whether they are valid or not. If they are not valid, the user is shown which file is invalid and what errors are there. +If all the files are valid (or only warnings are raised) then the comparison method is called and the files are compared and an excel file is available for the user to download. + +**Convert:** +The user can convert from one SPDX file format to another like Tag value file to RDF or vice versa. RDF to excel or vice versa. +The tool first validates the file whether it is valid or not, and then only call the convert function and return the downloadable file. + +**Check License:** +The user can compares license text to the SPDX listed licenses . The user inputs the license text to be searched and the tool searches the text in the license list from [spdx.org/licenses](https://spdx.org/licenses/). + +# Working of the REST API + +The API works the same way as the above tools. You can find about the file input fields for the different tools [[here | REST-API-Fields-Request-and-Response]] + +# Getting started + +Below are some ways you can get started participating and contributing! + +- Make suggestions to improvement for documentation: Newcomers have a great perspective as to the effectiveness of documentation! You can make suggestions via an issue, if you want to discuss the changes or if there is something specific that could be updated, then create a PR + +- Review PRs + +- Solving issues with the tag [good-first-issue](https://github.com/spdx/spdx-online-tools/labels/good-first-issue) can be a great starting point for all the new developers diff --git a/src/app/views.py b/src/app/views.py index 9e63b615..61bf6112 100644 --- a/src/app/views.py +++ b/src/app/views.py @@ -16,13 +16,10 @@ from django.http import HttpResponse,HttpResponseRedirect from django.contrib.auth import authenticate,login ,logout,update_session_auth_hash from django.conf import settings -from django import forms -from django.template import RequestContext, context from django.core.files.storage import FileSystemStorage from django.urls import reverse from django.contrib.auth.forms import PasswordChangeForm from django.contrib.auth.models import User -from django.utils.datastructures import MultiValueDictKeyError from django.contrib.auth.decorators import login_required from django.http import JsonResponse from src.version import spdx_online_tools_version @@ -33,15 +30,13 @@ import jpype import requests from lxml import etree -import re import os import logging import json from traceback import format_exc -from json import dumps, loads +from json import dumps from time import time from urllib.parse import urljoin -import xml.etree.cElementTree as ET import datetime import uuid from wsgiref.util import FileWrapper @@ -63,7 +58,6 @@ from .models import LicenseRequest, LicenseNamespace from spdx_license_matcher.utils import get_spdx_license_text -import cgi def index(request): """ View for index @@ -857,59 +851,47 @@ def license_xml_edit(request, page_id): else: return HttpResponseRedirect('/app/xml_upload') + +def get_context_dict_for_license_xml(request, license_obj): + context_dict = {} + if request.user.is_authenticated: + user = request.user + try: + github_login = user.social_auth.get(provider="github") + except UserSocialAuth.DoesNotExist: + github_login = None + context_dict["github_login"] = github_login + context_dict["xml_text"] = license_obj.xml + context_dict["license_name"] = license_obj.fullname + return context_dict + + def edit_license_xml(request, license_id=None): """View for editing the XML file corresponsing to a license entry - returns editor.html """ - context_dict = {} - ajaxdict = {} + returns editor.html""" if license_id: if not LicenseRequest.objects.filter(id=license_id).exists(): - return render(request, - '404.html',context_dict,status=404 - ) - if request.user.is_authenticated: - user = request.user - try: - github_login = user.social_auth.get(provider='github') - except UserSocialAuth.DoesNotExist: - github_login = None - context_dict["github_login"] = github_login + return render(request, "404.html", {}, status=404) license_obj = LicenseRequest.objects.get(id=license_id) - context_dict["xml_text"] = license_obj.xml - context_dict["license_name"] = license_obj.fullname - return render(request, - 'app/editor.html',context_dict,status=200 - ) + context_dict = get_context_dict_for_license_xml(request, license_obj) + return render(request, "app/editor.html", context_dict, status=200) else: return HttpResponseRedirect('/app/license_requests') def edit_license_namespace_xml(request, license_id=None): """View for editing the XML file corresponsing to a license namespace entry - returns editor.html """ - context_dict = {} - ajaxdict = {} + returns editor.html""" if license_id: if not LicenseNamespace.objects.filter(id=license_id).exists(): - return render(request, - '404.html',context_dict,status=404 - ) - if request.user.is_authenticated: - user = request.user - try: - github_login = user.social_auth.get(provider='github') - except UserSocialAuth.DoesNotExist: - github_login = None - context_dict["github_login"] = github_login + return render(request, "404.html", {}, status=404) license_obj = LicenseNamespace.objects.get(id=license_id) - context_dict["xml_text"] = license_obj.xml - context_dict["license_name"] = license_obj.fullname - return render(request, - 'app/ns_editor.html',context_dict,status=200 - ) + context_dict = get_context_dict_for_license_xml(request, license_obj) + return render(request, "app/ns_editor.html", context_dict, status=200) else: return HttpResponseRedirect('/app/license_namespace_requests') + def archiveRequests(request, license_id=None): """ View for archive license requests returns archive_requests.html template @@ -1205,112 +1187,84 @@ def issue(request): return HttpResponseRedirect(settings.LOGIN_URL) -def pull_request(request): - """ View that handles pull request """ +def handle_pull_request(request, is_ns): + """Handler for pull request""" if request.user.is_authenticated: - if request.method=="POST": - context_dict = {} + if request.method == "POST": ajaxdict = {} try: if request.user.is_authenticated: user = request.user try: - """ Getting user info and calling the makePullRequest function """ - github_login = user.social_auth.get(provider='github') + """Getting user info and calling the makePullRequest function""" + github_login = user.social_auth.get(provider="github") token = github_login.extra_data["access_token"] username = github_login.extra_data["login"] - response = utils.makePullRequest(username, token, request.POST["branchName"], request.POST["updateUpstream"], request.POST["fileName"], request.POST["commitMessage"], request.POST["prTitle"], request.POST["prBody"], request.POST["xmlText"], False) - if(response["type"]=="success"): - """ PR made successfully """ - if (request.is_ajax()): + response = utils.makePullRequest( + username, + token, + request.POST["branchName"], + request.POST["updateUpstream"], + request.POST["fileName"], + request.POST["commitMessage"], + request.POST["prTitle"], + request.POST["prBody"], + request.POST["xmlText"], + is_ns, + ) + if response["type"] == "success": + """PR made successfully""" + if request.is_ajax(): ajaxdict["type"] = "success" ajaxdict["data"] = response["pr_url"] response = dumps(ajaxdict) - return HttpResponse(response,status=200) - return HttpResponse(response["pr_url"],status=200) + return HttpResponse(response, status=200) + return HttpResponse(response["pr_url"], status=200) else: - """ Error while making PR """ - if (request.is_ajax()): + """Error while making PR""" + if request.is_ajax(): ajaxdict["type"] = "pr_error" ajaxdict["data"] = response["message"] response = dumps(ajaxdict) - return HttpResponse(response,status=500) - return HttpResponse(response["message"],status=500) + return HttpResponse(response, status=500) + return HttpResponse(response["message"], status=500) except UserSocialAuth.DoesNotExist: - """ User not authenticated with GitHub """ - if (request.is_ajax()): + """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(response, status=401) return HttpResponse("Please login using GitHub to use this feature.",status=401) except: - """ Other errors raised """ + """Other errors raised""" logger.error(str(format_exc())) - if (request.is_ajax()): + 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() + 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) - return HttpResponse("Unexpected error, please email the SPDX technical workgroup that the following error has occurred: " + format_exc(), status=500) + return HttpResponse(response, status=500) + return HttpResponse( + "Unexpected error, please email the SPDX technical workgroup that the following error has occurred: " + format_exc(), + status=500, + ) else: return HttpResponseRedirect(settings.HOME_URL) else: return HttpResponseRedirect(settings.LOGIN_URL) +def pull_request(request): + """ View that handles pull request """ + return handle_pull_request(request, is_ns=False) + + def namespace_pull_request(request): """ View that handles pull request for a license namespace """ - if request.user.is_authenticated: - if request.method=="POST": - context_dict = {} - ajaxdict = {} - try: - if request.user.is_authenticated: - user = request.user - try: - """ Getting user info and calling the makePullRequest function """ - github_login = user.social_auth.get(provider='github') - token = github_login.extra_data["access_token"] - username = github_login.extra_data["login"] - response = utils.makePullRequest(username, token, request.POST["branchName"], request.POST["updateUpstream"], request.POST["fileName"], request.POST["commitMessage"], request.POST["prTitle"], request.POST["prBody"], request.POST["xmlText"], True) - if(response["type"]=="success"): - """ PR made successfully """ - if (request.is_ajax()): - ajaxdict["type"] = "success" - ajaxdict["data"] = response["pr_url"] - response = dumps(ajaxdict) - return HttpResponse(response,status=200) - return HttpResponse(response["pr_url"],status=200) - else: - """ Error while making PR """ - if (request.is_ajax()): - ajaxdict["type"] = "pr_error" - ajaxdict["data"] = response["message"] - response = dumps(ajaxdict) - return HttpResponse(response,status=500) - return HttpResponse(response["message"],status=500) - 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) - except: - """ 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) - return HttpResponse("Unexpected error, please email the SPDX technical workgroup that the following error has occurred: " + format_exc(), status=500) - else: - return HttpResponseRedirect(settings.HOME_URL) - else: - return HttpResponseRedirect(settings.LOGIN_URL) + return handle_pull_request(request, is_ns=True) def loginuser(request):