necodeIT / lb_planner_plugin

Moodle Plugin for the LB Planner app
Other
1 stars 0 forks source link

Server expecting boolean #5

Closed mcquenji closed 2 months ago

mcquenji commented 2 months ago

The following payload produces an error with the server complaining about an incorrect datatype.

[FINER] Services.Network.DioNetworkService: Sending POST request to https://projekte.tgm.ac.at/lbplaner4/webservice/rest/server.php with body: {courseid: 13, color: #ff37ca9e, shortname: TEST, enabled: true, wstoken: redacted, moodlewsrestformat: json, wsfunction: local_lbplanner_courses_update_course}, headers: {Content-Type: application/x-www-form-urlencoded}, queryParameters: null
Click to see error message ``` [WARNING] Datasources.MoodleCourse.StdMoodleCourseDatasource: Failed to update course ApiServiceException: Invalid parameter value detected (enabled => Invalid parameter value detected (Invalid external api parameter: the value is "true", the server was expecting "bool" type): Invalid external api parameter: the value is "true", the server was expecting "bool" type) (status code: 200) { exception: invalid_parameter_exception, errorcode: invalidparameter, message: Invalid parameter value detected (enabled => Invalid parameter value detected (Invalid external api parameter: the value is "true", the server was expecting "bool" type): Invalid external api parameter: the value is "true", the server was expecting "bool" type), debuginfo: enabled => Invalid parameter value detected (Invalid external api parameter: the value is "true", the server was expecting "bool" type): Invalid external api parameter: the value is "true", the server was expecting "bool" type } ```

iirc Moodle uses 0/1 to represent booleans, however when calling local_lbplanner_courses_get_all_courses I get an actual bool with false/true.

RiedleroD commented 2 months ago

yknow what I'm just gonna make a model class for course and unfuck this whole shit

I found the probable cause of this being in course_helper

public static function get_lbplanner_course(int $courseid, int $userid): stdClass {
        global $DB;
        return $DB->get_record(self::LBPLANNER_COURSE_TABLE, ['courseid' => $courseid, 'userid' => $userid]);
    }

yep, zero checking nor type conversion

RiedleroD commented 2 months ago

update: nope, seems like the DB also stores them as integers. I'm gonna continue implementing the model while trying to find the issue

mcquenji commented 2 months ago

The issue would be resolved if the API just returned 0/1. instead of false/true