mirror of
https://github.com/progval/Limnoria.git
synced 2025-04-26 13:01:06 -05:00
Add configuration variable conf.supybot.capabilities.private.
This variable is a list of capabilities that are considered as 'private', ie. the bot won't tell anyone but admins that a user has it, nor will the bot give a list of users with this capability.
This commit is contained in:
parent
88b2b235ff
commit
fba70d15bc
@ -54,6 +54,15 @@ class User(callbacks.Plugin):
|
|||||||
predicates = []
|
predicates = []
|
||||||
for (option, arg) in optlist:
|
for (option, arg) in optlist:
|
||||||
if option == 'capability':
|
if option == 'capability':
|
||||||
|
try:
|
||||||
|
u = ircdb.users.getUser(msg.prefix)
|
||||||
|
if arg in conf.supybot.capabilities.private() and \
|
||||||
|
not u._checkCapability('admin'):
|
||||||
|
raise KeyError
|
||||||
|
except KeyError:
|
||||||
|
# Note that it may be raised by checkCapability too.
|
||||||
|
irc.error(_('This is a private capability. Only admins '
|
||||||
|
'can see who has it.'), Raise=True)
|
||||||
def p(u, cap=arg):
|
def p(u, cap=arg):
|
||||||
try:
|
try:
|
||||||
return u._checkCapability(cap)
|
return u._checkCapability(cap)
|
||||||
|
@ -33,7 +33,7 @@ import supybot.world as world
|
|||||||
import supybot.ircdb as ircdb
|
import supybot.ircdb as ircdb
|
||||||
|
|
||||||
class UserTestCase(PluginTestCase):
|
class UserTestCase(PluginTestCase):
|
||||||
plugins = ('User', 'Admin')
|
plugins = ('User', 'Admin', 'Config')
|
||||||
prefix1 = 'somethingElse!user@host.tld'
|
prefix1 = 'somethingElse!user@host.tld'
|
||||||
prefix2 = 'EvensomethingElse!user@host.tld'
|
prefix2 = 'EvensomethingElse!user@host.tld'
|
||||||
def testHostmaskList(self):
|
def testHostmaskList(self):
|
||||||
@ -95,6 +95,14 @@ class UserTestCase(PluginTestCase):
|
|||||||
self.assertRegexp('user list --capability testcap', 'no matching')
|
self.assertRegexp('user list --capability testcap', 'no matching')
|
||||||
self.assertNotError('admin capability add biff testcap')
|
self.assertNotError('admin capability add biff testcap')
|
||||||
self.assertResponse('user list --capability testcap', 'biff')
|
self.assertResponse('user list --capability testcap', 'biff')
|
||||||
|
self.assertNotError('config capabilities.private testcap')
|
||||||
|
self.assertRegexp('user list --capability testcap', 'Error:.*private')
|
||||||
|
self.assertNotError('admin capability add biff admin')
|
||||||
|
self.assertResponse('user list --capability testcap', 'biff')
|
||||||
|
self.assertNotError('admin capability remove biff admin')
|
||||||
|
self.assertRegexp('user list --capability testcap', 'Error:.*private')
|
||||||
|
self.assertNotError('config capabilities.private ""')
|
||||||
|
self.assertResponse('user list --capability testcap', 'biff')
|
||||||
self.assertNotError('admin capability remove biff testcap')
|
self.assertNotError('admin capability remove biff testcap')
|
||||||
self.assertRegexp('user list --capability testcap', 'no matching')
|
self.assertRegexp('user list --capability testcap', 'no matching')
|
||||||
|
|
||||||
|
@ -484,8 +484,12 @@ class RichReplyMethods(object):
|
|||||||
log.warning('Denying %s for lacking %q capability.',
|
log.warning('Denying %s for lacking %q capability.',
|
||||||
self.msg.prefix, capability)
|
self.msg.prefix, capability)
|
||||||
if not self._getConfig(conf.supybot.reply.error.noCapability):
|
if not self._getConfig(conf.supybot.reply.error.noCapability):
|
||||||
v = self._getConfig(conf.supybot.replies.noCapability)
|
if capability in conf.supybot.capabilities.private():
|
||||||
s = self.__makeReply(v % capability, s)
|
v = self._getConfig(conf.supybot.replies.genericNoCapability)
|
||||||
|
else:
|
||||||
|
v = self._getConfig(conf.supybot.replies.noCapability)
|
||||||
|
v %= capability
|
||||||
|
s = self.__makeReply(v, s)
|
||||||
return self._error(s, **kwargs)
|
return self._error(s, **kwargs)
|
||||||
else:
|
else:
|
||||||
log.debug('Not sending capability error, '
|
log.debug('Not sending capability error, '
|
||||||
|
@ -1082,6 +1082,9 @@ conf.registerGlobalValue(conf.supybot.capabilities, 'default',
|
|||||||
registry.Boolean(True, """Determines whether the bot by default will allow
|
registry.Boolean(True, """Determines whether the bot by default will allow
|
||||||
users to have a capability. If this is disabled, a user must explicitly
|
users to have a capability. If this is disabled, a user must explicitly
|
||||||
have the capability for whatever command he wishes to run."""))
|
have the capability for whatever command he wishes to run."""))
|
||||||
|
conf.registerGlobalValue(conf.supybot.capabilities, 'private',
|
||||||
|
registry.SpaceSeparatedListOfStrings([], """Determines what capabilities
|
||||||
|
the bot will never tell to a non-admin whether or not a user has them."""))
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
@ -531,13 +531,16 @@ class PluginRegexpTestCase(PluginTestCase):
|
|||||||
self.assertResponse('test', 'test <foo>')
|
self.assertResponse('test', 'test <foo>')
|
||||||
|
|
||||||
class RichReplyMethodsTestCase(PluginTestCase):
|
class RichReplyMethodsTestCase(PluginTestCase):
|
||||||
plugins = ()
|
plugins = ('Config',)
|
||||||
class NoCapability(callbacks.Plugin):
|
class NoCapability(callbacks.Plugin):
|
||||||
def error(self, irc, msg, args):
|
def error(self, irc, msg, args):
|
||||||
irc.errorNoCapability('admin')
|
irc.errorNoCapability('admin')
|
||||||
def testErrorNoCapability(self):
|
def testErrorNoCapability(self):
|
||||||
self.irc.addCallback(self.NoCapability(self.irc))
|
self.irc.addCallback(self.NoCapability(self.irc))
|
||||||
self.assertRegexp('error', 'admin')
|
self.assertRegexp('error', 'You don\'t have the admin capability')
|
||||||
|
self.assertNotError('config capabilities.private admin')
|
||||||
|
self.assertRegexp('error', 'Error: You\'re missing some capability')
|
||||||
|
self.assertNotError('config capabilities.private ""')
|
||||||
|
|
||||||
|
|
||||||
class SourceNestedPluginTestCase(PluginTestCase):
|
class SourceNestedPluginTestCase(PluginTestCase):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user