forum : envoie les rôles au Hub (POST /oauth/roles) à la connexion et à chaque changement de rôle, pour la page du compte Gastinel
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cette révision appartient à :
1 Parent
6551843f28
révision
0fdae3bd70
4 fichiers modifiés
+32
Aucun fichier ne correspond à votre recherche
@@ -6,6 +6,7 @@ Le sujet fixe « Bulletin de la semaine du Vercors » est toujours épinglé en
|
||||
import hashlib
|
||||
import os
|
||||
import secrets
|
||||
import threading
|
||||
|
||||
import db
|
||||
import photos
|
||||
@@ -32,6 +33,16 @@ class Forum:
|
||||
self.stations = stations or {} # id -> nom affiché (pour le titre des sujets de station)
|
||||
self.dossier_photos = dossier_photos
|
||||
self.proprietaire_id = proprietaire_id or None # id Gastinel de Théo (FORUM_PROPRIETAIRE_ID)
|
||||
self.apres_roles = None # fonction(hub_id, roles) : envoie les rôles au Hub (branchée par server.py)
|
||||
|
||||
def _pousser_roles(self, hub_id):
|
||||
if not self.apres_roles:
|
||||
return
|
||||
c = self.con.execute("SELECT id FROM users WHERE hub_id=?", (hub_id,)).fetchone()
|
||||
if c is None:
|
||||
return
|
||||
rs = [r[0] for r in self.con.execute("SELECT role FROM user_roles WHERE user_id=?", (c[0],))]
|
||||
threading.Thread(target=self.apres_roles, args=(hub_id, rs), daemon=True).start()
|
||||
|
||||
# --- connexion Gastinel et sessions ----------------------------------
|
||||
@staticmethod
|
||||
@@ -43,6 +54,7 @@ class Forum:
|
||||
u = self.utilisateur(hub_id, pseudo)
|
||||
if self.proprietaire_id and hub_id == self.proprietaire_id:
|
||||
u = self.fixer_proprietaire(hub_id, pseudo)
|
||||
self._pousser_roles(hub_id)
|
||||
return u
|
||||
|
||||
def ouvrir_session(self, user, jours=SESSION_JOURS, portee=""):
|
||||
@@ -167,6 +179,7 @@ class Forum:
|
||||
self.con.execute("INSERT OR IGNORE INTO user_roles(user_id, role, station, given_by) VALUES (?, ?, ?, ?)",
|
||||
(cible["id"], role, station, acteur["id"]))
|
||||
self.con.commit()
|
||||
self._pousser_roles(hub_id)
|
||||
|
||||
def retirer_role(self, acteur, hub_id, role, station=""):
|
||||
if not roles.peut_donner(self.roles_de(acteur), role):
|
||||
@@ -175,6 +188,7 @@ class Forum:
|
||||
self.con.execute("DELETE FROM user_roles WHERE user_id=? AND role=? AND station=?",
|
||||
(cible["id"], role, station if role == roles.STATION else ""))
|
||||
self.con.commit()
|
||||
self._pousser_roles(hub_id)
|
||||
|
||||
# --- lecture -------------------------------------------------------
|
||||
def _visible(self, user, t):
|
||||
|
||||
Référencer dans un nouveau ticket
Bloquer un utilisateur