mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-11-27 21:37:23 +01:00
Admin capability add/remove refactored, and tests changed accordingly.
This commit is contained in:
parent
71830d0c84
commit
890d92df0e
@ -237,57 +237,59 @@ class Admin(callbacks.Plugin):
|
|||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
part = wrap(part, [optional('validChannel'), additional('text')])
|
part = wrap(part, [optional('validChannel'), additional('text')])
|
||||||
|
|
||||||
def addcapability(self, irc, msg, args, user, capability):
|
class capability(callbacks.Commands):
|
||||||
"""<name|hostmask> <capability>
|
|
||||||
|
|
||||||
Gives the user specified by <name> (or the user to whom <hostmask>
|
def add(self, irc, msg, args, user, capability):
|
||||||
currently maps) the specified capability <capability>
|
"""<name|hostmask> <capability>
|
||||||
"""
|
|
||||||
# Ok, the concepts that are important with capabilities:
|
|
||||||
#
|
|
||||||
### 1) No user should be able to elevate his privilege to owner.
|
|
||||||
### 2) Admin users are *not* superior to #channel.ops, and don't
|
|
||||||
### have God-like powers over channels.
|
|
||||||
### 3) We assume that Admin users are two things: non-malicious and
|
|
||||||
### and greedy for power. So they'll try to elevate their privilege
|
|
||||||
### to owner, but they won't try to crash the bot for no reason.
|
|
||||||
|
|
||||||
# Thus, the owner capability can't be given in the bot. Admin users
|
Gives the user specified by <name> (or the user to whom <hostmask>
|
||||||
# can only give out capabilities they have themselves (which will
|
currently maps) the specified capability <capability>
|
||||||
# depend on supybot.capabilities and its child default) but generally
|
"""
|
||||||
# means they can't mess with channel capabilities.
|
# Ok, the concepts that are important with capabilities:
|
||||||
if ircutils.strEqual(capability, 'owner'):
|
#
|
||||||
irc.error('The "owner" capability can\'t be added in the bot. '
|
### 1) No user should be able to elevate his privilege to owner.
|
||||||
'Use the supybot-adduser program (or edit the '
|
### 2) Admin users are *not* superior to #channel.ops, and don't
|
||||||
'users.conf file yourself) to add an owner capability.')
|
### have God-like powers over channels.
|
||||||
return
|
### 3) We assume that Admin users are two things: non-malicious and
|
||||||
if ircdb.isAntiCapability(capability) or \
|
### and greedy for power. So they'll try to elevate their privilege
|
||||||
ircdb.checkCapability(msg.prefix, capability):
|
### to owner, but they won't try to crash the bot for no reason.
|
||||||
user.addCapability(capability)
|
|
||||||
ircdb.users.setUser(user)
|
|
||||||
irc.replySuccess()
|
|
||||||
else:
|
|
||||||
irc.error('You can\'t add capabilities you don\'t have.')
|
|
||||||
addcapability = wrap(addcapability, ['otherUser', 'lowered'])
|
|
||||||
|
|
||||||
def removecapability(self, irc, msg, args, user, capability):
|
# Thus, the owner capability can't be given in the bot. Admin users
|
||||||
"""<name|hostmask> <capability>
|
# can only give out capabilities they have themselves (which will
|
||||||
|
# depend on supybot.capabilities and its child default) but generally
|
||||||
Takes from the user specified by <name> (or the user to whom
|
# means they can't mess with channel capabilities.
|
||||||
<hostmask> currently maps) the specified capability <capability>
|
if ircutils.strEqual(capability, 'owner'):
|
||||||
"""
|
irc.error('The "owner" capability can\'t be added in the bot. '
|
||||||
if ircdb.checkCapability(msg.prefix, capability) or \
|
'Use the supybot-adduser program (or edit the '
|
||||||
ircdb.isAntiCapability(capability):
|
'users.conf file yourself) to add an owner capability.')
|
||||||
try:
|
return
|
||||||
user.removeCapability(capability)
|
if ircdb.isAntiCapability(capability) or \
|
||||||
|
ircdb.checkCapability(msg.prefix, capability):
|
||||||
|
user.addCapability(capability)
|
||||||
ircdb.users.setUser(user)
|
ircdb.users.setUser(user)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
except KeyError:
|
else:
|
||||||
irc.error('That user doesn\'t have that capability.')
|
irc.error('You can\'t add capabilities you don\'t have.')
|
||||||
else:
|
add = wrap(add, ['otherUser', 'lowered'])
|
||||||
s = 'You can\'t remove capabilities you don\'t have.'
|
|
||||||
irc.error(s)
|
def remove(self, irc, msg, args, user, capability):
|
||||||
removecapability = wrap(removecapability, ['otherUser','lowered'])
|
"""<name|hostmask> <capability>
|
||||||
|
|
||||||
|
Takes from the user specified by <name> (or the user to whom
|
||||||
|
<hostmask> currently maps) the specified capability <capability>
|
||||||
|
"""
|
||||||
|
if ircdb.checkCapability(msg.prefix, capability) or \
|
||||||
|
ircdb.isAntiCapability(capability):
|
||||||
|
try:
|
||||||
|
user.removeCapability(capability)
|
||||||
|
ircdb.users.setUser(user)
|
||||||
|
irc.replySuccess()
|
||||||
|
except KeyError:
|
||||||
|
irc.error('That user doesn\'t have that capability.')
|
||||||
|
else:
|
||||||
|
s = 'You can\'t remove capabilities you don\'t have.'
|
||||||
|
irc.error(s)
|
||||||
|
remove = wrap(remove, ['otherUser','lowered'])
|
||||||
|
|
||||||
def ignore(self, irc, msg, args, hostmask, expires):
|
def ignore(self, irc, msg, args, hostmask, expires):
|
||||||
"""<hostmask|nick> [<expires>]
|
"""<hostmask|nick> [<expires>]
|
||||||
|
|||||||
@ -61,16 +61,27 @@ class AdminTestCase(PluginTestCase):
|
|||||||
self.assertNotError('admin ignore foo!bar@baz')
|
self.assertNotError('admin ignore foo!bar@baz')
|
||||||
self.assertNotError('admin ignores')
|
self.assertNotError('admin ignores')
|
||||||
|
|
||||||
def testAddcapability(self):
|
def testCapabilityAdd(self):
|
||||||
self.assertError('addcapability sdlkfj foo')
|
self.assertError('capability add foo bar')
|
||||||
u = ircdb.users.newUser()
|
u = ircdb.users.newUser()
|
||||||
u.name = 'foo'
|
u.name = 'foo'
|
||||||
ircdb.users.setUser(u)
|
ircdb.users.setUser(u)
|
||||||
self.assertError('removecapability foo bar')
|
self.assertNotError('capability add foo bar')
|
||||||
self.assertNotRegexp('removecapability foo bar', 'find')
|
self.assertError('addcapability foo baz')
|
||||||
|
self.assert_('bar' in u.capabilities)
|
||||||
|
ircdb.users.delUser(u.id)
|
||||||
|
|
||||||
def testRemoveCapability(self):
|
def testCapabilityRemove(self):
|
||||||
self.assertError('removecapability alsdfkjasd foo')
|
self.assertError('capability remove foo bar')
|
||||||
|
u = ircdb.users.newUser()
|
||||||
|
u.name = 'foo'
|
||||||
|
ircdb.users.setUser(u)
|
||||||
|
self.assertNotError('capability add foo bar')
|
||||||
|
self.assert_('bar' in u.capabilities)
|
||||||
|
self.assertError('removecapability foo bar')
|
||||||
|
self.assertNotError('capability remove foo bar')
|
||||||
|
self.assert_(not 'bar' in u.capabilities)
|
||||||
|
ircdb.users.delUser(u.id)
|
||||||
|
|
||||||
def testJoin(self):
|
def testJoin(self):
|
||||||
m = self.getMsg('join #foo')
|
m = self.getMsg('join #foo')
|
||||||
@ -110,8 +121,7 @@ class AdminTestCase(PluginTestCase):
|
|||||||
conf.supybot.nick.setValue(original)
|
conf.supybot.nick.setValue(original)
|
||||||
|
|
||||||
def testAddCapabilityOwner(self):
|
def testAddCapabilityOwner(self):
|
||||||
self.assertError('admin addcapability %s owner' % self.nick)
|
self.assertError('admin capability add %s owner' % self.nick)
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user