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:
parent
19fa423210
commit
e11f0d8b4a
1 changed files with 73 additions and 24 deletions
|
|
@ -2899,18 +2899,27 @@ class PermissionConfigView(disnake.ui.View):
|
||||||
# Determine which list to update
|
# Determine which list to update
|
||||||
if self.config_type == "staff":
|
if self.config_type == "staff":
|
||||||
target_list = self.config.staff_roles
|
target_list = self.config.staff_roles
|
||||||
else:
|
elif self.config_type == "config":
|
||||||
target_list = self.config.config_roles
|
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
|
# Get new selected IDs
|
||||||
new_ids = interaction.data.get('values', [])
|
new_ids = interaction.data.get('values', [])
|
||||||
added_count = 0
|
added_count = 0
|
||||||
|
|
||||||
for new_id in new_ids:
|
for new_id in new_ids:
|
||||||
if new_id not in target_list:
|
if new_id not in target_list:
|
||||||
target_list.append(new_id)
|
target_list.append(new_id)
|
||||||
added_count += 1
|
added_count += 1
|
||||||
|
|
||||||
self.storage.save_config(interaction.guild_id, self.config)
|
self.storage.save_config(interaction.guild_id, self.config)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2927,17 +2936,20 @@ class PermissionConfigView(disnake.ui.View):
|
||||||
try:
|
try:
|
||||||
if self.config_type == "staff":
|
if self.config_type == "staff":
|
||||||
target_list = self.config.staff_users
|
target_list = self.config.staff_users
|
||||||
else:
|
elif self.config_type == "config":
|
||||||
target_list = self.config.config_users
|
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', [])]
|
new_ids = [int(uid) for uid in interaction.data.get('values', [])]
|
||||||
added_count = 0
|
added_count = 0
|
||||||
|
|
||||||
for new_id in new_ids:
|
for new_id in new_ids:
|
||||||
if new_id not in target_list:
|
if new_id not in target_list:
|
||||||
target_list.append(new_id)
|
target_list.append(new_id)
|
||||||
added_count += 1
|
added_count += 1
|
||||||
|
|
||||||
self.storage.save_config(interaction.guild_id, self.config)
|
self.storage.save_config(interaction.guild_id, self.config)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -2958,9 +2970,20 @@ class PermissionConfigView(disnake.ui.View):
|
||||||
await interaction.response.edit_message(components=self.get_components_v2())
|
await interaction.response.edit_message(components=self.get_components_v2())
|
||||||
|
|
||||||
def get_components_v2(self):
|
def get_components_v2(self):
|
||||||
title = "🛡️ Permissions Staff" if self.config_type == "staff" else "⚙️ Permissions Config"
|
if self.config_type == "staff":
|
||||||
desc = "Configurez qui peut gérer les tickets." if self.config_type == "staff" else "Configurez qui peut modifier les paramètres."
|
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 = [
|
sections = [
|
||||||
disnake.ui.TextDisplay(content=f"# {title}\n{desc}"),
|
disnake.ui.TextDisplay(content=f"# {title}\n{desc}"),
|
||||||
disnake.ui.Separator(divider=True),
|
disnake.ui.Separator(divider=True),
|
||||||
|
|
@ -2975,17 +2998,26 @@ class PermissionConfigView(disnake.ui.View):
|
||||||
def _add_remove_select(self):
|
def _add_remove_select(self):
|
||||||
# Build options from current config
|
# Build options from current config
|
||||||
options = []
|
options = []
|
||||||
|
|
||||||
if self.config_type == "staff":
|
if self.config_type == "staff":
|
||||||
roles = self.config.staff_roles
|
roles = self.config.staff_roles
|
||||||
users = self.config.staff_users
|
users = self.config.staff_users
|
||||||
else:
|
elif self.config_type == "config":
|
||||||
roles = self.config.config_roles
|
roles = self.config.config_roles
|
||||||
users = self.config.config_users
|
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)
|
# Limit to 25 items for removal dropdown (API Limit)
|
||||||
# If more, we might need pagination or just show first 25.
|
# If more, we might need pagination or just show first 25.
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
for r_id in roles:
|
for r_id in roles:
|
||||||
if count >= 25: break
|
if count >= 25: break
|
||||||
|
|
@ -2998,7 +3030,7 @@ class PermissionConfigView(disnake.ui.View):
|
||||||
description="Cliquez pour retirer"
|
description="Cliquez pour retirer"
|
||||||
))
|
))
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
for u_id in users:
|
for u_id in users:
|
||||||
if count >= 25: break
|
if count >= 25: break
|
||||||
user = self.guild.get_member(u_id)
|
user = self.guild.get_member(u_id)
|
||||||
|
|
@ -3010,7 +3042,7 @@ class PermissionConfigView(disnake.ui.View):
|
||||||
description="Cliquez pour retirer"
|
description="Cliquez pour retirer"
|
||||||
))
|
))
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
if options:
|
if options:
|
||||||
select = disnake.ui.Select(
|
select = disnake.ui.Select(
|
||||||
placeholder="Sélectionnez pour RETIRER des permissions...",
|
placeholder="Sélectionnez pour RETIRER des permissions...",
|
||||||
|
|
@ -3026,23 +3058,40 @@ class PermissionConfigView(disnake.ui.View):
|
||||||
async def _remove_callback(self, interaction: disnake.Interaction):
|
async def _remove_callback(self, interaction: disnake.Interaction):
|
||||||
try:
|
try:
|
||||||
values = interaction.data.get('values', [])
|
values = interaction.data.get('values', [])
|
||||||
|
|
||||||
removed_count = 0
|
removed_count = 0
|
||||||
for val in values:
|
for val in values:
|
||||||
prefix, id_str = val.split('_')
|
prefix, id_str = val.split('_')
|
||||||
id_val = int(id_str)
|
id_val = int(id_str)
|
||||||
|
|
||||||
if prefix == 'r': # Role
|
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:
|
if str(id_val) in target_list:
|
||||||
target_list.remove(str(id_val))
|
target_list.remove(str(id_val))
|
||||||
removed_count += 1
|
removed_count += 1
|
||||||
elif prefix == 'u': # User
|
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:
|
if id_val in target_list:
|
||||||
target_list.remove(id_val)
|
target_list.remove(id_val)
|
||||||
removed_count += 1
|
removed_count += 1
|
||||||
|
|
||||||
self.storage.save_config(interaction.guild_id, self.config)
|
self.storage.save_config(interaction.guild_id, self.config)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue