mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
Added Routes to BCF (#1644)
This commit is contained in:
+10
-9
@@ -4,10 +4,10 @@ A simple Python implementation of BCF. The data model is described in `data.py`.
|
||||
Manipulation of BCF-XML is available via `bcfxml.py` and manipulation of BCF-API
|
||||
is available via `bcfapi.py`.
|
||||
|
||||
- BCF-XML version 2.1: Fully supported
|
||||
- BCF-API version 2.1: Not supported, will probably tackle this after BCF-API v3.0
|
||||
- BCF-XML version 3.0: Almost fully supported, except for the documents module
|
||||
- BCF-API version 3.0: Almost fully supported, except for two requests.
|
||||
- BCF-XML version 2.1: Fully supported
|
||||
- BCF-API version 2.1: Not supported, will probably tackle this after BCF-API v3.0
|
||||
- BCF-XML version 3.0: Almost fully supported, except for the documents module
|
||||
- BCF-API version 3.0: Almost fully supported, except for two requests.
|
||||
|
||||
## bcfxml
|
||||
|
||||
@@ -73,9 +73,9 @@ auth_methods = foundation_client.get_auth_methods()
|
||||
|
||||
# Our library currently only implements the authorization_code flow
|
||||
if "authorization_code" in auth_methods:
|
||||
auth_client.login()
|
||||
foundation_client.login()
|
||||
|
||||
bcf_client = BcfClient()
|
||||
bcf_client = BcfClient(foundation_client)
|
||||
|
||||
versions = foundation_client.get_versions()
|
||||
for version in versions:
|
||||
@@ -94,7 +94,8 @@ print(data)
|
||||
```
|
||||
|
||||
## Todo List
|
||||
The remaining work that needs to be completed in `bcfxml.py` and `bcfapi.py`.
|
||||
* For `bcfxml.py` two xsds support is remaining namely 'documents.xsd` and `extensions.xsd`.
|
||||
* For `bcfapi.py` two requests that are `get_topics` and `get_comments` are remaining.
|
||||
|
||||
The remaining work that needs to be completed in `bcfxml.py` and `bcfapi.py`.
|
||||
|
||||
- For `bcfxml.py` two xsds support is remaining namely 'documents.xsd`and`extensions.xsd`.
|
||||
- For `bcfapi.py` two requests that are `get_topics` and `get_comments` are remaining.
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
from flask import jsonify, url_for, redirect, render_template, request, session, flash
|
||||
from flask_login import login_user, logout_user, login_required, current_user
|
||||
from flask.blueprints import Blueprint
|
||||
from website.models import User, OAuth2AuthorizationCode, OAuth2Token, OAuth2Client
|
||||
from run import app, db
|
||||
import json
|
||||
|
||||
bcf = Blueprint("bcf", __name__, template_folder="templates", url_prefix="/bcf/3.0")
|
||||
|
||||
|
||||
@bcf.route("/projects")
|
||||
def projects():
|
||||
Headers = str.split(request.headers["Authorization"])
|
||||
token = Headers[1]
|
||||
access_token = OAuth2Token.query.filter_by(access_token=token).first()
|
||||
print(access_token)
|
||||
if access_token:
|
||||
Body = {
|
||||
"project_id": "F445F4F2-4D02-4B2A-B612-5E456BEF9137",
|
||||
"name": "Example project 1",
|
||||
"authorization": {"project_actions": ["createTopic", "createDocument"]},
|
||||
}, {
|
||||
"project_id": "A233FBB2-3A3B-EFF4-C123-DE22ABC8414",
|
||||
"name": "Example project 2",
|
||||
"authorization": {"project_actions": []},
|
||||
}
|
||||
response = app.response_class(
|
||||
response=json.dumps(Body),
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
else:
|
||||
message = {"error": "User not recognized"}
|
||||
response = app.response_class(
|
||||
response=jsonify(message),
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/")
|
||||
@login_required
|
||||
def bcf_3():
|
||||
return "<h1>BCF HOMPAGE</h1>"
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>")
|
||||
def project_details(project_id):
|
||||
return "Project details"
|
||||
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"Projects":[{
|
||||
"project_id": "F445F4F2-4D02-4B2A-B612-5E456BEF9137",
|
||||
"name": "Example project 1",
|
||||
"authorization": {
|
||||
"project_actions": [
|
||||
"createTopic",
|
||||
"createDocument"
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"project_id": "A233FBB2-3A3B-EFF4-C123-DE22ABC8414",
|
||||
"name": "Example project 2",
|
||||
"authorization": {
|
||||
"project_actions": []
|
||||
}
|
||||
}],
|
||||
"Extensions":[{
|
||||
"topic_type": [
|
||||
"Information",
|
||||
"Error"
|
||||
],
|
||||
"topic_status": [
|
||||
"Open",
|
||||
"Closed",
|
||||
"ReOpened"
|
||||
],
|
||||
"topic_label": [
|
||||
"Architecture",
|
||||
"Structural",
|
||||
"MEP"
|
||||
],
|
||||
"snippet_type": [
|
||||
".ifc",
|
||||
".csv"
|
||||
],
|
||||
"priority": [
|
||||
"Low",
|
||||
"Medium",
|
||||
"High"
|
||||
],
|
||||
"users": [
|
||||
"Architect@example.com",
|
||||
"BIM-Manager@example.com",
|
||||
"bob_heater@example.com"
|
||||
],
|
||||
"stage": [
|
||||
"Preliminary Planning End",
|
||||
"Construction Start",
|
||||
"Construction End"
|
||||
],
|
||||
"project_actions": [
|
||||
"update",
|
||||
"createTopic",
|
||||
"createDocument"
|
||||
],
|
||||
"topic_actions": [
|
||||
"update",
|
||||
"updateBimSnippet",
|
||||
"updateRelatedTopics",
|
||||
"updateDocumentReferences",
|
||||
"updateFiles",
|
||||
"createComment",
|
||||
"createViewpoint"
|
||||
],
|
||||
"comment_actions": [
|
||||
"update"
|
||||
]
|
||||
}]
|
||||
}
|
||||
@@ -0,0 +1,733 @@
|
||||
from operator import methodcaller
|
||||
from flask import jsonify, url_for, redirect, render_template, request, session, flash
|
||||
from flask_login import login_user, logout_user, login_required, current_user
|
||||
from flask.blueprints import Blueprint
|
||||
from foundation.models import User, OAuth2AuthorizationCode, OAuth2Token, OAuth2Client
|
||||
from run import app, db
|
||||
import json
|
||||
import os
|
||||
|
||||
bcf = Blueprint("bcf", __name__, template_folder="templates", url_prefix="/bcf/3.0")
|
||||
my_absolute_dirpath = os.path.abspath(os.path.dirname(__file__))
|
||||
data = open(
|
||||
f"{my_absolute_dirpath}/project.json",
|
||||
)
|
||||
jdata = json.load(data)
|
||||
|
||||
|
||||
def validate_client(request):
|
||||
Headers = str.split(request.headers["Authorization"])
|
||||
token = Headers[1]
|
||||
access_token = OAuth2Token.query.filter_by(access_token=token).first()
|
||||
if access_token:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def invalid_user():
|
||||
message = {"error": "User not recognized"}
|
||||
response = app.response_class(
|
||||
response=json.dumps(message),
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
def invalid_project():
|
||||
message = {"error": "Project not found"}
|
||||
response = app.response_class(
|
||||
response=json.dumps(message),
|
||||
status=400,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects")
|
||||
def projects():
|
||||
access_token = validate_client(request)
|
||||
if access_token:
|
||||
response = app.response_class(
|
||||
response=jdata["Projects"],
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/")
|
||||
@login_required
|
||||
def bcf_3():
|
||||
return "<h1>BCF HOMPAGE</h1>"
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>")
|
||||
def project_details(project_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token:
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
response = app.response_class(
|
||||
response=i,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>", methods=["PUT"])
|
||||
def update_project(project_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "PUT":
|
||||
data = request.form["data"]
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
response = app.response_class(
|
||||
response=data,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/extensions")
|
||||
def extensions(project_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token:
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
response = app.response_class(
|
||||
response=jdata["Extensions"],
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.routes("/projects/<project_id>/topics")
|
||||
def topics(project_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token:
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
response = app.response_class(
|
||||
response=jdata["Topics"],
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.routes("/projects/<project_id>/topics/<topic_id>", methods=["POST"])
|
||||
def topic_details(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "POST":
|
||||
body = request.form["data"]
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=body,
|
||||
status=201,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.routes("/projects/<project_id>/topics/<topic_id>")
|
||||
def topic_details(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token:
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=j,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/topics/<topic_id>", methods=["PUT"])
|
||||
def update_topic(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "PUT":
|
||||
data = request.form["data"]
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=data,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/topics/<topic_id>", methods=["DELETE"])
|
||||
def delete_topic(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "DELETE":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
message = {"DELETED"}
|
||||
response = app.response_class(
|
||||
response=json.dumps(message),
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/topics/<topic_id>/snippet", methods=["GET"])
|
||||
def get_snippet(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "GET":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=json.dumps("Snippet test successfull"),
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/topics/<topic_id>/snippet", methods=["PUT"])
|
||||
def update_snippet(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "PUT":
|
||||
data = request.form["data"]
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=data,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/files_information", methods=["GET"])
|
||||
def get_files_information(project_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "GET":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
response = app.response_class(
|
||||
response=jdata["Files"],
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/topics/<topic_id>/files", methods=["GET"])
|
||||
def get_files(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "GET":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=json.dumps("Get request for files successfull"),
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/topics/<topic_id>/files", methods=["PUT"])
|
||||
def update_files(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "PUT":
|
||||
data = request.form["data"]
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=data,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/topics/<topic_id>/comments", methods=["GET"])
|
||||
def get_comments(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "GET":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=jdata["Comments"],
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/topics/<topic_id>/comments", methods=["POST"])
|
||||
def create_comments(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "POST":
|
||||
data = request.form["data"]
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=data,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route(
|
||||
"/projects/<project_id>/topics/<topic_id>/comments/<comment_id>", methods=["GET"]
|
||||
)
|
||||
def get_comment(project_id, topic_id, comment_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "GET":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
for k in jdata["Comments"]:
|
||||
if (k["guid"]) == comment_id:
|
||||
response = app.response_class(
|
||||
response=k,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route(
|
||||
"/projects/<project_id>/topics/<topic_id>/comments/<comment_id>", methods=["PUT"]
|
||||
)
|
||||
def update_comment(project_id, topic_id, comment_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "PUT":
|
||||
data = request.form["data"]
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
for k in jdata["Comments"]:
|
||||
if (k["guid"]) == comment_id:
|
||||
response = app.response_class(
|
||||
response=data,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route(
|
||||
"/projects/<project_id>/topics/<topic_id>/comments/<comment_id>", methods=["DELETE"]
|
||||
)
|
||||
def delete_comment(project_id, topic_id, comment_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "DELETE":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
for k in jdata["Comments"]:
|
||||
if (k["guid"]) == comment_id:
|
||||
message = {"DELETED"}
|
||||
response = app.response_class(
|
||||
response=json.dumps(message),
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
"""
|
||||
***Add ViewPoints Routes Here ***
|
||||
"""
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/topics/<topic_id>/related_topics", methods=["GET"])
|
||||
def get_related_topics(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "GET":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=jdata["RelatedTopics"],
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/topics/<topic_id>/related_topics", methods=["PUT"])
|
||||
def update_related_topics(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "PUT":
|
||||
data = request.form["data"]
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=data,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route(
|
||||
"/projects/<project_id>/topics/<topic_id>/document_references", methods=["GET"]
|
||||
)
|
||||
def get_document_references(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "GET":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=jdata["DocumentReferences"],
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route(
|
||||
"/projects/<project_id>/topics/<topic_id>/document_references", methods=["POST"]
|
||||
)
|
||||
def create_document_references(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "POST":
|
||||
data = request.form["data"]
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=data,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route(
|
||||
"/projects/<project_id>/topics/<topic_id>/document_references/<document_reference_id>",
|
||||
methods=["PUT"],
|
||||
)
|
||||
def update_document_references(project_id, topic_id, document_reference_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "PUT":
|
||||
data = request.form["data"]
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
for k in jdata["DocumentReferences"]:
|
||||
if (k["guid"]) == document_reference_id:
|
||||
response = app.response_class(
|
||||
response=data,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/topics/<topic_id>/documents", methods=["GET"])
|
||||
def get_documents(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "GET":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=jdata["Documents"],
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.routes("/projects/<project_id>/topics/<topic_id>/documents", methods=["POST"])
|
||||
def create_documents(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "POST":
|
||||
data = request.form["data"]
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=data,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route(
|
||||
"/projects/<project_id>/topics/<topic_id>/documents/<document_id>", methods=["GET"]
|
||||
)
|
||||
def get_document(project_id, topic_id, document_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "GET":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
for k in jdata["Documents"]:
|
||||
if (k["guid"]) == document_id:
|
||||
response = app.response_class(
|
||||
response=k,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/topics/events", methods=["GET"])
|
||||
def get_events(project_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "GET":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
response = app.response_class(
|
||||
response=jdata["Events"],
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/topics/<topic_id>/events", methods=["GET"])
|
||||
def get_topic_events(project_id, topic_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "GET":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
for k in jdata["Events"]:
|
||||
if (k["topic_guid"]) == topic_id:
|
||||
response = app.response_class(
|
||||
response=k,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route("/projects/<project_id>/topics/comments/events", methods=["GET"])
|
||||
def get_comments_events(project_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "GET":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
response = app.response_class(
|
||||
response=jdata["EventComments"],
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
|
||||
|
||||
@bcf.route(
|
||||
"/projects/<project_id>/topics/<topic_id>/comments/<comment_id>/events",
|
||||
methods=["GET"],
|
||||
)
|
||||
def get_comment_events(project_id, topic_id, comment_id):
|
||||
access_token = validate_client(request)
|
||||
if access_token and request.method == "GET":
|
||||
for i in jdata["Projects"]:
|
||||
if (i["project_id"]) == project_id:
|
||||
for j in jdata["Topics"]:
|
||||
if (j["guid"]) == topic_id:
|
||||
for k in jdata["EventComments"]:
|
||||
if (k["comment_guid"]) == comment_id:
|
||||
response = app.response_class(
|
||||
response=k,
|
||||
status=200,
|
||||
mimetype="application/json",
|
||||
)
|
||||
return response
|
||||
response = invalid_project()
|
||||
return response
|
||||
else:
|
||||
response = invalid_user()
|
||||
return response
|
||||
+17
-17
@@ -11,8 +11,8 @@ import urllib
|
||||
import json
|
||||
from run import db, app
|
||||
|
||||
website_obj = Blueprint(
|
||||
"website_obj",
|
||||
foundation_obj = Blueprint(
|
||||
"foundation_obj",
|
||||
__name__,
|
||||
template_folder="templates",
|
||||
)
|
||||
@@ -22,13 +22,13 @@ def split_by_crlf(s):
|
||||
return [v for v in s.splitlines() if v]
|
||||
|
||||
|
||||
@website_obj.route("/")
|
||||
@foundation_obj.route("/")
|
||||
def homepage():
|
||||
return render_template("index.html")
|
||||
# return "homepage"
|
||||
|
||||
|
||||
@website_obj.route("/register", methods=["GET", "POST"])
|
||||
@foundation_obj.route("/register", methods=["GET", "POST"])
|
||||
def register_page():
|
||||
form = RegisterForm()
|
||||
if form.validate_on_submit():
|
||||
@@ -45,7 +45,7 @@ def register_page():
|
||||
f"Account created successfully! {user_to_create.username}",
|
||||
category="success",
|
||||
)
|
||||
return redirect(url_for("website_obj.homepage"))
|
||||
return redirect(url_for("foundation_obj.homepage"))
|
||||
if form.errors != {}:
|
||||
for err_msg in form.errors.values():
|
||||
flash(
|
||||
@@ -55,7 +55,7 @@ def register_page():
|
||||
return render_template("register.html", form=form)
|
||||
|
||||
|
||||
@website_obj.route("/createclient", methods=["GET", "POST"])
|
||||
@foundation_obj.route("/createclient", methods=["GET", "POST"])
|
||||
@login_required
|
||||
def create_client():
|
||||
grants = [
|
||||
@@ -99,7 +99,7 @@ def create_client():
|
||||
return render_template("createclient.html", form=form, grants=grants)
|
||||
|
||||
|
||||
@website_obj.route("/login", methods=["GET", "POST"])
|
||||
@foundation_obj.route("/login", methods=["GET", "POST"])
|
||||
def login_page():
|
||||
form = LoginForm()
|
||||
if form.validate_on_submit():
|
||||
@@ -108,7 +108,7 @@ def login_page():
|
||||
attempted_password=form.password.data
|
||||
):
|
||||
login_user(attempted_user)
|
||||
return redirect(url_for("website_obj.homepage"))
|
||||
return redirect(url_for("foundation_obj.homepage"))
|
||||
else:
|
||||
flash(
|
||||
"Invalid Credentials",
|
||||
@@ -118,14 +118,14 @@ def login_page():
|
||||
return render_template("login.html", form=form)
|
||||
|
||||
|
||||
@website_obj.route("/logout")
|
||||
@foundation_obj.route("/logout")
|
||||
def logoutpage():
|
||||
logout_user()
|
||||
flash("You have been logged out!", category="info")
|
||||
return redirect(url_for("website_obj.homepage"))
|
||||
return redirect(url_for("foundation_obj.homepage"))
|
||||
|
||||
|
||||
@website_obj.route("/foundation/1.0/auth")
|
||||
@foundation_obj.route("/foundation/1.0/auth")
|
||||
def foundation_auth():
|
||||
data = {
|
||||
"oauth2_auth_url": "http://127.0.0.1:5000/oauth/authorize",
|
||||
@@ -138,7 +138,7 @@ def foundation_auth():
|
||||
return response
|
||||
|
||||
|
||||
@website_obj.route("/foundation/versions")
|
||||
@foundation_obj.route("/foundation/versions")
|
||||
def foundation_versions():
|
||||
Body = {
|
||||
"versions": [
|
||||
@@ -167,7 +167,7 @@ def foundation_versions():
|
||||
return response
|
||||
|
||||
|
||||
@website_obj.route("/outh/login", methods=["GET", "POST"])
|
||||
@foundation_obj.route("/outh/login", methods=["GET", "POST"])
|
||||
def oauth_login():
|
||||
form = LoginForm()
|
||||
if form.validate_on_submit():
|
||||
@@ -185,7 +185,7 @@ def oauth_login():
|
||||
state = request.args.get("state")
|
||||
return redirect(
|
||||
url_for(
|
||||
"website_obj.authorize",
|
||||
"foundation_obj.authorize",
|
||||
client_id=client_id,
|
||||
redirect_uri=redirect_uri,
|
||||
state=state,
|
||||
@@ -199,7 +199,7 @@ def oauth_login():
|
||||
return render_template("ologin.html", form=form)
|
||||
|
||||
|
||||
@website_obj.route("/oauth/authorize", methods=["GET", "POST"])
|
||||
@foundation_obj.route("/oauth/authorize", methods=["GET", "POST"])
|
||||
def authorize():
|
||||
client_id = request.args.get("client_id")
|
||||
redirect_uri = request.args.get("redirect_uri")
|
||||
@@ -209,7 +209,7 @@ def authorize():
|
||||
query = request.query_string
|
||||
return redirect(
|
||||
url_for(
|
||||
"website_obj.oauth_login",
|
||||
"foundation_obj.oauth_login",
|
||||
client_id=client_id,
|
||||
redirect_uri=redirect_uri,
|
||||
state=state,
|
||||
@@ -252,7 +252,7 @@ def authorize():
|
||||
return render_template("oauth.html")
|
||||
|
||||
|
||||
@website_obj.route("/oauth/token", methods=["POST"])
|
||||
@foundation_obj.route("/oauth/token", methods=["POST"])
|
||||
def issue_token():
|
||||
try:
|
||||
code = request.form["code"]
|
||||
+9
-5
@@ -30,7 +30,7 @@
|
||||
<div class="collapse navbar-collapse" id="navbarNav">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
<li class="nav-item active">
|
||||
<a class="nav-link" href="{{ url_for('website_obj.homepage') }}"
|
||||
<a class="nav-link" href="{{ url_for('foundation_obj.homepage') }}"
|
||||
>Home <span class="sr-only">(current)</span></a
|
||||
>
|
||||
</li>
|
||||
@@ -47,14 +47,16 @@
|
||||
<a class="nav-link">Welcome, {{ current_user.username }}</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('website_obj.logoutpage') }}"
|
||||
<a
|
||||
class="nav-link"
|
||||
href="{{ url_for('foundation_obj.logoutpage') }}"
|
||||
>Logout</a
|
||||
>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a
|
||||
class="nav-link"
|
||||
href="{{ url_for('website_obj.create_client') }}"
|
||||
href="{{ url_for('foundation_obj.create_client') }}"
|
||||
>Create Client</a
|
||||
>
|
||||
</li>
|
||||
@@ -62,14 +64,16 @@
|
||||
{% else %}
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('website_obj.login_page') }}"
|
||||
<a
|
||||
class="nav-link"
|
||||
href="{{ url_for('foundation_obj.login_page') }}"
|
||||
>Login</a
|
||||
>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a
|
||||
class="nav-link"
|
||||
href="{{ url_for('website_obj.register_page') }}"
|
||||
href="{{ url_for('foundation_obj.register_page') }}"
|
||||
>Register</a
|
||||
>
|
||||
</li>
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
<h6>Do not have an account?</h6>
|
||||
<a
|
||||
class="btn btn-sm btn-secondary"
|
||||
href="{{ url_for('website_obj.register_page') }}"
|
||||
href="{{ url_for('foundation_obj.register_page') }}"
|
||||
>Register</a
|
||||
>
|
||||
</div>
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
<h6>Do not have an account?</h6>
|
||||
<a
|
||||
class="btn btn-sm btn-secondary"
|
||||
href="{{ url_for('website_obj.register_page') }}"
|
||||
href="{{ url_for('foundation_obj.register_page') }}"
|
||||
>Register</a
|
||||
>
|
||||
</div>
|
||||
+1
-1
@@ -18,7 +18,7 @@
|
||||
<h6>Already have an account?</h6>
|
||||
<a
|
||||
class="btn btn-sm btn-secondary"
|
||||
href="{{ url_for('website_obj.login_page') }}"
|
||||
href="{{ url_for('foundation_obj.login_page') }}"
|
||||
>Login</a
|
||||
>
|
||||
</div>
|
||||
@@ -10,14 +10,14 @@ login_manager = LoginManager(app)
|
||||
bcrypt = Bcrypt(app)
|
||||
app.config["SECRET_KEY"] = "f613729206685405cde0e388"
|
||||
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///sqlite.db"
|
||||
login_manager.login_view = "website_obj.login_page"
|
||||
login_manager.login_view = "foundation_obj.login_page"
|
||||
login_manager.login_message_category = "info"
|
||||
|
||||
from website.routes import website_obj
|
||||
from foundation.routes import foundation_obj
|
||||
from bcf.routes import bcf
|
||||
|
||||
|
||||
app.register_blueprint(website_obj)
|
||||
app.register_blueprint(foundation_obj)
|
||||
app.register_blueprint(bcf)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user