forked from Ugric/Komodo-Hub
lock admin related things behind the new admin account
This commit is contained in:
1 parent
27bafb8caa
commit
2a11d13ba3
7 files changed
+57
-37
No files matched your search
+6
-7
@@ -1,4 +1,5 @@
|
|||||||
from database.db_connection import get_db, get_db
|
from database.db_connection import get_db, get_db
|
||||||
|
from database.db_commands import register_user
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
SEED_SPECIES = [
|
SEED_SPECIES = [
|
||||||
@@ -108,7 +109,6 @@ def init_database():
|
|||||||
""")
|
""")
|
||||||
print("Database initialised.")
|
print("Database initialised.")
|
||||||
seed_species()
|
seed_species()
|
||||||
init_programs_database()
|
|
||||||
|
|
||||||
|
|
||||||
def seed_species():
|
def seed_species():
|
||||||
@@ -220,9 +220,8 @@ def init_programs_database():
|
|||||||
""")
|
""")
|
||||||
print("Programs database tables initialised.")
|
print("Programs database tables initialised.")
|
||||||
|
|
||||||
|
init_database()
|
||||||
if __name__ == "__main__":
|
init_accounts_database()
|
||||||
init_database()
|
init_classes_database()
|
||||||
init_accounts_database()
|
init_programs_database()
|
||||||
init_classes_database()
|
register_user("admin", "admin@komodohub.org", "admin", "admin")
|
||||||
init_programs_database()
|
|
||||||
Binary file not shown.
@@ -64,7 +64,6 @@ def handle_bad_request(e):
|
|||||||
), 500
|
), 500
|
||||||
|
|
||||||
|
|
||||||
init_database()
|
|
||||||
import_pages("routes", app)
|
import_pages("routes", app)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from flask import render_template, Blueprint, request, redirect, url_for
|
from flask import render_template, Blueprint, request, redirect, url_for, g
|
||||||
from database.db_commands import delete_species, get_species_by_id, update_species, get_species_by_name
|
from database.db_commands import delete_species, get_species_by_id, update_species, get_species_by_name
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@@ -7,6 +7,8 @@ page = Blueprint("species_editor", __name__, url_prefix="/species/editor")
|
|||||||
|
|
||||||
@page.route("/<species_id>")
|
@page.route("/<species_id>")
|
||||||
def edit_species(species_id):
|
def edit_species(species_id):
|
||||||
|
if not g.user or g.user["account_type"] != "admin":
|
||||||
|
return "access denied", 401
|
||||||
species_to_edit = get_species_by_id(species_id)
|
species_to_edit = get_species_by_id(species_id)
|
||||||
print(species_id)
|
print(species_id)
|
||||||
return render_template(
|
return render_template(
|
||||||
@@ -17,6 +19,8 @@ def edit_species(species_id):
|
|||||||
|
|
||||||
@page.route("/<species_id>", methods=["POST"])
|
@page.route("/<species_id>", methods=["POST"])
|
||||||
def species_update(species_id):
|
def species_update(species_id):
|
||||||
|
if not g.user or g.user["account_type"] != "admin":
|
||||||
|
return "access denied", 401
|
||||||
try:
|
try:
|
||||||
eng_name = request.form["eng_name"].title()
|
eng_name = request.form["eng_name"].title()
|
||||||
latin_name = request.form["latin_name"].capitalize()
|
latin_name = request.form["latin_name"].capitalize()
|
||||||
@@ -43,6 +47,8 @@ def species_update(species_id):
|
|||||||
|
|
||||||
@page.route("/success/<eng_name>")
|
@page.route("/success/<eng_name>")
|
||||||
def edit_success(eng_name):
|
def edit_success(eng_name):
|
||||||
|
if not g.user or g.user["account_type"] != "admin":
|
||||||
|
return "access denied", 401
|
||||||
return render_template(
|
return render_template(
|
||||||
"species_portal/species_portal_success.jinja",
|
"species_portal/species_portal_success.jinja",
|
||||||
eng_name = eng_name,
|
eng_name = eng_name,
|
||||||
@@ -50,6 +56,8 @@ def edit_success(eng_name):
|
|||||||
|
|
||||||
@page.route("/delete/<species_english>", methods=["POST"])
|
@page.route("/delete/<species_english>", methods=["POST"])
|
||||||
def delete_species_from_database(species_english):
|
def delete_species_from_database(species_english):
|
||||||
|
if not g.user or g.user["account_type"] != "admin":
|
||||||
|
return "access denied", 401
|
||||||
try:
|
try:
|
||||||
entry = get_species_by_name(species_english)
|
entry = get_species_by_name(species_english)
|
||||||
if entry is None:
|
if entry is None:
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
from flask import render_template, Blueprint, request, redirect, url_for, flash
|
from flask import render_template, Blueprint, request, redirect, url_for, flash, g
|
||||||
from database.db_commands import add_species, delete_species, get_species_by_name, get_species_by_id
|
from database.db_commands import (
|
||||||
|
add_species,
|
||||||
|
delete_species,
|
||||||
|
get_species_by_name,
|
||||||
|
get_species_by_id,
|
||||||
|
)
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@@ -8,43 +13,53 @@ page = Blueprint("species_portal", __name__, url_prefix="/species/portal")
|
|||||||
|
|
||||||
@page.route("/")
|
@page.route("/")
|
||||||
def portal():
|
def portal():
|
||||||
|
if not g.user or g.user["account_type"] != "admin":
|
||||||
|
return "access denied", 401
|
||||||
return render_template("species_portal/species_portal.jinja")
|
return render_template("species_portal/species_portal.jinja")
|
||||||
|
|
||||||
|
|
||||||
@page.route("/", methods=["POST"])
|
@page.route("/", methods=["POST"])
|
||||||
def add_species_to_database():
|
def add_species_to_database():
|
||||||
|
if not g.user or g.user["account_type"] != "admin":
|
||||||
|
return "access denied", 401
|
||||||
try:
|
try:
|
||||||
eng_name = request.form["eng_name"].title()
|
eng_name = request.form["eng_name"].title()
|
||||||
latin_name = request.form["latin_name"].capitalize()
|
latin_name = request.form["latin_name"].capitalize()
|
||||||
main_text = request.form["main_text"]
|
main_text = request.form["main_text"]
|
||||||
category = request.form["category"].capitalize()
|
category = request.form["category"].capitalize()
|
||||||
extinction_risk = request.form["extinction_risk"]
|
extinction_risk = request.form["extinction_risk"]
|
||||||
species_image = request.files["species_image"]
|
species_image = request.files["species_image"]
|
||||||
image_id = ""
|
image_id = ""
|
||||||
if species_image:
|
if species_image:
|
||||||
image_id = str(uuid.uuid4())
|
image_id = str(uuid.uuid4())
|
||||||
species_image.save(f"database/images/{image_id}")
|
species_image.save(f"database/images/{image_id}")
|
||||||
print(category, extinction_risk)
|
print(category, extinction_risk)
|
||||||
add_species(eng_name, latin_name, main_text, category, extinction_risk, image_id)
|
add_species(
|
||||||
|
eng_name, latin_name, main_text, category, extinction_risk, image_id
|
||||||
|
)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"species_portal/species_portal_success.jinja",
|
"species_portal/species_portal_success.jinja",
|
||||||
eng_name = eng_name,
|
eng_name=eng_name,
|
||||||
)
|
)
|
||||||
except ValueError as error_information:
|
except ValueError as error_information:
|
||||||
species_to_edit = get_species_by_name(request.form["eng_name"].title())
|
species_to_edit = get_species_by_name(request.form["eng_name"].title())
|
||||||
species_id = species_to_edit['species_id']
|
species_id = species_to_edit["species_id"]
|
||||||
flash(f"{species_to_edit['species_english']} already exists. You have been redirected to the editor to update it.", "info")
|
flash(
|
||||||
|
f"{species_to_edit['species_english']} already exists. You have been redirected to the editor to update it.",
|
||||||
|
"info",
|
||||||
|
)
|
||||||
return redirect(url_for("species_editor.edit_species", species_id=species_id))
|
return redirect(url_for("species_editor.edit_species", species_id=species_id))
|
||||||
except Exception as error_information:
|
except Exception as error_information:
|
||||||
return render_template(
|
return render_template(
|
||||||
"species_portal/species_portal_failed.jinja",
|
"species_portal/species_portal_failed.jinja",
|
||||||
error_information=error_information
|
error_information=error_information,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@page.route("/<eng_name>")
|
@page.route("/<eng_name>")
|
||||||
def portal_success(eng_name):
|
def portal_success(eng_name):
|
||||||
return render_template(
|
return render_template(
|
||||||
"species_portal/species_portal_success.jinja",
|
"species_portal/species_portal_success.jinja",
|
||||||
eng_name = eng_name,
|
eng_name=eng_name,
|
||||||
)
|
)
|
||||||
@@ -2,13 +2,14 @@
|
|||||||
<div class="navbar">
|
<div class="navbar">
|
||||||
<div class="left">
|
<div class="left">
|
||||||
<a href="/" class="left">
|
<a href="/" class="left">
|
||||||
<img src="/images/lizard.png" class="logo-img">
|
<img src="/images/lizard.png" class="logo-img">
|
||||||
<span class="logo-text">Komodo Hub</span>
|
<span class="logo-text">Komodo Hub</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="links">
|
<div class="links">
|
||||||
{# todo #}
|
{% if user %}
|
||||||
|
{% if user["account_type"] == "admin" %}
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
<button class="dropbtn">Devtools ▾</button>
|
<button class="dropbtn">Devtools ▾</button>
|
||||||
<div class="dropdown-content">
|
<div class="dropdown-content">
|
||||||
@@ -21,9 +22,6 @@
|
|||||||
<a href="/dashboard">Dashboard</a>
|
<a href="/dashboard">Dashboard</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{# todo #}
|
|
||||||
{% if user %}
|
|
||||||
{% if user[4] %}
|
|
||||||
<a href="/admin">Admin</a>
|
<a href="/admin">Admin</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a href="/dashboard">Dashboard</a>
|
<a href="/dashboard">Dashboard</a>
|
||||||
|
|||||||
@@ -35,8 +35,9 @@
|
|||||||
<p>{{ main_text }}</p>
|
<p>{{ main_text }}</p>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
{# this button should only be visible to certain account types #}
|
{% if user and user["account_type"] == "admin"%}
|
||||||
<div style="text-align: right;">
|
<div style="text-align: right;">
|
||||||
{{ button(url='/species/editor/'+species_id, button_text='Edit Species') }}
|
{{ button(url='/species/editor/'+species_id, button_text='Edit Species') }}
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
Reference in new issue
Block a user