mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-27 04:59:24 +01:00
core: Rehashable permissions; import coremods on start
This commit is contained in:
parent
6af8e77ee1
commit
556b388a4e
@ -6,6 +6,7 @@ import os
|
|||||||
|
|
||||||
from pylinkirc import world, utils, conf, classes
|
from pylinkirc import world, utils, conf, classes
|
||||||
from pylinkirc.log import log, makeFileLogger, stopFileLoggers
|
from pylinkirc.log import log, makeFileLogger, stopFileLoggers
|
||||||
|
from . import permissions
|
||||||
|
|
||||||
def remove_network(ircobj):
|
def remove_network(ircobj):
|
||||||
"""Removes a network object from the pool."""
|
"""Removes a network object from the pool."""
|
||||||
@ -55,6 +56,10 @@ def _rehash():
|
|||||||
for filename, config in files.items():
|
for filename, config in files.items():
|
||||||
makeFileLogger(filename, config.get('loglevel'))
|
makeFileLogger(filename, config.get('loglevel'))
|
||||||
|
|
||||||
|
# Reset permissions.
|
||||||
|
log.debug('rehash: resetting permissions.')
|
||||||
|
permissions.resetPermissions()
|
||||||
|
|
||||||
for network, ircobj in world.networkobjects.copy().items():
|
for network, ircobj in world.networkobjects.copy().items():
|
||||||
# Server was removed from the config file, disconnect them.
|
# Server was removed from the config file, disconnect them.
|
||||||
log.debug('rehash: checking if %r is in new conf still.', network)
|
log.debug('rehash: checking if %r is in new conf still.', network)
|
||||||
|
@ -24,11 +24,19 @@ def resetPermissions():
|
|||||||
global permissions
|
global permissions
|
||||||
log.debug('permissions.resetPermissions: old perm list: %s', permissions)
|
log.debug('permissions.resetPermissions: old perm list: %s', permissions)
|
||||||
|
|
||||||
|
new_permissions = default_permissions.copy()
|
||||||
|
log.debug('permissions.resetPermissions: new_permissions %s', new_permissions)
|
||||||
if not conf.conf.get('permissions_merge_defaults', True):
|
if not conf.conf.get('permissions_merge_defaults', True):
|
||||||
log.debug('permissions.resetPermissions: clearing perm list due to permissions_merge_defaults set False.')
|
log.debug('permissions.resetPermissions: clearing perm list due to permissions_merge_defaults set False.')
|
||||||
permissions.clear()
|
new_permissions.clear()
|
||||||
|
|
||||||
permissions.update(conf.conf.get('permissions', default_permissions))
|
# Convert all perm lists to sets.
|
||||||
|
for k, v in conf.conf.get('permissions', {}).items():
|
||||||
|
new_permissions[k] |= set(v)
|
||||||
|
|
||||||
|
log.debug('permissions.resetPermissions: new_permissions %s', new_permissions)
|
||||||
|
permissions.clear()
|
||||||
|
permissions.update(new_permissions)
|
||||||
log.debug('permissions.resetPermissions: new perm list: %s', permissions)
|
log.debug('permissions.resetPermissions: new perm list: %s', permissions)
|
||||||
|
|
||||||
def addDefaultPermissions(perms):
|
def addDefaultPermissions(perms):
|
||||||
@ -64,7 +72,3 @@ def checkPermissions(irc, uid, perms, also_show=[]):
|
|||||||
return True
|
return True
|
||||||
raise utils.NotAuthorizedError("You are missing one of the following permissions: %s" %
|
raise utils.NotAuthorizedError("You are missing one of the following permissions: %s" %
|
||||||
(', '.join(perms+also_show)))
|
(', '.join(perms+also_show)))
|
||||||
|
|
||||||
|
|
||||||
# This is called on first import.
|
|
||||||
resetPermissions()
|
|
||||||
|
3
pylink
3
pylink
@ -69,3 +69,6 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
world.started.set()
|
world.started.set()
|
||||||
log.info("Loaded plugins: %s", ', '.join(sorted(world.plugins.keys())))
|
log.info("Loaded plugins: %s", ', '.join(sorted(world.plugins.keys())))
|
||||||
|
|
||||||
|
from pylinkirc import coremods
|
||||||
|
coremods.permissions.resetPermissions()
|
||||||
|
Loading…
Reference in New Issue
Block a user