fix(ranks): Fix creation permission check.
This commit is contained in:
@@ -12,6 +12,7 @@ from data import ORDER
|
|||||||
|
|
||||||
from utils.ui import MessageUI, Confirm
|
from utils.ui import MessageUI, Confirm
|
||||||
from utils.lib import MessageArgs
|
from utils.lib import MessageArgs
|
||||||
|
from wards import equippable_role
|
||||||
from babel.translator import ctx_translator
|
from babel.translator import ctx_translator
|
||||||
|
|
||||||
from .. import babel, logger
|
from .. import babel, logger
|
||||||
@@ -185,25 +186,11 @@ class RankOverviewUI(MessageUI):
|
|||||||
or edit an existing rank,
|
or edit an existing rank,
|
||||||
or throw an error if the role is @everyone or not manageable by the client.
|
or throw an error if the role is @everyone or not manageable by the client.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
role: discord.Role = selected.values[0]
|
role: discord.Role = selected.values[0]
|
||||||
if role >= selection.user.top_role:
|
|
||||||
# Do not allow user to manage a role above their own top role
|
if role.is_assignable():
|
||||||
t = self.bot.translator.t
|
# Create or edit the selected role
|
||||||
error = t(_p(
|
|
||||||
'ui:rank_overview|menu:roles|error:above_caller',
|
|
||||||
"You have insufficient permissions to assign {mention} as a rank role! "
|
|
||||||
"You may only manage roles below your top role."
|
|
||||||
)).format(mention=role.mention)
|
|
||||||
embed = discord.Embed(
|
|
||||||
title=t(_p(
|
|
||||||
'ui:rank_overview|menu:roles|error:above_caller|title',
|
|
||||||
"Insufficient permissions!"
|
|
||||||
)),
|
|
||||||
description=error,
|
|
||||||
colour=discord.Colour.brand_red()
|
|
||||||
)
|
|
||||||
await selection.response.send_message(embed=embed, ephemeral=True)
|
|
||||||
elif role.is_assignable():
|
|
||||||
existing = next((rank for rank in self.ranks if rank.roleid == role.id), None)
|
existing = next((rank for rank in self.ranks if rank.roleid == role.id), None)
|
||||||
if existing:
|
if existing:
|
||||||
# Display and edit the given role
|
# Display and edit the given role
|
||||||
@@ -216,6 +203,8 @@ class RankOverviewUI(MessageUI):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Create new rank based on role
|
# Create new rank based on role
|
||||||
|
# Need to check the calling author has authority to manage this role
|
||||||
|
await equippable_role(self.bot, role, selection.user)
|
||||||
await RankEditor.create_rank(
|
await RankEditor.create_rank(
|
||||||
selection,
|
selection,
|
||||||
self.rank_type,
|
self.rank_type,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from discord.ui.button import button, Button, ButtonStyle
|
|||||||
|
|
||||||
from meta import conf, LionBot
|
from meta import conf, LionBot
|
||||||
from core.data import RankType
|
from core.data import RankType
|
||||||
|
from wards import equippable_role
|
||||||
|
|
||||||
from utils.ui import MessageUI, AButton, AsComponents
|
from utils.ui import MessageUI, AButton, AsComponents
|
||||||
from utils.lib import MessageArgs, replace_multiple
|
from utils.lib import MessageArgs, replace_multiple
|
||||||
@@ -214,24 +215,11 @@ class RankPreviewUI(MessageUI):
|
|||||||
role: discord.Role = selected.values[0]
|
role: discord.Role = selected.values[0]
|
||||||
await selection.response.defer(thinking=True, ephemeral=True)
|
await selection.response.defer(thinking=True, ephemeral=True)
|
||||||
|
|
||||||
if role >= selection.user.top_role:
|
if role.is_assignable():
|
||||||
# Do not allow user to manage a role above their own top role
|
|
||||||
error = t(_p(
|
|
||||||
'ui:rank_preview|menu:roles|error:above_caller',
|
|
||||||
"You have insufficient permissions to assign {mention} as a rank role! "
|
|
||||||
"You may only manage roles below your top role."
|
|
||||||
))
|
|
||||||
embed = discord.Embed(
|
|
||||||
title=t(_p(
|
|
||||||
'ui:rank_preview|menu:roles|error:above_caller|title',
|
|
||||||
"Insufficient permissions!"
|
|
||||||
)),
|
|
||||||
description=error,
|
|
||||||
colour=discord.Colour.brand_red()
|
|
||||||
)
|
|
||||||
await selection.response.send_message(embed=embed, ephemeral=True)
|
|
||||||
elif role.is_assignable():
|
|
||||||
# Update the rank role
|
# Update the rank role
|
||||||
|
# Generic permission check for the new role
|
||||||
|
await equippable_role(self.bot, role, selection.user)
|
||||||
|
|
||||||
await self.rank.update(roleid=role.id)
|
await self.rank.update(roleid=role.id)
|
||||||
self.bot.get_cog('RankCog').flush_guild_ranks(self.guild.id)
|
self.bot.get_cog('RankCog').flush_guild_ranks(self.guild.id)
|
||||||
if self.parent is not None and not self.parent.is_finished():
|
if self.parent is not None and not self.parent.is_finished():
|
||||||
|
|||||||
Reference in New Issue
Block a user