change Topic to have a default required capability set, for all write operations.

by default, now only allows chanops, and users with admin or channel,op capability to change topics
This commit is contained in:
Daniel Folkinshteyn 2010-04-09 15:56:16 -04:00 committed by Valentin Lorentz
parent 7ec1ca2070
commit c0986e1122
3 changed files with 11 additions and 13 deletions

View File

@ -66,12 +66,11 @@ conf.registerChannelValue(Topic.undo, 'max',
registry.NonNegativeInteger(10, _("""Determines the number of previous
topics to keep around in case the undo command is called.""")))
conf.registerChannelValue(Topic, 'requireManageCapability',
registry.String('channel,op; channel,halfop',
_("""Determines the
registry.String('admin; channel,op', _("""Determines the
capabilities required (if any) to make any topic changes,
(everything except for read-only operations). Use 'channel,capab' for
(everything except for read-only operations). Use 'channel,capab' for
channel-level capabilities.
Note that absence of an explicit anticapability means user has
Note that absence of an explicit anticapability means user has
capability.""")))

View File

@ -46,6 +46,7 @@ import supybot.callbacks as callbacks
from supybot.i18n import PluginInternationalization, internationalizeDocstring
_ = PluginInternationalization('Topic')
import supybot.ircdb as ircdb
def canChangeTopic(irc, msg, args, state):
assert not state.channel
@ -207,7 +208,6 @@ class Topic(callbacks.Plugin):
irc.queueMsg(ircmsgs.topic(channel, newTopic))
irc.noReply()
@internationalizeDocstring
def _checkManageCapabilities(self, irc, msg, channel):
"""Check if the user has any of the required capabilities to manage
the channel topic.
@ -219,7 +219,7 @@ class Topic(callbacks.Plugin):
manually anyway.
"""
c = irc.state.channels[channel]
if msg.nick in c.ops or msg.nick in c.halfops or 't' not in c.modes:
if msg.nick in c.ops:
return True
capabilities = self.registryValue('requireManageCapability')
if capabilities:
@ -403,6 +403,9 @@ class Topic(callbacks.Plugin):
index into the topics. <channel> is only necessary if the message
isn't sent in the channel itself.
"""
if not self._checkManageCapabilities(irc, msg, channel):
capabilities = self.registryValue('requireManageCapability')
irc.errorNoCapability(capabilities, Raise=True)
topics = self._splitTopic(irc.state.getTopic(channel), channel)
irc.reply(topics[number])
get = wrap(get, ['inChannel', 'topicNumber'])

View File

@ -70,18 +70,14 @@ class TopicTestCase(ChannelPluginTestCase):
self.assertEqual(m.command, 'TOPIC')
self.assertEqual(m.args[0], self.channel)
self.assertEqual(m.args[1], 'foo (test) || bar (test)')
def testManageCapabilities(self):
try:
self.irc.feedMsg(ircmsgs.mode(self.channel, args=('+o', self.nick),
prefix=self.prefix))
self.irc.feedMsg(ircmsgs.mode(self.channel, args=('+t'),
prefix=self.prefix))
world.testing = False
origuser = self.prefix
self.prefix = 'stuff!stuff@stuff'
self.assertNotError('register nottester stuff', private=True)
self.assertError('topic add foo')
origconf = conf.supybot.plugins.Topic.requireManageCapability()
conf.supybot.plugins.Topic.requireManageCapability.setValue('')
@ -90,7 +86,7 @@ class TopicTestCase(ChannelPluginTestCase):
world.testing = True
self.prefix = origuser
conf.supybot.plugins.Topic.requireManageCapability.setValue(origconf)
def testInsert(self):
m = self.getMsg('topic add foo')
self.assertEqual(m.args[1], 'foo (test)')