lock admin related things behind the new admin account

This commit is contained in:
Ugric committed 2026-04-06 15:48:33 +01:00
1 parent 27bafb8caa
commit 2a11d13ba3
7 files changed
+57 -37

No files matched your search

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