Example #1
0
        def add(self, irc, msg, args, user, capability):
            """<name|hostmask> <capability>

            Gives the user specified by <name> (or the user to whom <hostmask>
            currently maps) the specified capability <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 can only give out capabilities they have themselves (which
            # will depend on supybot.capabilities and its child default) but
            # generally means they can't mess with channel capabilities.
            if ircutils.strEqual(capability, 'owner'):
                irc.error('The "owner" capability can\'t be added in the bot.'
                          '  Use the supybot-adduser program (or edit the '
                          'users.conf file yourself) to add an owner '
                          'capability.')
                return
            if ircdb.isAntiCapability(capability) or \
               ircdb.checkCapability(msg.prefix, capability):
                user.addCapability(capability)
                ircdb.users.setUser(user)
                irc.replySuccess()
            else:
                irc.error('You can\'t add capabilities you don\'t have.')
Example #2
0
        def add(self, irc, msg, args, user, capability):
            """<name|hostmask> <capability>

            Gives the user specified by <name> (or the user to whom <hostmask>
            currently maps) the specified capability <capability>
            """
            # Ok, the concepts that are important with capabilities:
            #
            ### 1) No user should be able to elevate their 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 can only give out capabilities they have themselves (which
            # will depend on supybot.capabilities and its child default) but
            # generally means they can't mess with channel capabilities.
            if ircutils.strEqual(capability, 'owner'):
                irc.error(_('The "owner" capability can\'t be added in the '
                          'bot.  Use the supybot-adduser program (or edit the '
                          'users.conf file yourself) to add an owner '
                          'capability.'))
                return
            if ircdb.isAntiCapability(capability) or \
               ircdb.checkCapability(msg.prefix, capability):
                user.addCapability(capability)
                ircdb.users.setUser(user)
                irc.replySuccess()
            else:
                irc.error(_('You can\'t add capabilities you don\'t have.'))
Example #3
0
        def remove(self, irc, msg, args, user, capability):
            """<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)
Example #4
0
        def remove(self, irc, msg, args, user, capability):
            """<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)
Example #5
0
    def defaultcapability(self, irc, msg, args, action, capability):
        """{add|remove} <capability>

        Adds or removes (according to the first argument) <capability> from the
        default capabilities given to users (the configuration variable
        supybot.capabilities stores these).
        """
        if action == "add":
            conf.supybot.capabilities().add(capability)
            irc.replySuccess()
        elif action == "remove":
            try:
                conf.supybot.capabilities().remove(capability)
                irc.replySuccess()
            except KeyError:
                if ircdb.isAntiCapability(capability):
                    irc.error("That capability wasn't in " "supybot.capabilities.")
                else:
                    anticap = ircdb.makeAntiCapability(capability)
                    conf.supybot.capabilities().add(anticap)
                    irc.replySuccess()
Example #6
0
    def defaultcapability(self, irc, msg, args, action, capability):
        """{add|remove} <capability>

        Adds or removes (according to the first argument) <capability> from the
        default capabilities given to users (the configuration variable
        supybot.capabilities stores these).
        """
        if action == 'add':
            conf.supybot.capabilities().add(capability)
            irc.replySuccess()
        elif action == 'remove':
            try:
                conf.supybot.capabilities().remove(capability)
                irc.replySuccess()
            except KeyError:
                if ircdb.isAntiCapability(capability):
                    irc.error('That capability wasn\'t in '
                              'supybot.capabilities.')
                else:
                    anticap = ircdb.makeAntiCapability(capability)
                    conf.supybot.capabilities().add(anticap)
                    irc.replySuccess()
Example #7
0
 def testIsAntiCapability(self):
     self.assertFalse(ircdb.isAntiCapability('foo'))
     self.assertFalse(ircdb.isAntiCapability('#foo,bar'))
     self.assertTrue(ircdb.isAntiCapability('-foo'))
     self.assertTrue(ircdb.isAntiCapability('#foo,-bar'))
     self.assertTrue(ircdb.isAntiCapability('#foo.bar,-baz'))
Example #8
0
 def testIsAntiCapability(self):
     self.failIf(ircdb.isAntiCapability('foo'))
     self.failIf(ircdb.isAntiCapability('#foo,bar'))
     self.failUnless(ircdb.isAntiCapability('-foo'))
     self.failUnless(ircdb.isAntiCapability('#foo,-bar'))
     self.failUnless(ircdb.isAntiCapability('#foo.bar,-baz'))
Example #9
0
 def testIsAntiCapability(self):
     self.failIf(ircdb.isAntiCapability('foo'))
     self.failIf(ircdb.isAntiCapability('#foo,bar'))
     self.failUnless(ircdb.isAntiCapability('-foo'))
     self.failUnless(ircdb.isAntiCapability('#foo,-bar'))
     self.failUnless(ircdb.isAntiCapability('#foo.bar,-baz'))