Skip to content

Commit

Permalink
Fix: more rebase issues
Browse files Browse the repository at this point in the history
  • Loading branch information
john681611 committed Nov 5, 2023
1 parent 6a7e18c commit c20e137
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 34 deletions.
42 changes: 21 additions & 21 deletions application/frontend/src/pages/Standard/StandardSection.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import './standard.scss';

import axios from 'axios';
import React, { useEffect, useMemo, useState } from 'react';
import { useQuery } from 'react-query';
import { useParams } from 'react-router-dom';
import { Pagination } from 'semantic-ui-react';

import { DocumentNode } from '../../components/DocumentNode';
import { LoadingAndErrorIndicator } from '../../components/LoadingAndErrorIndicator';
import { DOCUMENT_TYPES, DOCUMENT_TYPE_NAMES, TOOL } from '../../const';
import { useEnvironment } from '../../hooks';
import { Document, PaginatedResponse } from '../../types';
import { Document } from '../../types';
import { getDocumentDisplayName, groupLinksByType } from '../../utils';
import { getDocumentTypeText } from '../../utils/document';

Expand All @@ -18,36 +18,36 @@ export const StandardSection = () => {
const { apiUrl } = useEnvironment();
const [page, setPage] = useState<number>(1);
const [loading, setLoading] = useState<boolean>(false);
const [error, setError] = useState<string | Object | null>(null);
const [data, setData] = useState<PaginatedResponse | null>();

const getSectionParameter = (): string => {
return section ? `&section=${encodeURIComponent(section)}` : '';
};
const getSectionIDParameter = (): string => {
return sectionID ? `&sectionID=${encodeURIComponent(sectionID)}` : '';
};
const { error, data, refetch } = useQuery<
{ standards: Document[]; total_pages: number; page: number },
string
>(
'standard section',
() =>
fetch(`${apiUrl}/standard/${id}?page=${page}${getSectionParameter()}${getSectionIDParameter()}`).then(
(res) => res.json()
),
{
retry: false,
enabled: false,
onSettled: () => {
setLoading(false);
},
}
);

useEffect(() => {
window.scrollTo(0, 0);
setLoading(true);
axios
.get(`${apiUrl}/standard/${id}?page=${page}${getSectionParameter()}${getSectionIDParameter()}`)
.then(function (response) {
setError(null);
setData(response.data);
})
.catch(function (axiosError) {
if (axiosError.response.status === 404) {
setError('Standard does not exist in the DB, please check your search parameters');
} else {
setError(axiosError.response);
}
})
.finally(() => {
setLoading(false);
});
}, [id, section, sectionID, page]);
refetch();
}, [page, id]);

const documents = data?.standards || [];
const document = documents[0];
Expand Down
28 changes: 15 additions & 13 deletions application/web/web_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ def find_cre(creid: str = None, crename: str = None) -> Any: # refer
result = {"data": json.loads(oscal_utils.document_to_oscal(cre))}

return jsonify(result)
abort(404, "CRE does not exist")
abort(404)


@app.route("/rest/v1/<ntype>/<name>", methods=["GET"])
@app.route("/rest/v1/standard/<name>", methods=["GET"])
# @cache.cached(timeout=50)
def find_node_by_name(name: str, ntype: str = defs.Credoctypes.Standard.value) -> Any:
database = db.Node_collection()
opt_section = request.args.get("section")
Expand Down Expand Up @@ -189,7 +190,7 @@ def find_node_by_name(name: str, ntype: str = defs.Credoctypes.Standard.value) -

return jsonify(result)
else:
abort(404, "Node does not exist")
abort(404)


# TODO: (spyros) paginate
Expand All @@ -215,7 +216,7 @@ def find_document_by_tag() -> Any:

return jsonify(result)
logger.info("tags aborting 404")
abort(404, "Tag does not exist")
abort(404)


@app.route("/rest/v1/map_analysis", methods=["GET"])
Expand Down Expand Up @@ -360,6 +361,7 @@ def standards() -> Any:


@app.route("/rest/v1/text_search", methods=["GET"])
# @cache.cached(timeout=50)
def text_search() -> Any:
"""
Performs arbitrary text search among all known documents.
Expand Down Expand Up @@ -388,7 +390,7 @@ def text_search() -> Any:
res = [doc.todict() for doc in documents]
return jsonify(res)
else:
abort(404, "No object matches the given search terms")
abort(404)


@app.route("/rest/v1/root_cres", methods=["GET"])
Expand All @@ -415,19 +417,18 @@ def find_root_cres() -> Any:
return jsonify(json.loads(oscal_utils.list_to_oscal(documents)))

return jsonify(result)
abort(404, "No root CREs")
abort(404)


@app.errorhandler(404)
def page_not_found(e) -> Any:
from pprint import pprint

return "Resource Not found", 404


# If no other routes are matched, serve the react app, or any other static files (like bundle.js)
@app.route("/", defaults={"path": ""})
@app.route("/<path:path>")
# @cache.cached(timeout=50)
def index(path: str) -> Any:
print(1)
if path != "" and os.path.exists(app.static_folder + "/" + path):
Expand All @@ -437,17 +438,18 @@ def index(path: str) -> Any:


@app.route("/smartlink/<ntype>/<name>/<section>", methods=["GET"])
# @cache.cached(timeout=50)
def smartlink(
name: str, ntype: str = defs.Credoctypes.Standard.value, section: str = ""
) -> Any:
"""if node is found, show node, else redirect"""
# ATTENTION: DO NOT MESS WITH THIS FUNCTIONALITY WITHOUT A TICKET AND CORE CONTRIBUTORS APPROVAL!
# CRITICAL FUNCTIONALITY DEPENDS ON THIS!
database = db.Node_collection()
opt_version = request.args.get("version")
# match ntype to the credoctypes case-insensitive
typ = [t.value for t in defs.Credoctypes if t.value.lower() == ntype.lower()]
doctype = None if not typ else typ[0]
typ = [t for t in defs.Credoctypes if t.value.lower() == ntype.lower()]
doctype = None
if typ:
doctype = typ[0]

page = 1
items_per_page = 1
Expand Down Expand Up @@ -478,7 +480,7 @@ def smartlink(
if found_section_id:
return redirect(f"/node/{ntype}/{name}/sectionid/{section}")
return redirect(f"/node/{ntype}/{name}/section/{section}")
elif doctype == defs.Credoctypes.Standard.value and redirectors.redirect(
elif ntype == defs.Credoctypes.Standard.value and redirectors.redirect(
name, section
):
logger.info(
Expand All @@ -487,7 +489,7 @@ def smartlink(
return redirect(redirectors.redirect(name, section))
else:
logger.info(f"not sure what happened, 404")
return abort(404, "Document does not exist")
return abort(404)


@app.before_request
Expand Down

0 comments on commit c20e137

Please sign in to comment.