Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-66061

Fix get_comments WS

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.8
    • 3.7, 3.8
    • Comments
    • MOODLE_37_STABLE, MOODLE_38_STABLE
    • MOODLE_38_STABLE
    • MDL-66061-master
    • Hide
      1. Create a new course with just one section, create a new database module with comments enabled.
      2. Create a database record in the activity
      3. As a student and admin, add some comments to the record (comment1, comment2...)
      4. As admin, enable "Mobile services": Site administration ► Mobile app ► Mobile settings
      5. Create a Token for the user (student) your are going to test with:
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      6. Click add, select user and service (Mobile Service)
      7. Next, you can do a CURL REST call simulating a WS client:
        • You need to replace the wstoken and the URL of your moodle instance. And the following parameters:
          • instanceid with the course module id (it's the "id" in the URL when you access to the activity from course page)
          • itemid (it's the "rid" in the URL when you edit the created database record)

            curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'contextlevel=module&instanceid=84&component=mod_data&itemid=1&area=database_entry&page=0&wsfunction=core_comment_get_comments&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' --compressed

      8. Confirm that:
        • You receive a list including all the comments in the database record entry
        • The field count indicates the total number of comments
        • There is a field "perpage" set to 15
        • The newer comments are displayed first
      9. Now, append &sortdirection=ASC just after the wstoken value and execute the curl request again
      10. Confirm that:
        • The ordering has changed and now the older comments are displayed first
      Show
      Create a new course with just one section, create a new database module with comments enabled. Create a database record in the activity As a student and admin, add some comments to the record (comment1, comment2...) As admin, enable "Mobile services": Site administration ► Mobile app ► Mobile settings Create a Token for the user (student) your are going to test with: Click on Site administration ► Plugins ► Web services ► Manage tokens Click add, select user and service (Mobile Service) Next, you can do a CURL REST call simulating a WS client: You need to replace the wstoken and the URL of your moodle instance. And the following parameters: instanceid with the course module id (it's the "id" in the URL when you access to the activity from course page) itemid (it's the "rid" in the URL when you edit the created database record) curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'contextlevel=module&instanceid=84&component=mod_data&itemid=1&area=database_entry&page=0&wsfunction=core_comment_get_comments&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' --compressed Confirm that: You receive a list including all the comments in the database record entry The field count indicates the total number of comments There is a field "perpage" set to 15 The newer comments are displayed first Now, append &sortdirection=ASC just after the wstoken value and execute the curl request again Confirm that: The ordering has changed and now the older comments are displayed first

      core_comment_get_comments has some flaws that should be amended on a the same or a new WS.

      1. total comments is missing, that makes that we have to all the WS multiple times to know the total comments value.
      2. Pagination is not complete: it needs a perpage param or a loadmore boolean to know if we should call it again to obtain more results.
      3. Sorting is wrong. This can be amended on website or on WS. The problem is that the sorting is different in both cases. In website it uses timecreated ASC and in WS timecreated DESC. Pagination makes different comment showing on top so we cannot re-sort).

      About sorting: IMO it should be amended on website. JS rendering script is concatenating strings using html = (val+html);. This changes the sorting of the comments and makes pagination feel a bit strange: First page will show entries 3,4,5 and then second page will show 1,2. IMO it would be better to show: 5,4,3 and then 2,1. A new issue should be created if that seems reasonable. (Take numbers as creation date so 1 was created before 2).

       

            jleyva Juan Leyva
            pferre22 Pau Ferrer
            Pau Ferrer Pau Ferrer
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Janelle Barcega Janelle Barcega
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours, 36 minutes
                4h 36m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.