Skip to content

Commit

Permalink
chg: [website] Various improvements to the API documentation and to t…
Browse files Browse the repository at this point in the history
…he documentation blueprint.
  • Loading branch information
cedricbonhomme committed Nov 25, 2024
1 parent d018dc5 commit f9a03fb
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 10 deletions.
5 changes: 4 additions & 1 deletion website/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ def generate_apikey(self) -> str:
self.apikey = generate_token()
return self.apikey

def __repr__(self) -> str:
return "<User %r>" % (self.uuid)

def __str__(self) -> str:
return str(self.uuid)
return f"UUID: {self.uuid}\nLogin: {self.login}\nEmail: {self.email}"

@validates("login")
def validates_login(self, key: str, value: str) -> str:
Expand Down
1 change: 0 additions & 1 deletion website/web/api/v1/sighting.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def get(self, sighting_uuid: str) -> Tuple[dict[Any, Any], int]:
return result, 200


@sighting_ns.route("/sighting")
@sighting_ns.route("/sighting/")
class SightingsList(Resource): # type: ignore[misc]
@sighting_ns.doc("list_sightings") # type: ignore[misc]
Expand Down
2 changes: 0 additions & 2 deletions website/web/api/v1/vulnerability.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from flask_login import current_user # type: ignore[import-untyped]
from flask import request
from flask_restx import abort # type: ignore[import-untyped]
from flask_restx import fields
from flask_restx import Namespace
from flask_restx import reqparse
from flask_restx import Resource
Expand All @@ -19,7 +18,6 @@
from vulnerabilitylookup.helpers import fromisoformat_wrapper
from website.validators import validate_json
from website.web.api.v1.common import auth_func
from website.web.bootstrap import application
from website.web.bootstrap import vulnerabilitylookup
from website.web.permissions import reporter_permission, admin_permission

Expand Down
2 changes: 1 addition & 1 deletion website/web/templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ <h3>Formats</h3>
<h5 id="documentation" class="mb-0">Documentation</h5>
</div>
<div class="card-body">
<p>You can read the <a href="https://vulnerability.circl.lu/documentation" rel="noreferrer" target="_blank">documentation</a> as well as the <a href="{{ url_for('apiv1.doc') }}">documentation dedicated to the API</a>.</p>
<p>You can read the <a href="https://vulnerability.circl.lu/documentation" rel="noreferrer" target="_blank">official documentation</a> as well as the <a href="{{ url_for('apiv1.doc') }}">documentation dedicated to the API</a>.</p>
<p>Found a bug? Report it <a href="https://github.com/cve-search/vulnerability-lookup/issues" rel="noreferrer" target="_blank">here</a>.</p>
<p>
This software is under AGPLv3 license. You are welcome to copy, modify or
Expand Down
2 changes: 1 addition & 1 deletion website/web/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ <h5 class="modal-title" id="dynamicConfirmModalLabel"></h5>
{% if config.user_accounts %}
<a class="text-end" href="{{ url_for('users_bp.list_users') }}">Contributors</a>&nbsp;&nbsp;
{% endif %}
<a class="text-end" href="https://vulnerability.circl.lu/documentation" target="_blank">Documentation</a>&nbsp;&nbsp;
<a class="text-end" href="{{ url_for('documentation_bp.serve_index') }}">Documentation</a>&nbsp;&nbsp;
<a class="text-end" href="{{ url_for('apiv1.doc') }}">API</a>&nbsp;&nbsp;
<a class="text-end" href="{{ url_for('home_bp.about') }}">About</a>&nbsp;&nbsp;
</div>
Expand Down
25 changes: 22 additions & 3 deletions website/web/views/documentation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env python3

from flask import abort
from flask import flash
from flask import Blueprint
from flask import send_from_directory
from markupsafe import Markup
from werkzeug import Response as WerkzeugResponse

from vulnerabilitylookup.default import get_homedir
Expand All @@ -11,21 +13,38 @@
homedir = get_homedir()
static_folder = homedir.joinpath("docs/_build/html")
documentation_bp = Blueprint(
"documentation", __name__, url_prefix="/documentation", static_folder=static_folder
"documentation_bp",
__name__,
url_prefix="/documentation",
static_folder=static_folder,
)


@documentation_bp.route("/<path:filename>")
def serve_documentation(filename: str) -> WerkzeugResponse:
"""Serve static files from the Sphinx build folder."""
if None is documentation_bp.static_folder:
if not static_folder.exists() or not documentation_bp.static_folder:
flash(
Markup(
"The documentation has yet to be generated. "
"See the <a href='https://vulnerability.circl.lu/documentation/command-line-interface.html' target='_blank'>official documentation</a>."
),
"warning",
)
return abort(404)
return send_from_directory(documentation_bp.static_folder, filename)


@documentation_bp.route("/")
def serve_index() -> WerkzeugResponse:
"""Redirect `/documentation` to `/documentation/index.html`"""
if None is documentation_bp.static_folder:
if not static_folder.exists() or not documentation_bp.static_folder:
flash(
Markup(
"The documentation has yet to be generated. "
"See the <a href='https://vulnerability.circl.lu/documentation/command-line-interface.html' target='_blank'>official documentation</a>."
),
"warning",
)
return abort(404)
return send_from_directory(documentation_bp.static_folder, "index.html")
2 changes: 1 addition & 1 deletion website/web/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
make_response,
Response,
)
from markupsafe import escape, Markup
from markupsafe import Markup
from flask_paginate import get_page_args # type: ignore[import-untyped]
from sqlalchemy import String, cast, func

Expand Down

0 comments on commit f9a03fb

Please sign in to comment.