diff --git a/plugins/Quote/test.py b/plugins/Quote/test.py index d3a1d6c4f..f8a069491 100644 --- a/plugins/Quote/test.py +++ b/plugins/Quote/test.py @@ -43,13 +43,9 @@ class QuoteTestCase(ChannelPluginTestCase): def testUnauthenticatedAdd(self): # This should fail because the user isn't registered self.assertError('quote add hello world!') - original_value = conf.supybot.databases.plugins.requireRegistration() - conf.supybot.databases.plugins.requireRegistration.setValue(False) - try: + with conf.supybot.databases.plugins.requireRegistration.context(False): self.assertNotError('quote add hello world!') self.assertRegexp('quote get 1', 'hello') self.assertNotError('quote remove 1') - finally: - conf.supybot.databases.plugins.requireRegistration.setValue(original_value) # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/plugins/__init__.py b/plugins/__init__.py index b6b2a15a1..1dd6d728d 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -330,6 +330,8 @@ class ChannelIdDatabasePlugin(callbacks.Plugin): (self.name(), id, channel)) def checkChangeAllowed(self, irc, msg, channel, user, record): + # Checks and returns True if either the user ID (integer) + # or the hostmask of the caller match. if (hasattr(user, 'id') and user.id == record.by) or user == record.by: return True cap = ircdb.makeChannelCapability(channel, 'op') @@ -341,12 +343,12 @@ class ChannelIdDatabasePlugin(callbacks.Plugin): """This should irc.error or raise an exception if text is invalid.""" pass - def getUserId(self, irc, prefix): + def getUserId(self, irc, prefix, channel=None): try: user = ircdb.users.getUser(prefix) return user.id except KeyError: - if conf.supybot.databases.plugins.requireRegistration(): + if conf.get(conf.supybot.databases.plugins.requireRegistration, channel): irc.errorNotRegistered(Raise=True) return @@ -357,7 +359,7 @@ class ChannelIdDatabasePlugin(callbacks.Plugin): is only necessary if the message isn't sent in the channel itself. """ - user = self.getUserId(irc, msg.prefix) or msg.prefix + user = self.getUserId(irc, msg.prefix, channel) or msg.prefix at = time.time() self.addValidator(irc, text) if text is not None: @@ -372,7 +374,7 @@ class ChannelIdDatabasePlugin(callbacks.Plugin): is only necessary if the message isn't sent in the channel itself. """ - user = self.getUserId(irc, msg.prefix) or msg.prefix + user = self.getUserId(irc, msg.prefix, channel) or msg.prefix try: record = self.db.get(channel, id) self.checkChangeAllowed(irc, msg, channel, user, record) @@ -448,7 +450,7 @@ class ChannelIdDatabasePlugin(callbacks.Plugin): . is only necessary if the message isn't sent in the channel itself. """ - user = self.getUserId(irc, msg.prefix) or msg.prefix + user = self.getUserId(irc, msg.prefix, channel) or msg.prefix try: record = self.db.get(channel, id) self.checkChangeAllowed(irc, msg, channel, user, record) diff --git a/src/conf.py b/src/conf.py index ec0c0b207..ba2eb89d5 100644 --- a/src/conf.py +++ b/src/conf.py @@ -932,7 +932,7 @@ class ChannelSpecific(registry.Boolean): registerGroup(supybot.databases, 'plugins') -registerGlobalValue(supybot.databases.plugins, 'requireRegistration', +registerChannelValue(supybot.databases.plugins, 'requireRegistration', registry.Boolean(True, _("""Determines whether the bot will require user registration to use 'add' commands in database-based Supybot plugins.""")))