예제 #1
0
    def delete_user(name=None):
        """Delete a User for good.

         Args:

            name: Name of the user to delete.

        Returns:

            True if user was deleted, False otherwise.
        """

        if name == AdminUser:
            return False, 'Cannot delete the %s user.' % AdminUser

        if not name:
            return False, 'Username was not provided.'

        try:

            user = Hierarchy.get_user(name)
            if not user:
                return False, 'Did not find user `%s`' % name

            deleted = actions.db_delete_by_secondary(
                collection=Collection.UsersPerCustomer,
                values=name,
                index=UsersPerCustomerKey.UserId)
            if not deleted:
                msg = 'Unable to delete users per customer.'
                logger.error(msg)

            deleted = actions.db_delete_by_secondary(
                collection=Collection.GroupsPerUser,
                values=name,
                index=GroupsPerUserKey.UserId)

            if not deleted:
                msg = 'Unable to delete group per user.'
                logger.error(msg)

            deleted = actions.db_delete(collection=Collection.Users, _id=name)

            if not deleted:
                msg = 'Unable to delete user `%s`' % name
                logger.error(msg)
                return False, msg

            return True, ''

        except Exception as e:

            logger.error("Unable to delete user `%s`" % name)
            logger.exception(e)

        return False, "Unable to delete user `%s`" % name
예제 #2
0
    def delete_customer(name=None):
        """Delete a Customer for good.

         Args:

            name: Name of the customer to delete.

        Returns:

            True if customer was deleted, False otherwise.
        """

        if not name:
            return False, "Customer name was not provided."

        if name == DefaultCustomer:
            return False, ("Can not delete the `%s` customer." %
                           DefaultCustomer)

        error_msg = "Unable to delete customer `%s`." % name

        try:

            if not Hierarchy.get_customer(name):
                return False, 'Did not find customer `%s`' % name

            deleted = actions.db_delete_by_secondary(
                collection=Collection.Groups,
                values=name,
                index=GroupKey.CustomerId)

            if not deleted:
                msg = 'Unable to delete groups from customer.'
                logger.error(msg)

            deleted = actions.db_delete_by_secondary(
                collection=Collection.UsersPerCustomer,
                values=name,
                index=UsersPerCustomerKey.CustomerId)

            if not deleted:
                msg = 'Unable to delete users from customer.'
                logger.error(msg)

            deleted = actions.db_delete(collection=Collection.Customers,
                                        _id=name)

            if not deleted:
                logger.error(error_msg)
                return False, error_msg

            Hierarchy._users_of_delete_customer(name)

            return True, ''

        except Exception as e:

            logger.error(error_msg)
            logger.exception(e)

        return False, error_msg