Skip to content

Commit

Permalink
Merge pull request fortran-lang#78 from henilp105/main
Browse files Browse the repository at this point in the history
fix: bugs detected in current release
  • Loading branch information
henilp105 authored Apr 11, 2024
2 parents 702c7be + aecb741 commit 2d08417
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 63 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/security_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ jobs:

- uses: fortran-lang/setup-fpm@v5
with:
fpm-version: 'v0.10.1'
github-token: ${{ secrets.GITHUB_TOKEN }}
fpm-version: 'v0.10.2'
github-token: ${{ secrets.GITHUB_TOKEN }}
fpm-repository: https://github.com/henilp105/fpm

- name: Setup Python
uses: actions/setup-python@v5
Expand Down
2 changes: 1 addition & 1 deletion backend/models/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def __init__(self, namespace, description, author, maintainers=[], admins=[], pa
self.author = author
self.maintainers = maintainers
self.admins = admins
self.packages = []
self.packages = packages

# Create a to_json method.
def to_json(self):
Expand Down
34 changes: 2 additions & 32 deletions backend/namespaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def namespace_packages(namespace):
"name": 1,
"description": 1,
"author": 1,
"updatedAt": 1,
"updated_at": 1,
},
)

Expand All @@ -185,7 +185,7 @@ def namespace_packages(namespace):
"name": package["name"],
"description": package["description"],
"author": author_obj.username,
"updatedAt": package["updatedAt"],
"updated_at": package["updated_at"],
})

return (
Expand All @@ -201,30 +201,14 @@ def namespace_packages(namespace):

@app.route("/namespaces/<namespace>/admins", methods=["POST"])
@swag_from("documentation/get_namespace_admins.yaml", methods=["POST"])
@jwt_required()
def namespace_admins(namespace):
uuid = get_jwt_identity()

if not uuid:
return jsonify({"code": 401, "message": "Unauthorized"}), 401

user = db.users.find_one({"uuid": uuid})

if not user:
return jsonify({"code": 404, "message": "User not found"}), 404

user_obj = User.from_json(user)

namespace_doc = db.namespaces.find_one({"namespace": namespace})

if not namespace_doc:
return jsonify({"code": 404, "message": "Namespace not found"}), 404

namespace_obj = Namespace.from_json(namespace_doc)

if not user_obj.id in namespace_obj.admins and not user_obj.id in namespace_obj.maintainers:
return jsonify({"code": 401, "message": "Unauthorized"}), 401

admins = []

for i in namespace_obj.admins:
Expand All @@ -239,28 +223,14 @@ def namespace_admins(namespace):

@app.route("/namespaces/<namespace>/maintainers", methods=["POST"])
@swag_from("documentation/get_namespace_maintainers.yaml", methods=["POST"])
@jwt_required()
def namespace_maintainers(namespace):
uuid = get_jwt_identity()

if not uuid:
return jsonify({"code": 401, "message": "Unauthorized"}), 401

user = db.users.find_one({"uuid": uuid})

if not user:
return jsonify({"code": 404, "message": "User not found"}), 404

namespace_doc = db.namespaces.find_one({"namespace": namespace})

if not namespace_doc:
return jsonify({"code": 404, "message": "Namespace not found"}), 404

namespace_obj = Namespace.from_json(namespace_doc)
user_obj = User.from_json(user)

if not user_obj.id in namespace_obj.admins and not user_obj.id in namespace_obj.maintainers:
return jsonify({"code": 401, "message": "Unauthorized"}), 401

maintainers = []

Expand Down
13 changes: 2 additions & 11 deletions backend/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,18 +837,9 @@ def create_token_upload_token_package(namespace_name, package_name):
)


@app.route("/packages/<namespace>/<package>/maintainers", methods=["GET"])
@swag_from("documentation/package_maintainers.yaml", methods=["GET"])
@jwt_required()
@app.route("/packages/<namespace>/<package>/maintainers", methods=["GET","POST"])
@swag_from("documentation/package_maintainers.yaml", methods=["GET","POST"])
def package_maintainers(namespace, package):
uuid = get_jwt_identity()

user = db.users.find_one({"uuid": uuid})

if not user:
return jsonify({"code": 401, "message": "Unauthorized"}), 401

user_obj = User.from_json(user)

namespace_doc = db.namespaces.find_one({"namespace": namespace})

Expand Down
3 changes: 2 additions & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ semantic-version
docker
toml
flask-jwt-extended
numpy
numpy
markdown
28 changes: 18 additions & 10 deletions backend/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def profile(username):
"name": package_doc["name"],
"namespace": namespace["namespace"],
"description": package_doc["description"],
"updatedAt": package_doc["updated_at"],
"updated_at": package_doc["updated_at"],
"isNamespaceMaintainer": isNamespaceMaintainer,
"isNamespaceAdmin": isNamespaceAdmin,
"isPackageMaintainer": isPackageMaintainer,
Expand Down Expand Up @@ -119,7 +119,7 @@ def profile(username):
"name": package["name"],
"namespace": namespace["namespace"],
"description": package["description"],
"updatedAt": package["updated_at"],
"updated_at": package["updated_at"],
"isNamespaceMaintainer": isNamespaceMaintainer,
"isPackageMaintainer": isPackageMaintainer,
}
Expand Down Expand Up @@ -149,8 +149,9 @@ def profile(username):

@app.route("/users/delete", methods=["POST"])
@swag_from("documentation/delete_user.yaml", methods=["POST"])
@jwt_required()
def delete_user():
uuid = request.form.get("uuid")
uuid = get_jwt_identity()
username = request.form.get("username")

if not uuid:
Expand All @@ -173,8 +174,9 @@ def delete_user():

@app.route("/users/account", methods=["POST"])
@swag_from("documentation/get_user_account.yaml", methods=["POST"])
@jwt_required()
def account():
uuid = request.form.get("uuid")
uuid = get_jwt_identity()
if not uuid:
return jsonify({"message": "Unauthorized", "code": 401}), 401
else:
Expand Down Expand Up @@ -263,8 +265,9 @@ def transfer_account():

@app.route("/<username>/maintainer", methods=["POST"])
@swag_from("documentation/add_package_maintainer.yaml", methods=["POST"])
@jwt_required()
def add_maintainers_to_package(username):
uuid = request.form.get("uuid")
uuid = get_jwt_identity()
username_to_be_added = request.form.get("username")
package = request.form.get("package")
namespace = request.form.get("namespace")
Expand Down Expand Up @@ -344,8 +347,9 @@ def add_maintainers_to_package(username):

@app.route("/<username>/maintainer/remove", methods=["POST"])
@swag_from("documentation/remove_package_maintainer.yaml", methods=["POST"])
@jwt_required()
def remove_maintainers_from_package(username):
uuid = request.form.get("uuid")
uuid = get_jwt_identity()
username_to_be_removed = request.form.get("username")
package = request.form.get("package")
namespace = request.form.get("namespace")
Expand Down Expand Up @@ -430,8 +434,9 @@ def remove_maintainers_from_package(username):

@app.route("/<username>/namespace/maintainer", methods=["POST"])
@swag_from("documentation/add_namespace_maintainer.yaml", methods=["POST"])
@jwt_required()
def add_maintainers_to_namespace(username):
uuid = request.form.get("uuid")
uuid = get_jwt_identity()
username_to_be_added = request.form.get("username")
namespace = request.form.get("namespace")

Expand Down Expand Up @@ -499,8 +504,9 @@ def add_maintainers_to_namespace(username):

@app.route("/<username>/namespace/maintainer/remove", methods=["POST"])
@swag_from("documentation/remove_namespace_maintainer.yaml", methods=["POST"])
@jwt_required()
def remove_maintainers_from_namespace(username):
uuid = request.form.get("uuid")
uuid = get_jwt_identity()
username_to_be_removed = request.form.get("username")
namespace = request.form.get("namespace")

Expand Down Expand Up @@ -575,8 +581,9 @@ def remove_maintainers_from_namespace(username):

@app.route("/<username>/namespace/admin", methods=["POST"])
@swag_from("documentation/add_namespace_admin.yaml", methods=["POST"])
@jwt_required()
def add_admins_to_namespace(username):
uuid = request.form.get("uuid")
uuid = get_jwt_identity()
username_to_be_added = request.form.get("username")
namespace = request.form.get("namespace")

Expand Down Expand Up @@ -639,8 +646,9 @@ def add_admins_to_namespace(username):

@app.route("/<username>/namespace/admin/remove", methods=["POST"])
@swag_from("documentation/remove_namespace_admin.yaml", methods=["POST"])
@jwt_required()
def remove_admins_from_namespace(username):
uuid = request.form.get("uuid")
uuid = get_jwt_identity()
username_to_be_removed = request.form.get("username")
namespace = request.form.get("namespace")

Expand Down
9 changes: 9 additions & 0 deletions backend/validate.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from app import app
import subprocess
import toml
import html
from mongo import db
from mongo import file_storage
from bson.objectid import ObjectId
from gridfs.errors import NoFile
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]:
Expand Down Expand Up @@ -82,6 +84,13 @@ def process_package(packagename: str) -> Tuple[bool, Union[dict, None], str]:
cleanup_command = f'rm -rf static/temp/{packagename} static/temp/{packagename}.tar.gz'
# 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
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/components/packageItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ const PackageItem = ({ packageEntity }) => {
</Link>

<h6 className="mb-2 text-muted">
Namespace {packageEntity.namespace}
<a
href={`/namespaces/${packageEntity.namespace}`}
style={{ textDecoration: "none" }}
>
Namespace {packageEntity.namespace}
</a>
</h6>
<label className="mb-2 text-muted" style={{ fontSize: "18px" }}>
{packageEntity.description}
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/pages/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ const NamespacePage = () => {
<Row
style={{ marginLeft: "10px", marginTop: "10px", fontSize: "20px" }}
>
<MDBIcon style={{ marginTop: "5px" }} fas icon="box">
<MDBIcon style={{ marginTop: "5px" }} far icon="box">
{" Namespace: " + namespace}
</MDBIcon>
<br></br>
<MDBIcon style={{ marginTop: "5px" }} far icon="calendar-alt">
{" Created " + dateJoined.slice(4, 16)}
</MDBIcon>
Expand All @@ -68,7 +69,7 @@ const NamespacePage = () => {
>
<MDBIcon
style={{ marginTop: "5px" }}
fas
far
icon="user"
onClick={() => {
setFindNamespaceMaintainers(false);
Expand All @@ -90,7 +91,7 @@ const NamespacePage = () => {
>
<MDBIcon
style={{ marginTop: "5px" }}
fas
far
icon="user"
onClick={() => {
setFindNamespaceMaintainers(true);
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/pages/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ const PackagePage = () => {
justifyContent: "space-between",
}}
>
<p style={{ textAlign: "left", fontSize: 24 }}>{data.name}</p>
<p style={{ textAlign: "left", fontSize: 24 }}><a
href={`/namespaces/${data.namespace}`}
style={{ textDecoration: "none" }}
>
{data.namespace}
</a>
/{data.name}</p>

<ViewPackageMaintainersButton
namespace_name={namespace_name}
Expand Down
8 changes: 7 additions & 1 deletion frontend/src/pages/showUserListDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ const ShowUserListDialog = (props) => {
marginBottom: "0",
}}
>
{user.username}

<a
href={`/users/${user.username}`}
style={{ textDecoration: "none" }}
>
{user.username}
</a>
</h6>
</Card.Body>
</Card>
Expand Down

0 comments on commit 2d08417

Please sign in to comment.