Skip to content

Commit

Permalink
Added missing permissions for admin commands (#1226)
Browse files Browse the repository at this point in the history
* Added permission to music server admin commands.

* Added permissions to upgrade, toolbar and help admin commands.
  • Loading branch information
TheMaximum committed Nov 5, 2022
1 parent 801985f commit 001a9f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pyplanet/apps/contrib/admin/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ async def on_start(self):
self.app.context.signals.listen(mp_signals.player.player_connect, self.player_connect)

# Register commands.
await self.instance.permission_manager.register('toolbar', 'Toggle the admin toolbar', app=self.app, min_level=1)
await self.instance.command_manager.register(
Command(command='toolbar', target=self.toggle_toolbar, admin=True, description='Toggles the admin toolbar.')
Command(command='toolbar', perms='admin:toolbar', target=self.toggle_toolbar, admin=True, description='Toggles the admin toolbar.')
)

# Display to all current online admins.
Expand Down
6 changes: 4 additions & 2 deletions pyplanet/apps/contrib/music_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ async def on_start(self):
self.playlist_view = PlaylistView(self)

await self.context.setting.register(self.setting_override_map_music)
await self.instance.permission_manager.register('play', 'Plays a song from the playlist', app=self, min_level=1)
await self.instance.permission_manager.register('clear', 'Clear the playlist', app=self, min_level=1)

await self.instance.command_manager.register(
Command(command='play', target=self.play_song, admin=True)
Command(command='play', target=self.play_song, perms='music_server:play', admin=True)
.add_param(name='songname', type=str, required=True),
Command(command='song', target=self.get_current_song, admin=False),
Command(command='songlist', aliases='musiclist', target=self.song_list, admin=False),
Command(command='playlist', target=self.show_playlist, admin=False),
Command(command='clearplaylist', target=self.clear_playlist, admin=True),
Command(command='clearplaylist', target=self.clear_playlist, perms='music_server:clear', admin=True),
)

self.current_song_index = -1
Expand Down
10 changes: 7 additions & 3 deletions pyplanet/apps/core/pyplanet/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,24 @@ async def on_start(self):
# Display logo.
await self.controller_view.display()

# Permissions.
await self.instance.permission_manager.register('upgrade', 'Upgrade the PyPlanet instance', app=self, min_level=3)
await self.instance.permission_manager.register('help', 'Open the commands list for admins', app=self, min_level=1)

# Listeners.
self.context.signals.listen('maniaplanet:player_connect', self.on_connect)
await self.instance.command_manager.register(
Command('version', self.chat_version,
description='Displays the current server and PyPlanet versions and the active PyPlanet plugins.'),
Command('upgrade', self.chat_upgrade, admin=True, description='Upgrade PyPlanet installation (Experimental)')
Command('upgrade', self.chat_upgrade, perms='core.pyplanet:upgrade', admin=True, description='Upgrade PyPlanet installation (Experimental)')
.add_param('to_version', type=str, default=None, required=False, help='Upgrade to specific version'),

Command('help', target=self.chat_help, description='Shows a chat-based list with all available commands.')
.add_param('command', nargs='*', required=False),
Command('help', target=self.chat_help, admin=True, description='Shows a chat-based list with all available admin commands.')
Command('help', target=self.chat_help, perms='core.pyplanet:help', admin=True, description='Shows a chat-based list with all available admin commands.')
.add_param('command', nargs='*', required=False),
Command('helpall', target=self.chat_helpall, description='Shows all available commands in a list window.'),
Command('helpall', target=self.chat_helpall, admin=True, description='Shows all available admin commands in a list window.')
Command('helpall', target=self.chat_helpall, perms='core.pyplanet:help', admin=True, description='Shows all available admin commands in a list window.')
)

async def on_connect(self, player, **kwargs):
Expand Down

0 comments on commit 001a9f5

Please sign in to comment.