mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-18 14:40:51 +01:00
User: if '@hostmask add' detects a conflict and the caller is the owner, tell them who the conflicting user is.
This commit is contained in:
parent
bd39debb48
commit
d656db454d
@ -321,6 +321,7 @@ class User(callbacks.Plugin):
|
|||||||
must be sent to the bot privately (not on a channel) since it may
|
must be sent to the bot privately (not on a channel) since it may
|
||||||
contain a password.
|
contain a password.
|
||||||
"""
|
"""
|
||||||
|
caller_is_owner = ircdb.checkCapability(msg.prefix, 'owner')
|
||||||
if not hostmask:
|
if not hostmask:
|
||||||
hostmask = msg.prefix
|
hostmask = msg.prefix
|
||||||
if not ircutils.isUserHostmask(hostmask):
|
if not ircutils.isUserHostmask(hostmask):
|
||||||
@ -335,15 +336,17 @@ class User(callbacks.Plugin):
|
|||||||
try:
|
try:
|
||||||
otherId = ircdb.users.getUserId(hostmask)
|
otherId = ircdb.users.getUserId(hostmask)
|
||||||
if otherId != user.id:
|
if otherId != user.id:
|
||||||
irc.error(_('That hostmask is already registered.'),
|
if caller_is_owner:
|
||||||
Raise=True)
|
err = _('That hostmask is already registered to %s.')
|
||||||
|
err %= otherId
|
||||||
|
else:
|
||||||
|
err = _('That hostmask is already registered.')
|
||||||
|
irc.error(err, Raise=True)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
if not user.checkPassword(password) and \
|
if not user.checkPassword(password) and \
|
||||||
not user.checkHostmask(msg.prefix):
|
not user.checkHostmask(msg.prefix) and \
|
||||||
if ircdb.checkCapability(msg.prefix, 'owner'):
|
not caller_is_owner:
|
||||||
u = ircdb.users.getUser(msg.prefix)
|
|
||||||
else:
|
|
||||||
irc.error(conf.supybot.replies.incorrectAuthentication(),
|
irc.error(conf.supybot.replies.incorrectAuthentication(),
|
||||||
Raise=True)
|
Raise=True)
|
||||||
try:
|
try:
|
||||||
@ -352,10 +355,14 @@ class User(callbacks.Plugin):
|
|||||||
irc.error(str(e), Raise=True)
|
irc.error(str(e), Raise=True)
|
||||||
try:
|
try:
|
||||||
ircdb.users.setUser(user)
|
ircdb.users.setUser(user)
|
||||||
except ircdb.DuplicateHostmask:
|
except ircdb.DuplicateHostmask as e:
|
||||||
user.removeHostmask(hostmask)
|
user.removeHostmask(hostmask)
|
||||||
irc.error(_('That hostmask is already registered.'),
|
if caller_is_owner:
|
||||||
Raise=True)
|
err = _('That hostmask is already registered to %s.') \
|
||||||
|
% e.args[0]
|
||||||
|
else:
|
||||||
|
err = _('That hostmask is already registered.')
|
||||||
|
irc.error(err, Raise=True)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
irc.error(str(e), Raise=True)
|
irc.error(str(e), Raise=True)
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
|
@ -40,6 +40,7 @@ class UserTestCase(PluginTestCase):
|
|||||||
plugins = ('User', 'Admin', 'Config')
|
plugins = ('User', 'Admin', 'Config')
|
||||||
prefix1 = 'somethingElse!user@host1.tld'
|
prefix1 = 'somethingElse!user@host1.tld'
|
||||||
prefix2 = 'EvensomethingElse!user@host2.tld'
|
prefix2 = 'EvensomethingElse!user@host2.tld'
|
||||||
|
prefix3 = 'Completely!Different@host3.tld__no_testcap__'
|
||||||
|
|
||||||
def testHostmaskList(self):
|
def testHostmaskList(self):
|
||||||
self.assertError('hostmask list')
|
self.assertError('hostmask list')
|
||||||
@ -67,14 +68,36 @@ class UserTestCase(PluginTestCase):
|
|||||||
self.assertResponse('whoami', 'bar', frm=self.prefix2)
|
self.assertResponse('whoami', 'bar', frm=self.prefix2)
|
||||||
self.assertNotError('hostmask add foo *!*@foobar/b',
|
self.assertNotError('hostmask add foo *!*@foobar/b',
|
||||||
frm=self.prefix1)
|
frm=self.prefix1)
|
||||||
|
|
||||||
self.assertResponse('hostmask add bar *!*@foobar/*',
|
self.assertResponse('hostmask add bar *!*@foobar/*',
|
||||||
'Error: That hostmask is already registered.',
|
'Error: That hostmask is already registered to foo.',
|
||||||
frm=self.prefix2)
|
frm=self.prefix2)
|
||||||
self.assertRegexp('hostmask list foo', '\*!\*@foobar/b',
|
self.assertRegexp('hostmask list foo', '\*!\*@foobar/b',
|
||||||
frm=self.prefix1)
|
frm=self.prefix1)
|
||||||
self.assertNotRegexp('hostmask list bar', 'foobar',
|
self.assertNotRegexp('hostmask list bar', 'foobar',
|
||||||
frm=self.prefix2)
|
frm=self.prefix2)
|
||||||
|
|
||||||
|
def testHostmaskOverlapPrivacy(self):
|
||||||
|
self.assertNotError('register foo passwd', frm=self.prefix1)
|
||||||
|
self.assertNotError('register bar passwd', frm=self.prefix3)
|
||||||
|
self.assertResponse('whoami', 'foo', frm=self.prefix1)
|
||||||
|
self.assertResponse('whoami', 'bar', frm=self.prefix3)
|
||||||
|
self.assertNotError('hostmask add foo *!*@foobar/b',
|
||||||
|
frm=self.prefix1)
|
||||||
|
|
||||||
|
ircdb.users.getUser('bar').addCapability('owner')
|
||||||
|
self.assertResponse('whoami', 'bar',
|
||||||
|
frm=self.prefix3)
|
||||||
|
self.assertResponse('capabilities', '[owner]',
|
||||||
|
frm=self.prefix3)
|
||||||
|
self.assertResponse('hostmask add *!*@foobar/*',
|
||||||
|
'Error: That hostmask is already registered to foo.',
|
||||||
|
frm=self.prefix3)
|
||||||
|
ircdb.users.getUser('bar').removeCapability('owner')
|
||||||
|
self.assertResponse('hostmask add *!*@foobar/*',
|
||||||
|
'Error: That hostmask is already registered.',
|
||||||
|
frm=self.prefix3)
|
||||||
|
|
||||||
|
|
||||||
def testHostmask(self):
|
def testHostmask(self):
|
||||||
self.assertResponse('hostmask', self.prefix)
|
self.assertResponse('hostmask', self.prefix)
|
||||||
|
@ -775,7 +775,7 @@ class UsersDictionary(utils.IterableMap):
|
|||||||
self.nextId = max(self.nextId, user.id)
|
self.nextId = max(self.nextId, user.id)
|
||||||
try:
|
try:
|
||||||
if self.getUserId(user.name) != user.id:
|
if self.getUserId(user.name) != user.id:
|
||||||
raise DuplicateHostmask(user.name)
|
raise DuplicateHostmask(user.name, user.name)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
for hostmask in user.hostmasks:
|
for hostmask in user.hostmasks:
|
||||||
@ -788,10 +788,10 @@ class UsersDictionary(utils.IterableMap):
|
|||||||
# raise an exception. So instead, we'll raise an
|
# raise an exception. So instead, we'll raise an
|
||||||
# exception, but be nice and give the offending hostmask
|
# exception, but be nice and give the offending hostmask
|
||||||
# back at the same time.
|
# back at the same time.
|
||||||
raise DuplicateHostmask(hostmask)
|
raise DuplicateHostmask(u.name, hostmask)
|
||||||
for otherHostmask in u.hostmasks:
|
for otherHostmask in u.hostmasks:
|
||||||
if ircutils.hostmaskPatternEqual(hostmask, otherHostmask):
|
if ircutils.hostmaskPatternEqual(hostmask, otherHostmask):
|
||||||
raise DuplicateHostmask(hostmask)
|
raise DuplicateHostmask(u.name, hostmask)
|
||||||
self.invalidateCache(user.id)
|
self.invalidateCache(user.id)
|
||||||
self.users[user.id] = user
|
self.users[user.id] = user
|
||||||
if flush:
|
if flush:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user