3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-01 09:19:23 +01:00

corecommands: port to use the permissions API (#367)

This commit is contained in:
James Lu 2016-12-09 21:39:52 -08:00
parent 1e7210a6db
commit 5a066bfde4
2 changed files with 15 additions and 6 deletions

View File

@ -1,3 +1,3 @@
# Note: Service support has to be imported first, so that utils.add_cmd() works for corecommands, # Note: Service support has to be imported first, so that utils.add_cmd() works for corecommands,
# etc. # etc.
from . import service_support, control, handlers, corecommands, exttargets, permissions from . import service_support, permissions, control, handlers, corecommands, exttargets

View File

@ -9,7 +9,7 @@ import gc
import sys import sys
import importlib import importlib
from . import control, login from . import control, login, permissions
from pylinkirc import utils, world, conf from pylinkirc import utils, world, conf
from pylinkirc.log import log from pylinkirc.log import log
@ -62,7 +62,9 @@ def shutdown(irc, source, args):
"""takes no arguments. """takes no arguments.
Exits PyLink by disconnecting all networks.""" Exits PyLink by disconnecting all networks."""
irc.checkAuthenticated(source, allowOper=False)
permissions.checkPermissions(irc, source, ['core.shutdown'])
u = irc.users[source] u = irc.users[source]
log.info('(%s) SHUTDOWN requested by "%s!%s@%s", exiting...', irc.name, u.nick, log.info('(%s) SHUTDOWN requested by "%s!%s@%s", exiting...', irc.name, u.nick,
@ -75,7 +77,10 @@ def load(irc, source, args):
"""<plugin name>. """<plugin name>.
Loads a plugin from the plugin folder.""" Loads a plugin from the plugin folder."""
irc.checkAuthenticated(source, allowOper=False) # Note: reload capability is acceptable here, because all it actually does is call
# load after unload.
permissions.checkPermissions(irc, source, ['core.load', 'core.reload'])
try: try:
name = args[0] name = args[0]
except IndexError: except IndexError:
@ -104,6 +109,7 @@ def unload(irc, source, args):
"""<plugin name>. """<plugin name>.
Unloads a currently loaded plugin.""" Unloads a currently loaded plugin."""
permissions.checkPermissions(irc, source, ['core.unload', 'core.reload'])
irc.checkAuthenticated(source, allowOper=False) irc.checkAuthenticated(source, allowOper=False)
try: try:
name = args[0] name = args[0]
@ -177,6 +183,8 @@ def reload(irc, source, args):
except IndexError: except IndexError:
irc.reply("Error: Not enough arguments. Needs 1: plugin name.") irc.reply("Error: Not enough arguments. Needs 1: plugin name.")
return return
# Note: these functions do permission checks, so there are none needed here.
if unload(irc, source, args): if unload(irc, source, args):
load(irc, source, args) load(irc, source, args)
@ -185,8 +193,9 @@ def rehash(irc, source, args):
"""takes no arguments. """takes no arguments.
Reloads the configuration file for PyLink, (dis)connecting added/removed networks. Reloads the configuration file for PyLink, (dis)connecting added/removed networks.
Plugins must be manually reloaded."""
irc.checkAuthenticated(source, allowOper=False) Note: plugins must be manually reloaded."""
permissions.checkPermissions(irc, source, ['core.rehash'])
try: try:
control._rehash() control._rehash()
except Exception as e: # Something went wrong, abort. except Exception as e: # Something went wrong, abort.