Browse Source

groups: move default group data to a suitable place

master
Lephe 7 months ago
parent
commit
725e768520
4 changed files with 90 additions and 41 deletions
  1. 72
    0
      app/data/groups.yaml
  2. 1
    1
      app/models/privs.py
  3. 15
    39
      app/routes/admin.py
  4. 2
    1
      assets/privs.txt

+ 72
- 0
app/data/groups.yaml View File

@@ -0,0 +1,72 @@
-
name: Administrateur
css: "color: #ee0000"
descr: "Vous voyez Chuck Norris ? Pareil."
privs: access-admin-board access-assoc-board write-news
upload-shared-files delete-shared-files
edit-posts delete-posts scheduled-posting
delete-content move-public-content move-private-content showcase-content
edit-static-content extract-posts
delete-notes delete-tests
shoutbox-kick shoutbox-ban
unlimited-pms footer-statistics community-login
access-admin-panel edit-account delete-account
-
name: Modérateur
css: "color: green"
descr: "Maîtres du kick, ils sont là pour faire respecter un semblant d'ordre."
privs: access-admin-board
edit-posts delete-posts
move-public-content extract-posts
delete-notes delete-tests
shoutbox-kick shoutbox-ban
unlimited-pms
-
name: Développeur
css: "color: #4169e1"
descr: "Les développeurs maintiennent et améliorent le code du site."
privs: access-admin-board
upload-shared-files delete-shared-files
scheduled-posting
edit-static-content
unlimited-pms footer-statistics community-login
access-admin-panel
-
name: Rédacteur
css: "color: blue"
descr: "Rédigent les meilleurs articles de la page d'accueil, rien que pour
vous <3"
privs: access-admin-board write-news
upload-shared-files delete-shared-files
scheduled-posting
showcase-content edit-static-content
-
name: Responsable communauté
css: "color: DarkOrange"
descr: "Anime les pages Twitter et Facebook de Planète Casio et surveille
l'évolution du monde autour de nous !"
privs: access-admin-board write-news
upload-shared-files delete-shared-files
scheduled-posting
showcase-content
-
name: Partenaire
css: "color: purple"
descr: "Membres de l'équipe d'administration des sites partenaires."
privs: write-news
upload-shared-files delete-shared-files
scheduled-posting
-
name: Compte communautaire
css: "background:#d8d8d8; border-radius:4px; color:#303030; padding:1px 2px"
descr: "Compte à usage général de l'équipe de Planète Casio."
-
name: Robot
css: "color: #cf25d0"
descr: "♫ Je suis Nono, le petit robot, l'ami d'Ulysse ♫"
privs: shoutbox-post shoutbox-kick shoutbox-ban
-
name: Membre de CreativeCalc
css: "color: #222222"
descr: "CreativeCalc est l'association qui gère Planète Casio."
privs: access-assoc-board

+ 1
- 1
app/models/privs.py View File

@@ -65,7 +65,7 @@ class Group(db.Model):

def privs(self):
gps = GroupPrivilege.query.filter_by(gid=self.id).all()
return [ gp.priv for gp in gps ]
return sorted(gp.priv for gp in gps)

def __repr__(self):
return f'<Group "{self.name}">'

+ 15
- 39
app/routes/admin.py View File

@@ -8,47 +8,20 @@ from app.models.privs import SpecialPrivilege
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')

# Default groups and privileges.
default_groups = [
('Administrateur', 'color: #ee0000',
"Vous voyez Chuck Norris ? Pareil."),
('Modérateur', 'color: green',
"Maîtres du kick, ils sont là pour faire respecter un semblant " +
"d'ordre."),
('Développeur', 'color: #4169e1',
"Les développeurs maintiennent et améliorent le code du site."),
('Rédacteur', 'color: blue',
"Rédigent les meilleurs articles de la page d'accueil, rien " +
"que pour vous <3"),
('Responsable communauté', 'color: DarkOrange',
"Anime les pages Twitter et Facebook de Planète Casio et " +
"surveille l'évolution du monde autour de nous !"),
('Partenaire', 'color: purple',
"Membres de l'équipe d'administration des sites partenaires."),
('Compte communautaire', 'background: #d8d8d8; border-radius: ' +
'4px; color:#303030; padding: 1px 2px',
"Compte à usage général de l'équipe de Planète Casio."),

('Robot', 'color: #cf25d0',
"♫ Je suis Nono, le petit robot, l'ami d'Ulysse ♫",
"shoutbox-kick shoutbox-ban".split()),

('Membre de CreativeCalc', 'color: #222222',
"CreativeCalc est l'association qui gère Planète Casio.",
"access-assoc-board".split()),
]

@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')
submit = SubmitField(
'Régénérer les groupes, privilèges, et comptes communs')

form = GroupRegenerationForm()
if form.validate_on_submit():
@@ -57,16 +30,18 @@ def adm_groups():
g.delete()

# Create base groups
groups = [ Group(g[0], g[1], g[2]) for g in default_groups ]
groups = []
with open(os.path.join(app.root_path, "data", "groups.yaml")) as fp:
groups = yaml.load(fp.read())

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

for g, dg in zip(groups, default_groups):
if len(dg) < 4:
continue
for priv in dg[3]:
db.session.add(GroupPrivilege(g, priv))
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
@@ -98,7 +73,8 @@ def adm_groups():

users = Member.query.all()
groups = Group.query.all()
return render('admin/groups_privileges.html', users=users, groups=groups, form=form)
return render('admin/groups_privileges.html', users=users, groups=groups,
form=form)

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

+ 2
- 1
assets/privs.txt View File

@@ -20,6 +20,7 @@ Content (topic, progs, tutos, etc) management:
move-private-content Change the section of a page in a private section
showcase-content Manage stocky content (post-its)
edit-static-content Edit static content pages
extract-posts Move out-of-topic posts to a new places

Program evaluation:
delete-notes Delete program notes
@@ -37,5 +38,5 @@ Miscellaenous:

Administration panel:
access-admin-panel Administration panel of website
edt-account Edit details of any account
edit-account Edit details of any account
delete-account Remove member accounts

Loading…
Cancel
Save