From b2cbcc3d891ff4ff0c497fc4992c1f17b9aad11b Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Thu, 11 Apr 2024 18:34:37 +0530 Subject: [PATCH 01/14] fix: package naming, verification digest bug, versions based verification --- backend/check_digests.py | 8 +- backend/debug_req.json | 930 ++++++++++++++++++++++++++++++++++++++ backend/models/package.py | 5 +- backend/unverify.py | 36 ++ backend/validate.py | 65 ++- 5 files changed, 1003 insertions(+), 41 deletions(-) create mode 100644 backend/debug_req.json create mode 100644 backend/unverify.py diff --git a/backend/check_digests.py b/backend/check_digests.py index 0e705ccc..829a482d 100644 --- a/backend/check_digests.py +++ b/backend/check_digests.py @@ -1,6 +1,7 @@ from typing import Tuple import numpy as np import json +import re def hash(input_string): @@ -28,6 +29,8 @@ def dilate(instr): outstr.append(outstr_c) return outstr +def process(lines): + return re.sub(r'(?<=\S) +(?=\n)', '', ''.join(lines)) def check_digests(file_path: str) -> Tuple[int, bool]: """ @@ -65,9 +68,10 @@ def check_digests(file_path: str) -> Tuple[int, bool]: try: # Read the content of the file - with open(f"{file_path}{file_name}", 'r',newline='') as file: - file_content: str = file.read() + with open(f'{file_path}{file_name.replace("./", "")}', 'r',newline='') as file: + file_content: str = ''.join(process(file.readlines())) except: + print(f'Error reading file content: {file_path}{file_name}') return (-1, "Error reading file content.") # Compute the digest of the file content diff --git a/backend/debug_req.json b/backend/debug_req.json new file mode 100644 index 00000000..6aeb0f7e --- /dev/null +++ b/backend/debug_req.json @@ -0,0 +1,930 @@ +{ + "code": 200, + "packages": [ + { + "author": "urbanjost", + "categories": [ + "fortran", + "fpm", + "preprocessing", + "application", + "preprocessing", + "application", + "preprocessing", + "application", + "preprocessing", + "application", + "preprocessing", + "application", + "preprocessing", + "application", + "preprocessing", + "application", + "preprocessing", + "application", + "preprocessing", + "application", + "preprocessing", + "application", + "preprocessing", + "application", + "preprocessing", + "application", + "preprocessing", + "application", + "preprocessing", + "application", + "preprocessing", + "application", + "preprocessing", + "application" + ], + "description": "Fortran pre-processor", + "keywords": [ + "fortran", + "fpm", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran", + "preprocessor", + "fortran", + "fpm", + "General Purpose Fortran" + ], + "name": "prep", + "namespace": "GPF", + "updated_at": "Sat, 30 Mar 2024 18:11:10 GMT" + }, + { + "author": "mskocic", + "categories": [ + "fortran", + "fpm" + ], + "description": "description not provided.", + "keywords": [ + "fortran", + "fpm" + ], + "name": "iapws", + "namespace": "mskocic", + "updated_at": "Mon, 25 Mar 2024 16:45:10 GMT" + }, + { + "author": "mskocic", + "categories": [ + "fortran", + "fpm", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science", + "Science" + ], + "description": "CODATA physical constants.", + "keywords": [ + "fortran", + "fpm", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry", + "constants", + "physics", + "chemistry" + ], + "name": "codata", + "namespace": "mskocic", + "updated_at": "Sun, 24 Mar 2024 22:07:49 GMT" + }, + { + "author": "urbanjost", + "categories": [ + "fortran", + "fpm", + "Universally Unique ID", + "Universally Unique ID", + "Universally Unique ID", + "Universally Unique ID", + "Universally Unique ID", + "Universally Unique ID", + "Universally Unique ID", + "Universally Unique ID", + "Universally Unique ID", + "Universally Unique ID", + "Universally Unique ID", + "Universally Unique ID", + "Universally Unique ID", + "Universally Unique ID", + "Universally Unique ID", + "Universally Unique ID" + ], + "description": "module to produce a UUID string", + "keywords": [ + "fortran", + "fpm", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID", + "fortran", + "UUID", + "RFC 4122", + "Universally Unique ID" + ], + "name": "M_uuid", + "namespace": "GPF", + "updated_at": "Sat, 30 Mar 2024 16:05:10 GMT" + }, + { + "author": "urbanjost", + "categories": [ + "fortran", + "fpm", + "time", + "time", + "time", + "time", + "time", + "time", + "time", + "time", + "time", + "time", + "time", + "time", + "time", + "time", + "time", + "time" + ], + "description": "date and time conversion, formatting and computation ", + "keywords": [ + "fortran", + "fpm", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar", + "fortran", + "date", + "time", + "Julian", + "Unix Epoch", + "calendar" + ], + "name": "M_time", + "namespace": "GPF", + "updated_at": "Sat, 30 Mar 2024 16:04:25 GMT" + }, + { + "author": "urbanjost", + "categories": [ + "fortran", + "fpm", + "POSIX", + "system", + "POSIX", + "system", + "POSIX", + "system", + "POSIX", + "system", + "POSIX", + "system", + "POSIX", + "system", + "POSIX", + "system", + "POSIX", + "system", + "POSIX", + "system", + "POSIX", + "system", + "POSIX", + "system", + "POSIX", + "system", + "POSIX", + "system", + "POSIX", + "system", + "POSIX", + "system", + "POSIX", + "system" + ], + "description": "(mostly)POSIX system routine interface", + "keywords": [ + "fortran", + "fpm", + "fortran", + "system interface", + "fortran", + "system interface", + "fortran", + "system interface", + "fortran", + "system interface", + "fortran", + "system interface", + "fortran", + "system interface", + "fortran", + "system interface", + "fortran", + "system interface", + "fortran", + "system interface", + "fortran", + "system interface", + "fortran", + "system interface", + "fortran", + "system interface", + "fortran", + "system interface", + "fortran", + "system interface", + "fortran", + "system interface", + "fortran", + "system interface" + ], + "name": "M_system", + "namespace": "GPF", + "updated_at": "Sat, 30 Mar 2024 16:41:50 GMT" + }, + { + "author": "urbanjost", + "categories": [ + "fortran", + "fpm", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran", + "timing", + "fortran" + ], + "description": "timing routines using stopwatches", + "keywords": [ + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm", + "timing", + "fortran", + "fpm" + ], + "name": "M_stopwatch", + "namespace": "GPF", + "updated_at": "Tue, 26 Mar 2024 00:57:29 GMT" + }, + { + "author": "urbanjost", + "categories": [ + "fortran", + "fpm", + "sorting", + "sorting", + "sorting", + "sorting", + "sorting", + "sorting", + "sorting", + "sorting", + "sorting", + "sorting", + "sorting", + "sorting", + "sorting", + "sorting", + "sorting", + "sorting" + ], + "description": "sorting procedures", + "keywords": [ + "fortran", + "fpm", + "fortran", + "quick sort", + "fortran", + "quick sort", + "fortran", + "quick sort", + "fortran", + "quick sort", + "fortran", + "quick sort", + "fortran", + "quick sort", + "fortran", + "quick sort", + "fortran", + "quick sort", + "fortran", + "quick sort", + "fortran", + "quick sort", + "fortran", + "quick sort", + "fortran", + "quick sort", + "fortran", + "quick sort", + "fortran", + "quick sort", + "fortran", + "quick sort", + "fortran", + "quick sort" + ], + "name": "M_sort", + "namespace": "GPF", + "updated_at": "Sat, 30 Mar 2024 16:03:41 GMT" + }, + { + "author": "urbanjost", + "categories": [ + "fortran", + "fpm", + "graphics", + "graphics", + "graphics", + "graphics", + "graphics", + "graphics", + "graphics", + "graphics", + "graphics", + "graphics", + "graphics", + "graphics", + "graphics", + "graphics", + "graphics", + "graphics" + ], + "description": " produce basic slice plot on POSIX systems with X11 Windows", + "keywords": [ + "fortran", + "fpm", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph", + "fortran", + "plot", + "graph" + ], + "name": "M_slices", + "namespace": "GPF", + "updated_at": "Sat, 30 Mar 2024 15:59:40 GMT" + }, + { + "author": "urbanjost", + "categories": [ + "fortran", + "fpm", + "sets", + "sets", + "sets", + "sets", + "sets", + "sets", + "sets", + "sets", + "sets", + "sets", + "sets", + "sets", + "sets", + "sets", + "sets" + ], + "description": "set-theory functions including Union, intersection, and set membership", + "keywords": [ + "fortran", + "fpm", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership", + "fortran", + "sets", + "set-theory", + "union", + "intersection", + "membership" + ], + "name": "M_sets", + "namespace": "GPF", + "updated_at": "Sat, 30 Mar 2024 16:03:18 GMT" + } + ], + "total_pages": 5 +} \ No newline at end of file diff --git a/backend/models/package.py b/backend/models/package.py index 0a76dd09..6cc2091a 100644 --- a/backend/models/package.py +++ b/backend/models/package.py @@ -1,6 +1,6 @@ class Package: def __init__(self, name, namespace, description, homepage, repository, - copyright, license, created_at, updated_at, author, maintainers, keywords, categories, is_deprecated, versions=[], id=None, + copyright, license, created_at, updated_at, author, maintainers, keywords, categories, is_deprecated, versions=[], id=None,unable_to_verify=False, malicious_report={}, is_verified=False, is_malicious=False, security_status="No security issues found", ratings={"users": {}, "avg_ratings": 0}): self.id = id self.name = name @@ -24,6 +24,7 @@ def __init__(self, name, namespace, description, homepage, repository, self.downloads_stats = {} self.ratings = ratings self.categories = categories + self.unable_to_verify = unable_to_verify # Ensure that versions list only contains instances of Version class for v in self.versions: @@ -61,6 +62,7 @@ def to_json(self): "is_malicious": self.is_malicious, "security_status": self.security_status, "ratings": self.ratings, + "unable_to_verify": self.unable_to_verify, } # Create a from_json method. @@ -94,6 +96,7 @@ def from_json(json_data): is_malicious=json_data.get("is_malicious"), security_status=json_data.get("security_status"), ratings=json_data.get("ratings"), + unable_to_verify=json_data.get("unable_to_verify"), ) class Version: diff --git a/backend/unverify.py b/backend/unverify.py new file mode 100644 index 00000000..3ca22fe6 --- /dev/null +++ b/backend/unverify.py @@ -0,0 +1,36 @@ +from mongo import db +import pymongo + +# t = db.packages.update_many({}, {"$set": {"is_verified": False}}) +# print(t.modified_count) +# packages = list(db.packages.find()) + +# # Step 2: Make keywords unique for each package +# for package in packages: +# unique_keywords = list(set(package.get("categories", []))) # Making keywords unique +# package["categories"] = unique_keywords + +# # Step 3: Store the updated packages in a list +# updated_packages = [{"_id": package["_id"], "categories": package["categories"]} for package in packages] + +# # Step 4: Perform bulk update operation +# bulk_operations = [pymongo.UpdateOne({"_id": package["_id"]}, {"$set": {"categories": package["categories"]}}) for package in updated_packages] +# result = db.packages.bulk_write(bulk_operations) + +# print("Number of documents matched:", result.matched_count) +# print("Number of documents modified:", result.modified_count) +# remove key k from all the documents in the collection +t = db.packages.update_many({}, {"$set": {"is_verified": False}}) +# result = db.packages.update_many({}, {"$set": {"unable_to_verify": False}}) + +# print("Number of documents matched:", result.matched_count) +# print("Number of documents modified:", result.modified_count) + +print(t.modified_count,t.matched_count) + +# M_fixedform-0.1.2 + + + +# report check if access_token is not undefined. +# diff --git a/backend/validate.py b/backend/validate.py index 9dc08ef6..1c15b406 100755 --- a/backend/validate.py +++ b/backend/validate.py @@ -1,7 +1,7 @@ from app import app import subprocess import toml -import html +import os from mongo import db from mongo import file_storage from bson.objectid import ObjectId @@ -9,7 +9,6 @@ import toml from check_digests import check_digests from typing import Union,List, Tuple, Dict, Any -import markdown def run_command(command: str) -> Union[str, None]: @@ -29,24 +28,27 @@ def run_command(command: str) -> Union[str, None]: print(result.stderr) return result.stdout if result.stdout else result.stderr -def collect_dependencies(section: str, parsed_toml: Dict[str, List[Dict[str, Any]]]) -> List[Tuple[str, str]]: +def extract_dependencies(parsed_toml: Dict[str, List[Dict[str, Any]]]) -> List[Tuple[str, str, str]]: """ - Collect dependencies from a section in a parsed TOML file. - + Extracts dependencies from a parsed TOML file. + Args: - section (str): The section in the TOML file to collect dependencies from. parsed_toml (Dict[str, List[Dict[str, Any]]]): The parsed TOML file represented as a dictionary. Returns: - List[Tuple[str, str]]: A list of dependency tuples containing (namespace, dependency_name). - + List[Tuple[str, str, str]]: A list of dependency tuples containing (namespace, package_name, version). + """ dependencies = list() - for dependency_dict in parsed_toml.get(section, []): - for dependency_name, dependency_info in dependency_dict.get('dependencies', {}).items(): - dependencies.append((dependency_info['namespace'],dependency_name)) + for dependency_name, dependency_info in parsed_toml.get('dependencies', {}).items(): + dependencies.append((dependency_info['namespace'], dependency_name, dependency_info.get('v', None))) + for section in ['test', 'example', 'executable']: + if section in parsed_toml and 'dependencies' in parsed_toml[section]: + for dependency_name, dependency_info in parsed_toml[section].get('dependencies', {}).items(): + dependencies.append((dependency_info['namespace'], dependency_name, dependency_info.get('v', None))) return dependencies + def process_package(packagename: str) -> Tuple[bool, Union[dict, None], str]: """ This function creates a directory, extracts package contents, reads and parses 'fpm.toml', @@ -80,17 +82,14 @@ def process_package(packagename: str) -> Tuple[bool, Union[dict, None], str]: result = check_digests(f'static/temp/{packagename}/') + if os.path.exists(f'static/temp/{packagename}/README.md'): + with open(f'static/temp/{packagename}/README.md', 'r') as file: + parsed_toml['description'] = file.read() + # Clean up cleanup_command = f'rm -rf static/temp/{packagename} static/temp/{packagename}.tar.gz' - # run_command(cleanup_command) + run_command(cleanup_command) print(result) - - if 'description' in parsed_toml and parsed_toml['description'] == "README.md": - try: - with open(f'static/temp/{packagename}/README.md', 'r') as file: - parsed_toml['description'] = markdown.markdown(file.read()) # Sanitize HTML content - except: - parsed_toml['description'] = "README.md not found." if result[0]==-1: # Package verification failed @@ -111,7 +110,6 @@ def validate() -> None: Returns: None """ - # packages = db.packages.find({"versions": {"$elemMatch": {"isVerified": False}}}) # find packages with unverified versions packages = db.packages.find({"is_verified": False}) packages = list(packages) for package in packages: @@ -128,13 +126,14 @@ def validate() -> None: result = process_package(packagename) update_data = {} if result[0] == False: - update_data['isVerified'] = False - update_data['unabletoVerify'] = True + update_data['is_verified'] = False + update_data['unable_to_verify'] = True print("Package tests failed for " + packagename) print(result) else: print("Package tests success for " + packagename) - update_data['isVerified'] = True + update_data['is_verified'] = True + update_data['unable_to_verify'] = False if result[2] == "Error parsing toml file": db.packages.update_one({"name": package['name'],"namespace":package['namespace']}, {"$set": update_data}) @@ -143,28 +142,18 @@ def validate() -> None: for key in ['repository', 'copyright', 'description',"homepage", 'categories', 'keywords']: if key in result[1] and package[key] != result[1][key]: if key in ['categories', 'keywords']: - update_data[key] = package[key] + result[1][key] + update_data[key] = list(set(package[key] + list(map(str.strip, result[1][key])))) else: update_data[key] = result[1][key] - dependencies = list() - try: - dependencies += [(dependency_info['namespace'],dependency_name) for dependency_name, dependency_info in result[1].get('dependencies', {}).items()] - except: - pass - for section in ['test', 'example', 'executable']: - try: - dependencies += collect_dependencies(section, result[1]) - except: - pass - - update_data['dependencies'] = list(set(dependencies)) + dependencies = extract_dependencies(result[1]) for i in dependencies: - dependency_package = db.packages.find_one({"name": i[1], "namespace": i[0]}) # TODO: enable version checking + namespace = db.namespaces.find_one({"namespace": i[0]}) + dependency_package = db.packages.find_one({"name": i[1], "namespace": namespace['namespace'], "versions.version": i[2] if i[2] is not None else {"$exists": True} }) if dependency_package is None: print(f"Dependency {i[0]}/{i[1]} not found in the database") - update_data['isVerified'] = False # if any dependency is not found, the package is not verified + update_data['is_verified'] = False for k,v in package.items(): if v == "Package Under Verification" and k not in update_data.keys(): From 5518b792914f53dbd24de09b751a2bd27e920c33 Mon Sep 17 00:00:00 2001 From: Henil Panchal Date: Thu, 18 Apr 2024 12:23:21 +0530 Subject: [PATCH 02/14] fix: multiple bugs --- backend/check_digests.py | 6 +- backend/debug_req.json | 930 ------------------------- backend/models/package.py | 7 +- backend/packages.py | 66 +- backend/unverify.py | 36 - backend/validate.py | 8 +- frontend/src/components/packageItem.js | 4 +- frontend/src/pages/package.js | 3 +- 8 files changed, 31 insertions(+), 1029 deletions(-) delete mode 100644 backend/debug_req.json delete mode 100644 backend/unverify.py diff --git a/backend/check_digests.py b/backend/check_digests.py index 829a482d..409ce60e 100644 --- a/backend/check_digests.py +++ b/backend/check_digests.py @@ -30,7 +30,9 @@ def dilate(instr): return outstr def process(lines): - return re.sub(r'(?<=\S) +(?=\n)', '', ''.join(lines)) + cleaned = re.sub(r'(?<=\S) +(?=\n)', '', ''.join(lines)) + cleaned = re.sub(r'(?<=\n)\t+(?=\n)', '', cleaned) + return re.sub(r'\n\s+\n', '\n\n\n', cleaned) def check_digests(file_path: str) -> Tuple[int, bool]: """ @@ -69,7 +71,7 @@ def check_digests(file_path: str) -> Tuple[int, bool]: try: # Read the content of the file with open(f'{file_path}{file_name.replace("./", "")}', 'r',newline='') as file: - file_content: str = ''.join(process(file.readlines())) + file_content: str = process(file.readlines()) except: print(f'Error reading file content: {file_path}{file_name}') return (-1, "Error reading file content.") diff --git a/backend/debug_req.json b/backend/debug_req.json deleted file mode 100644 index 6aeb0f7e..00000000 --- a/backend/debug_req.json +++ /dev/null @@ -1,930 +0,0 @@ -{ - "code": 200, - "packages": [ - { - "author": "urbanjost", - "categories": [ - "fortran", - "fpm", - "preprocessing", - "application", - "preprocessing", - "application", - "preprocessing", - "application", - "preprocessing", - "application", - "preprocessing", - "application", - "preprocessing", - "application", - "preprocessing", - "application", - "preprocessing", - "application", - "preprocessing", - "application", - "preprocessing", - "application", - "preprocessing", - "application", - "preprocessing", - "application", - "preprocessing", - "application", - "preprocessing", - "application", - "preprocessing", - "application", - "preprocessing", - "application" - ], - "description": "Fortran pre-processor", - "keywords": [ - "fortran", - "fpm", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran", - "preprocessor", - "fortran", - "fpm", - "General Purpose Fortran" - ], - "name": "prep", - "namespace": "GPF", - "updated_at": "Sat, 30 Mar 2024 18:11:10 GMT" - }, - { - "author": "mskocic", - "categories": [ - "fortran", - "fpm" - ], - "description": "description not provided.", - "keywords": [ - "fortran", - "fpm" - ], - "name": "iapws", - "namespace": "mskocic", - "updated_at": "Mon, 25 Mar 2024 16:45:10 GMT" - }, - { - "author": "mskocic", - "categories": [ - "fortran", - "fpm", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science", - "Science" - ], - "description": "CODATA physical constants.", - "keywords": [ - "fortran", - "fpm", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry", - "constants", - "physics", - "chemistry" - ], - "name": "codata", - "namespace": "mskocic", - "updated_at": "Sun, 24 Mar 2024 22:07:49 GMT" - }, - { - "author": "urbanjost", - "categories": [ - "fortran", - "fpm", - "Universally Unique ID", - "Universally Unique ID", - "Universally Unique ID", - "Universally Unique ID", - "Universally Unique ID", - "Universally Unique ID", - "Universally Unique ID", - "Universally Unique ID", - "Universally Unique ID", - "Universally Unique ID", - "Universally Unique ID", - "Universally Unique ID", - "Universally Unique ID", - "Universally Unique ID", - "Universally Unique ID", - "Universally Unique ID" - ], - "description": "module to produce a UUID string", - "keywords": [ - "fortran", - "fpm", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID", - "fortran", - "UUID", - "RFC 4122", - "Universally Unique ID" - ], - "name": "M_uuid", - "namespace": "GPF", - "updated_at": "Sat, 30 Mar 2024 16:05:10 GMT" - }, - { - "author": "urbanjost", - "categories": [ - "fortran", - "fpm", - "time", - "time", - "time", - "time", - "time", - "time", - "time", - "time", - "time", - "time", - "time", - "time", - "time", - "time", - "time", - "time" - ], - "description": "date and time conversion, formatting and computation ", - "keywords": [ - "fortran", - "fpm", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar", - "fortran", - "date", - "time", - "Julian", - "Unix Epoch", - "calendar" - ], - "name": "M_time", - "namespace": "GPF", - "updated_at": "Sat, 30 Mar 2024 16:04:25 GMT" - }, - { - "author": "urbanjost", - "categories": [ - "fortran", - "fpm", - "POSIX", - "system", - "POSIX", - "system", - "POSIX", - "system", - "POSIX", - "system", - "POSIX", - "system", - "POSIX", - "system", - "POSIX", - "system", - "POSIX", - "system", - "POSIX", - "system", - "POSIX", - "system", - "POSIX", - "system", - "POSIX", - "system", - "POSIX", - "system", - "POSIX", - "system", - "POSIX", - "system", - "POSIX", - "system" - ], - "description": "(mostly)POSIX system routine interface", - "keywords": [ - "fortran", - "fpm", - "fortran", - "system interface", - "fortran", - "system interface", - "fortran", - "system interface", - "fortran", - "system interface", - "fortran", - "system interface", - "fortran", - "system interface", - "fortran", - "system interface", - "fortran", - "system interface", - "fortran", - "system interface", - "fortran", - "system interface", - "fortran", - "system interface", - "fortran", - "system interface", - "fortran", - "system interface", - "fortran", - "system interface", - "fortran", - "system interface", - "fortran", - "system interface" - ], - "name": "M_system", - "namespace": "GPF", - "updated_at": "Sat, 30 Mar 2024 16:41:50 GMT" - }, - { - "author": "urbanjost", - "categories": [ - "fortran", - "fpm", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran", - "timing", - "fortran" - ], - "description": "timing routines using stopwatches", - "keywords": [ - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm", - "timing", - "fortran", - "fpm" - ], - "name": "M_stopwatch", - "namespace": "GPF", - "updated_at": "Tue, 26 Mar 2024 00:57:29 GMT" - }, - { - "author": "urbanjost", - "categories": [ - "fortran", - "fpm", - "sorting", - "sorting", - "sorting", - "sorting", - "sorting", - "sorting", - "sorting", - "sorting", - "sorting", - "sorting", - "sorting", - "sorting", - "sorting", - "sorting", - "sorting", - "sorting" - ], - "description": "sorting procedures", - "keywords": [ - "fortran", - "fpm", - "fortran", - "quick sort", - "fortran", - "quick sort", - "fortran", - "quick sort", - "fortran", - "quick sort", - "fortran", - "quick sort", - "fortran", - "quick sort", - "fortran", - "quick sort", - "fortran", - "quick sort", - "fortran", - "quick sort", - "fortran", - "quick sort", - "fortran", - "quick sort", - "fortran", - "quick sort", - "fortran", - "quick sort", - "fortran", - "quick sort", - "fortran", - "quick sort", - "fortran", - "quick sort" - ], - "name": "M_sort", - "namespace": "GPF", - "updated_at": "Sat, 30 Mar 2024 16:03:41 GMT" - }, - { - "author": "urbanjost", - "categories": [ - "fortran", - "fpm", - "graphics", - "graphics", - "graphics", - "graphics", - "graphics", - "graphics", - "graphics", - "graphics", - "graphics", - "graphics", - "graphics", - "graphics", - "graphics", - "graphics", - "graphics", - "graphics" - ], - "description": " produce basic slice plot on POSIX systems with X11 Windows", - "keywords": [ - "fortran", - "fpm", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph", - "fortran", - "plot", - "graph" - ], - "name": "M_slices", - "namespace": "GPF", - "updated_at": "Sat, 30 Mar 2024 15:59:40 GMT" - }, - { - "author": "urbanjost", - "categories": [ - "fortran", - "fpm", - "sets", - "sets", - "sets", - "sets", - "sets", - "sets", - "sets", - "sets", - "sets", - "sets", - "sets", - "sets", - "sets", - "sets", - "sets" - ], - "description": "set-theory functions including Union, intersection, and set membership", - "keywords": [ - "fortran", - "fpm", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership", - "fortran", - "sets", - "set-theory", - "union", - "intersection", - "membership" - ], - "name": "M_sets", - "namespace": "GPF", - "updated_at": "Sat, 30 Mar 2024 16:03:18 GMT" - } - ], - "total_pages": 5 -} \ No newline at end of file diff --git a/backend/models/package.py b/backend/models/package.py index 6cc2091a..f43dda6c 100644 --- a/backend/models/package.py +++ b/backend/models/package.py @@ -1,15 +1,17 @@ class Package: - def __init__(self, name, namespace, description, homepage, repository, + def __init__(self, name, namespace, namespace_name, description, homepage, repository, registry_description, copyright, license, created_at, updated_at, author, maintainers, keywords, categories, is_deprecated, versions=[], id=None,unable_to_verify=False, malicious_report={}, is_verified=False, is_malicious=False, security_status="No security issues found", ratings={"users": {}, "avg_ratings": 0}): self.id = id self.name = name self.namespace = namespace + self.namespace_name = namespace_name + self.registry_description = registry_description self.description = description self.homepage = homepage self.repository = repository self.copyright = copyright - self.license = license + self.license = license, self.created_at = created_at self.updated_at = updated_at self.author = author @@ -44,6 +46,7 @@ def to_json(self): "id": str(self.id), "name": self.name, "namespace": self.namespace, + "namespace_name": self.namespace_name, "description": self.description, "homepage": self.homepage, "repository": self.repository, diff --git a/backend/packages.py b/backend/packages.py index db16aff3..ea8f4e9a 100644 --- a/backend/packages.py +++ b/backend/packages.py @@ -132,24 +132,14 @@ def search_packages(): for i in packages: package_obj = Package.from_json(i) - namespace = db.namespaces.find_one({"_id": package_obj.namespace}) - namespace_obj = Namespace.from_json(namespace) - - author = db.users.find_one({"_id": package_obj.author}) - author_obj = User.from_json(author) - - package_obj.namespace = namespace_obj.namespace - package_obj.author = author_obj.username search_packages.append({ "name": package_obj.name, - "namespace": package_obj.namespace, - "author": package_obj.author, + "namespace": package_obj.namespace_name, "description": package_obj.description, "keywords": package_obj.keywords, "categories": package_obj.categories, "updated_at": package_obj.updated_at, }) - return ( jsonify( {"code": 200, "packages": search_packages, "total_pages": total_pages} @@ -207,11 +197,8 @@ def upload(): namespace_doc = db.namespaces.find_one( {"upload_tokens": {"$elemMatch": {"token": upload_token}}} ) - package_doc = db.packages.find_one( - {"upload_tokens": {"$elemMatch": {"token": upload_token}}} - ) - if not namespace_doc and not package_doc: + if not namespace_doc: return jsonify({"code": 401, "message": "Invalid upload token"}), 401 if namespace_doc: @@ -225,18 +212,6 @@ def upload(): {"name": package_name, "namespace": namespace_obj.id} ) - elif package_doc: - package_obj = Package.from_json(package_doc) - if package_obj.name != package_name: - return jsonify({"code": 401, "message": "Invalid upload token"}), 401 - - upload_token_doc = next( - item - for item in package_doc["upload_tokens"] - if item["token"] == upload_token - ) - namespace_doc = db.namespaces.find_one({"_id": package_doc["namespace"]}) - # Check if the token is expired. # Expire the token after one week of it's creation. if check_token_expiry(upload_token_created_at=upload_token_doc["createdAt"]): @@ -294,6 +269,7 @@ def upload(): "description": "Package Under Verification", "copyright": "Package Under Verification", "homepage": "Package Under Verification", + "registry_description": "Package Under Verification", } file_object_id = file_storage.put( @@ -306,6 +282,7 @@ def upload(): package_obj = Package( name=package_name, namespace=namespace_obj.id, + namespace_name=namespace_obj.namespace, description=package_data["description"], homepage=package_data["homepage"], repository=package_data["repository"], @@ -478,20 +455,9 @@ def check_version(current_version, new_version): @app.route("/packages//", methods=["GET"]) @swag_from("documentation/get_package.yaml", methods=["GET"]) def get_package(namespace_name, package_name): - # Get namespace from namespace name. - namespace = db.namespaces.find_one({"namespace": namespace_name}) - - # Check if namespace exists. - if not namespace: - return ( - jsonify({"status": "error", "message": "Namespace not found", "code": 404}), - 404, - ) - - namespace_obj = Namespace.from_json(namespace) - # Get package from a package_name and namespace's id. + # Get package from a package_name and namespace's name. package = db.packages.find_one( - {"name": package_name, "namespace": namespace_obj.id} + {"name": package_name, "namespace_name": namespace_name} ) # Check if package is not found. @@ -549,7 +515,7 @@ def get_package(namespace_name, package_name): # Only latest version of the package will be sent as a response. package_response_data = { "name": package_obj.name, - "namespace": namespace_obj.namespace, + "namespace": package_obj.namespace_name, "latest_version_data": latest_version_data, "author": package_author_obj.username, "keywords": package_obj.keywords if package_obj.keywords else [], @@ -559,6 +525,7 @@ def get_package(namespace_name, package_name): "version_history": version_history, "updated_at": package_obj.updated_at, "description": package_obj.description, + "registry_description": package_obj.registry_description, "ratings": ratings, "downloads": downloads_stats, "ratings_count": rating_count @@ -586,7 +553,7 @@ def verify_user_role(namespace_name, package_name): ) package = db.packages.find_one( - {"name": package_name, "namespace": namespace["_id"]} + {"name": package_name, "namespace": namespace_name} ) if not package: @@ -612,20 +579,11 @@ def verify_user_role(namespace_name, package_name): @app.route("/packages///", methods=["GET"]) @swag_from("documentation/get_version.yaml", methods=["GET"]) def get_package_from_version(namespace_name, package_name, version): - # Get namespace from namespace name. - namespace = db.namespaces.find_one({"namespace": namespace_name}) - - # Check if namespace does not exists. - if not namespace: - return jsonify({"message": "Namespace not found", "code": 404}), 404 - - namespace_obj = Namespace.from_json(namespace) - - # Get package from a package_name, namespace's id and version. + # Get package from a package_name, namespace_name and version. package = db.packages.find_one( { "name": package_name, - "namespace": namespace["_id"], + "namespace": namespace_name, "versions.version": version, } ) @@ -652,7 +610,7 @@ def get_package_from_version(namespace_name, package_name, version): # Only queried version should be sent as response. package_response_data = { "name": package_obj.name, - "namespace": namespace_obj.namespace, + "namespace": package_obj.namespace_name, "author": package_author_obj.username, "keywords": package_obj.keywords, "categories": package_obj.categories, diff --git a/backend/unverify.py b/backend/unverify.py deleted file mode 100644 index 3ca22fe6..00000000 --- a/backend/unverify.py +++ /dev/null @@ -1,36 +0,0 @@ -from mongo import db -import pymongo - -# t = db.packages.update_many({}, {"$set": {"is_verified": False}}) -# print(t.modified_count) -# packages = list(db.packages.find()) - -# # Step 2: Make keywords unique for each package -# for package in packages: -# unique_keywords = list(set(package.get("categories", []))) # Making keywords unique -# package["categories"] = unique_keywords - -# # Step 3: Store the updated packages in a list -# updated_packages = [{"_id": package["_id"], "categories": package["categories"]} for package in packages] - -# # Step 4: Perform bulk update operation -# bulk_operations = [pymongo.UpdateOne({"_id": package["_id"]}, {"$set": {"categories": package["categories"]}}) for package in updated_packages] -# result = db.packages.bulk_write(bulk_operations) - -# print("Number of documents matched:", result.matched_count) -# print("Number of documents modified:", result.modified_count) -# remove key k from all the documents in the collection -t = db.packages.update_many({}, {"$set": {"is_verified": False}}) -# result = db.packages.update_many({}, {"$set": {"unable_to_verify": False}}) - -# print("Number of documents matched:", result.matched_count) -# print("Number of documents modified:", result.modified_count) - -print(t.modified_count,t.matched_count) - -# M_fixedform-0.1.2 - - - -# report check if access_token is not undefined. -# diff --git a/backend/validate.py b/backend/validate.py index 1c15b406..56aef011 100755 --- a/backend/validate.py +++ b/backend/validate.py @@ -8,6 +8,7 @@ from gridfs.errors import NoFile import toml from check_digests import check_digests +from bson.objectid import ObjectId from typing import Union,List, Tuple, Dict, Any @@ -139,7 +140,7 @@ def validate() -> None: db.packages.update_one({"name": package['name'],"namespace":package['namespace']}, {"$set": update_data}) pass - for key in ['repository', 'copyright', 'description',"homepage", 'categories', 'keywords']: + for key in ['repository', 'copyright', 'description',"homepage", 'categories', 'keywords','registry_description']: if key in result[1] and package[key] != result[1][key]: if key in ['categories', 'keywords']: update_data[key] = list(set(package[key] + list(map(str.strip, result[1][key])))) @@ -150,7 +151,10 @@ def validate() -> None: for i in dependencies: namespace = db.namespaces.find_one({"namespace": i[0]}) - dependency_package = db.packages.find_one({"name": i[1], "namespace": namespace['namespace'], "versions.version": i[2] if i[2] is not None else {"$exists": True} }) + query = {"name": i[1], "namespace": ObjectId(str(namespace['_id']))} + if i[2] is not None: + query['versions.version'] = i[2] + dependency_package = db.packages.find_one(query) if dependency_package is None: print(f"Dependency {i[0]}/{i[1]} not found in the database") update_data['is_verified'] = False diff --git a/frontend/src/components/packageItem.js b/frontend/src/components/packageItem.js index bd3c619a..9298853e 100644 --- a/frontend/src/components/packageItem.js +++ b/frontend/src/components/packageItem.js @@ -56,10 +56,10 @@ const PackageItem = ({ packageEntity }) => {
- Namespace {packageEntity.namespace} + Namespace {packageEntity.namespace_name}