Пример #1
0
    def run(self, params={}):
        target_user = params.get('username')
        reassignee = params.get('reassignee')
        host = self.connection.host
        username = self.connection.username
        password = self.connection.password

        creds = helpers.encode_creds(username, password)

        users = helpers.get_users(host, creds, target_user)
        if not users: raise Exception('Run: No users found')

        r_users = helpers.get_users(host, creds, reassignee)
        if not r_users: raise Exception('Run: No reassignees found')

        user_id = None
        for user in users:
            if user['username'] == target_user:
                user_id = str(user['id'])

        if not user_id: raise Exception('Run: No user with that username')

        reassignee_id = None
        for user in r_users:
            if user['username'] == reassignee:
                reassignee_id = str(user['id'])

        if not reassignee_id:
            raise Exception('Run: No reassignee with that username')

        success = helpers.delete_user(host, creds, user_id, reassignee_id)
        if not success: raise Exception('Run: User was not deleted')
        return {'success': True}
Пример #2
0
    def run(self, params={}):
        target_user = params.get('username')
        host = self.connection.host
        username = self.connection.username
        password = self.connection.password

        creds = helpers.encode_creds(username, password)
        users = helpers.get_users(host, creds, target_user)

        if not users: raise Exception('Run: No users found')

        roles = []
        for user in users:
            if user['username'] == target_user:
                roles = user['roles']
                if not roles:
                    self.logger.info('Run: User already has no roles')
                    return {'success': True}
                url = host + 'wp/v2/users/' + str(user['id'])
                success = helpers.post_url(
                    url, json.dumps({'roles': []}), {
                        'Authorization': creds,
                        'Accept': 'application/json',
                        'Content-Type': 'application/json'
                    })
                if not success:
                    self.logger.error(
                        'Run: User was not suspended but API contacted')
                    break
                else:
                    self.logger.info('Run: User was suspended from roles: %s' %
                                     roles)
                    return {'success': True}
        return {'success': False}
Пример #3
0
    def test(self):
        """TODO: Test action"""
        host = self.connection.host
        username = self.connection.username
        password = self.connection.password

        creds = helpers.encode_creds(username, password)

        if not helpers.test_auth(host, creds):
            raise Exception('Test: Failed authentication')

        return {}
Пример #4
0
    def run(self, params={}):
        target_user = params.get("username")
        host = self.connection.host
        username = self.connection.username
        password = self.connection.password

        creds = helpers.encode_creds(username, password)
        users = helpers.get_users(host, creds, target_user)

        if not users:
            raise Exception("Run: No users found")

        roles = []
        for user in users:
            if user["username"] == target_user:
                roles = user["roles"]
                if not roles:
                    self.logger.info("Run: User already has no roles")
                    return {"success": True}
                url = host + "wp/v2/users/" + str(user["id"])
                success = helpers.post_url(
                    url,
                    json.dumps({"roles": []}),
                    {
                        "Authorization": creds,
                        "Accept": "application/json",
                        "Content-Type": "application/json",
                    },
                )
                if not success:
                    self.logger.error(
                        "Run: User was not suspended but API contacted")
                    break
                else:
                    self.logger.info("Run: User was suspended from roles: %s" %
                                     roles)
                    return {"success": True}
        return {"success": False}