fix(ticket): isoler les permissions staff par catégorie

Le bug faisait que les rôles staff ajoutés via le panneau d'une
catégorie spécifique étaient incorrectement stockés dans config_roles
au lieu de staff_roles de la catégorie. Corrige PermissionConfigView
pour gérer correctement config_type="cat_{id}".

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Lowei 2026-05-23 12:48:08 +02:00
parent 19fa423210
commit e11f0d8b4a

View file

@ -2899,8 +2899,17 @@ class PermissionConfigView(disnake.ui.View):
# Determine which list to update
if self.config_type == "staff":
target_list = self.config.staff_roles
else:
elif self.config_type == "config":
target_list = self.config.config_roles
else:
# Category-specific staff roles (config_type = "cat_{cat_id}")
cat_id = self.config_type.replace("cat_", "")
category = self.config.get_category(cat_id)
if category:
target_list = category.staff_roles
else:
await interaction.response.send_message("Catégorie introuvable.", ephemeral=True)
return
# Get new selected IDs
new_ids = interaction.data.get('values', [])
@ -2927,8 +2936,11 @@ class PermissionConfigView(disnake.ui.View):
try:
if self.config_type == "staff":
target_list = self.config.staff_users
else:
elif self.config_type == "config":
target_list = self.config.config_users
else:
# Category-specific staff - users not separately managed per category, use global staff_users
target_list = self.config.staff_users
new_ids = [int(uid) for uid in interaction.data.get('values', [])]
added_count = 0
@ -2958,8 +2970,19 @@ class PermissionConfigView(disnake.ui.View):
await interaction.response.edit_message(components=self.get_components_v2())
def get_components_v2(self):
title = "🛡️ Permissions Staff" if self.config_type == "staff" else "⚙️ Permissions Config"
desc = "Configurez qui peut gérer les tickets." if self.config_type == "staff" else "Configurez qui peut modifier les paramètres."
if self.config_type == "staff":
title = "🛡️ Permissions Staff"
desc = "Configurez qui peut gérer les tickets."
elif self.config_type == "config":
title = "⚙️ Permissions Config"
desc = "Configurez qui peut modifier les paramètres."
else:
# Category-specific staff roles
cat_id = self.config_type.replace("cat_", "")
category = self.config.get_category(cat_id)
cat_name = category.name if category else f"Catégorie {cat_id}"
title = f"🛡️ Permissions Staff - {cat_name}"
desc = f"Configurez les rôles staff ayant accès à la catégorie '{cat_name}'."
sections = [
disnake.ui.TextDisplay(content=f"# {title}\n{desc}"),
@ -2979,9 +3002,18 @@ class PermissionConfigView(disnake.ui.View):
if self.config_type == "staff":
roles = self.config.staff_roles
users = self.config.staff_users
else:
elif self.config_type == "config":
roles = self.config.config_roles
users = self.config.config_users
else:
# Category-specific staff roles
cat_id = self.config_type.replace("cat_", "")
category = self.config.get_category(cat_id)
if category:
roles = category.staff_roles
else:
roles = []
users = self.config.staff_users # Category uses global staff_users
# Limit to 25 items for removal dropdown (API Limit)
# If more, we might need pagination or just show first 25.
@ -3033,12 +3065,29 @@ class PermissionConfigView(disnake.ui.View):
id_val = int(id_str)
if prefix == 'r': # Role
target_list = self.config.staff_roles if self.config_type == "staff" else self.config.config_roles
if self.config_type == "staff":
target_list = self.config.staff_roles
elif self.config_type == "config":
target_list = self.config.config_roles
else:
# Category-specific staff roles
cat_id = self.config_type.replace("cat_", "")
category = self.config.get_category(cat_id)
if category:
target_list = category.staff_roles
else:
continue
if str(id_val) in target_list:
target_list.remove(str(id_val))
removed_count += 1
elif prefix == 'u': # User
target_list = self.config.staff_users if self.config_type == "staff" else self.config.config_users
if self.config_type == "staff":
target_list = self.config.staff_users
elif self.config_type == "config":
target_list = self.config.config_users
else:
# Category-specific staff uses global staff_users
target_list = self.config.staff_users
if id_val in target_list:
target_list.remove(id_val)
removed_count += 1