Пример #1
0
    def validate_update(self, user, current_user):
        """
        Validates required fields, username, verifies if the user
        exists, verifies that the user is not root and that belongs to
        ovsdb_user group
        Returns None when valid else returns error json dict
        """
        validation_result = self.__validate_required_fields__(user, OP_UPDATE)
        if validation_result is not None:
            return validation_result

        username = user.configuration.username
        validation_result = self.__validate_username__(username)
        if validation_result is not None:
            return validation_result

        if user_utils.user_exists(username):
            # Avoid update a root user
            if username == "root":
                error_message = "Permission denied."\
                                "Cannot update the root user."
                validation_result = to_json_error(error_message, None, None)
                return validation_result
            # Avoid update users from another group
            if not user_utils.check_user_group(username, DEFAULT_USER_GRP):
                error_message = "Unknown user %s" % username
                validation_result = to_json_error(error_message, None, None)
                return validation_result
        else:
            error_message = "User %s doesn't exists." % username
            validation_result = to_json_error(error_message, None, None)
            return validation_result

        return None
Пример #2
0
    def validate_create(self, user, current_user):
        """
        Validate required fields, username and if the user exists
        Returns None when valid else returns error json dict
        """
        validation_result = self.__validate_required_fields__(user, OP_CREATE)
        if validation_result is not None:
            return validation_result

        username = user.configuration.username
        validation_result = self.__validate_username__(username)
        if validation_result is not None:
            return validation_result

        if user_utils.user_exists(username):
            error_message = "User %s already exists" % username
            validation_result = to_json_error(error_message, None, None)
            return validation_result