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,8 +66,7 @@ conf.registerChannelValue(Topic.undo, 'max',
registry.NonNegativeInteger(10, _("""Determines the number of previous registry.NonNegativeInteger(10, _("""Determines the number of previous
topics to keep around in case the undo command is called."""))) topics to keep around in case the undo command is called.""")))
conf.registerChannelValue(Topic, 'requireManageCapability', conf.registerChannelValue(Topic, 'requireManageCapability',
registry.String('channel,op; channel,halfop', registry.String('admin; channel,op', _("""Determines the
_("""Determines the
capabilities required (if any) to make any topic changes, 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. channel-level capabilities.

View File

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

View File

@ -73,10 +73,6 @@ class TopicTestCase(ChannelPluginTestCase):
def testManageCapabilities(self): def testManageCapabilities(self):
try: 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 world.testing = False
origuser = self.prefix origuser = self.prefix
self.prefix = 'stuff!stuff@stuff' self.prefix = 'stuff!stuff@stuff'