|
68 | 68 | from fedcode.models import Review |
69 | 69 | from fedcode.models import SyncRequest |
70 | 70 | from fedcode.models import Vulnerability |
| 71 | +from fedcode.pipes.utils import get_vulnerability_path |
71 | 72 | from fedcode.signatures import FEDERATEDCODE_PUBLIC_KEY |
72 | 73 | from fedcode.signatures import HttpSignature |
73 | 74 | from fedcode.utils import ap_collection |
@@ -810,16 +811,17 @@ def redirect_repository(request, repository_id): |
810 | 811 | def redirect_vulnerability(request, vulnerability_id): |
811 | 812 | try: |
812 | 813 | vul = Vulnerability.objects.get(id=vulnerability_id) |
813 | | - vul_filepath = os.path.join( |
814 | | - vul.repo.path, |
815 | | - f"./aboutcode-vulnerabilities-{vulnerability_id[5:7]}/{vulnerability_id[10:12]}" |
816 | | - f"/{vulnerability_id}/{vulnerability_id}.yml", |
817 | | - ) |
818 | | - with open(vul_filepath) as f: |
819 | | - return HttpResponse(json.dumps(f.read())) |
| 814 | + |
| 815 | + repo_path = vul.repo.path |
| 816 | + vul_filepath = get_vulnerability_path(repo_path, vulnerability_id) |
| 817 | + |
| 818 | + with open(vul_filepath, encoding="utf-8") as f: |
| 819 | + return HttpResponse(json.dumps(f.read()), content_type="application/json") |
820 | 820 |
|
821 | 821 | except Vulnerability.DoesNotExist: |
822 | | - return Http404("Vulnerability does not exist") |
| 822 | + raise Http404("Vulnerability does not exist") |
| 823 | + except FileNotFoundError: |
| 824 | + raise Http404("Vulnerability file not found") |
823 | 825 |
|
824 | 826 |
|
825 | 827 | class UserFollowing(View): |
|
0 commit comments