Browse Source

Put admin routes into a folder

pull/12/head
Darks 5 months ago
parent
commit
de2c1e8c63
Signed by: Darks <l.gatin@neuf.fr> GPG Key ID: F61F10FA138E797C
3 changed files with 82 additions and 75 deletions
  1. 1
    75
      app/routes/admin/edit-account.py
  2. 72
    0
      app/routes/admin/groups.py
  3. 9
    0
      app/routes/admin/index.py

app/routes/admin.py → app/routes/admin/edit-account.py View File

@@ -1,83 +1,9 @@
from flask import request, flash, redirect, url_for
from app.utils.priv_required import priv_required
from flask_wtf import FlaskForm
from wtforms import SubmitField
from app.models.users import Member, Group, GroupPrivilege
from app.models.privs import SpecialPrivilege
from app.models.users import Member
from app.forms.account import AdminUpdateAccountForm, AdminDeleteAccountForm
from app.utils.render import render
from app import app, db
import yaml
import os


@app.route('/admin', methods=['GET', 'POST'])
@priv_required('access-admin-panel')
def adm():
return render('admin/index.html')


@app.route('/admin/groups', methods=['GET', 'POST'])
@priv_required('access-admin-panel')
def adm_groups():
class GroupRegenerationForm(FlaskForm):
submit = SubmitField(
'Régénérer les groupes, privilèges, et comptes communs')

form = GroupRegenerationForm()
if form.validate_on_submit():
# Clean up groups
for g in Group.query.all():
g.delete()

# Create base groups
groups = []
with open(os.path.join(app.root_path, "data", "groups.yaml")) as fp:
groups = yaml.load(fp.read())

for g in groups:
g["obj"] = Group(g["name"], g["css"], g["descr"])
db.session.add(g["obj"])
db.session.commit()

for g in groups:
for priv in g.get("privs", "").split():
db.session.add(GroupPrivilege(g["obj"], priv))
db.session.commit()

# Clean up test members
for name in "PlanèteCasio GLaDOS".split():
m = Member.query.filter_by(name=name).first()
if m is not None:
m.delete()

# Create template members

def addgroup(member, group):
g = Group.query.filter_by(name=group).first()
if g is not None:
member.groups.append(g)

m = Member('PlanèteCasio', 'contact@planet-casio.com', 'v5-forever')
addgroup(m, "Compte communautaire")
db.session.add(m)

m = Member('GLaDOS', 'glados@aperture.science', 'v5-forever')
m.xp = 1337
addgroup(m, "Robot")
db.session.add(m)
db.session.commit()

db.session.add(SpecialPrivilege(m, "edit-posts"))
db.session.add(SpecialPrivilege(m, "shoutbox-ban"))

db.session.commit()

users = Member.query.all()
groups = Group.query.all()

return render('admin/groups_privileges.html', users=users, groups=groups,
form=form)


@app.route('/admin/edit-account/<user_id>', methods=['GET', 'POST'])

+ 72
- 0
app/routes/admin/groups.py View File

@@ -0,0 +1,72 @@
from app.utils.priv_required import priv_required
from flask_wtf import FlaskForm
from wtforms import SubmitField
from app.models.users import Member, Group, GroupPrivilege
from app.models.privs import SpecialPrivilege
from app.utils.render import render
from app import app, db
import yaml
import os


@app.route('/admin/groups', methods=['GET', 'POST'])
@priv_required('access-admin-panel')
def adm_groups():
class GroupRegenerationForm(FlaskForm):
submit = SubmitField(
'Régénérer les groupes, privilèges, et comptes communs')

form = GroupRegenerationForm()
if form.validate_on_submit():
# Clean up groups
for g in Group.query.all():
g.delete()

# Create base groups
groups = []
with open(os.path.join(app.root_path, "data", "groups.yaml")) as fp:
groups = yaml.load(fp.read())

for g in groups:
g["obj"] = Group(g["name"], g["css"], g["descr"])
db.session.add(g["obj"])
db.session.commit()

for g in groups:
for priv in g.get("privs", "").split():
db.session.add(GroupPrivilege(g["obj"], priv))
db.session.commit()

# Clean up test members
for name in "PlanèteCasio GLaDOS".split():
m = Member.query.filter_by(name=name).first()
if m is not None:
m.delete()

# Create template members

def addgroup(member, group):
g = Group.query.filter_by(name=group).first()
if g is not None:
member.groups.append(g)

m = Member('PlanèteCasio', 'contact@planet-casio.com', 'v5-forever')
addgroup(m, "Compte communautaire")
db.session.add(m)

m = Member('GLaDOS', 'glados@aperture.science', 'v5-forever')
m.xp = 1337
addgroup(m, "Robot")
db.session.add(m)
db.session.commit()

db.session.add(SpecialPrivilege(m, "edit-posts"))
db.session.add(SpecialPrivilege(m, "shoutbox-ban"))

db.session.commit()

users = Member.query.all()
groups = Group.query.all()

return render('admin/groups_privileges.html', users=users, groups=groups,
form=form)

+ 9
- 0
app/routes/admin/index.py View File

@@ -0,0 +1,9 @@
from app.utils.priv_required import priv_required
from app.utils.render import render
from app import app


@app.route('/admin', methods=['GET', 'POST'])
@priv_required('access-admin-panel')
def adm():
return render('admin/index.html')

Loading…
Cancel
Save