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

New Web Service core_blog_get_entries

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.4.1, 3.6
    • Fix Version/s: 3.6
    • Component/s: Blog
    • Labels:
    • Testing Instructions:
      Hide
      1. Login as admin
      2. Enable blogs in Site administration > Advanced features
      3. Go to Site administration > Appearance > Blog and enable “Enable blog associations” and set Blog visibility to “The world can read entries set to be world accessible”
      4. Go to Site administration > Security > Site policies and ensure that “Force users to log in” is not checked
      5. Go to the Admin profile (click on his name at the top of the right) > Profile > Blog entries and then Add a new entry
      6. Add a new Blog entry including images in the Blog entry body and attachments. Ensure that “Publish to” is set to Anyone in the world
      7. In a different browser (or incognito tab) where you are not logged to the site open the page YOUR_SITE_URL/blog/index.php and check that you see the entry you created (including the images and attachments)
      8. Open the console and execute the following curl request replacing localhost/m/stable_master with your site URL

        curl 'http://localhost/m/stable_master/lib/ajax/service.php' --data-binary '[{"index":0,"methodname":"core_blog_get_entries","args":{}}]' | python -m "json.tool"

      9. Confirm that:
        • You receive a JSON structure and that in total entries you see 1,
        • In data->entries->attachmentfiles you see the files you attached,
        • In data->entries->summaryfiles you see the images you included in the post body
        • The subject and summary match the text you entered when you created the post
      10. Now, as admin create a new entry (follow step 5) but this time setting “Publish to” to “Anyone on this site”
      11. In a different browser (or incognito tab) where you are not logged to the site open the page YOUR_SITE_URL/blog/index.php and check that you don’t see the new entry created (because you are not logged to the site)
      12. In the console, execute again the CURL request and check that you steel see only 1 entry (the first entry you created, not the last one)
      13. Login to the site using a normal user account (not admin) go to YOUR_SITE_URL/blog/index.ph and check that you see the two posts you created so far
      14. As admin, enable "Mobile services": Site administration ► Mobile app ► Mobile settings
      15. Create a Token in the mobile app service for the user used two steps above (the one not admin you check that you see all the posts in blog/index.php)
        • Click on Site administration ► Plugins ► Web services ► Manage tokens
      16. Open the console an execute this new curl request, replacing wstoken with the token you just created and the site url with yours.

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_blog_get_entries&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' | python -m "json.tool"

      17. Confirm that:
        • You receive a JSON structure with the two entries
      18. Now, append the following &page=0&perpage=1 just after the wstoken, execute the curl request in the console
      19. Confirm that:
      20. You see the latest entry you created
      21. Replace page=0 with page=1, execute the curl request in the console
      22. Confirm that:
      23. You see the first entry you created
      24. Login as admin. Go to Site administration > Appearance > Blog and enable “Enable blog associations” and set Blog visibility to “all site users can see all blog entries”
      25. Open the console and execute the following request

        curl 'http://localhost/m/stable_master/lib/ajax/service.php' --data-binary '[{"index":0,"methodname":"core_blog_get_entries","args":{}}]' | python -m "json.tool"

      26. Confirm that:
        • You get an exception and the field exception.>errorcode is set to requireloginerror
      27. In a different browser (or incognito tab) where you are not logged to the site open the page YOUR_SITE_URL/blog/index.php and check that you are redirected to the log in page
      28. Open the console an execute this curl request, replacing wstoken with the token for the user you created and the site url with yours.

        curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_blog_get_entries&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' | python -m "json.tool"

      29. Confirm that you only see your latest entry (the first entry is not displayed anymore)
      30. Now, login as the user you created the token for creating a new entry (follow step 5) setting “Publish to” to “Anyone on this site”
      31. Execute the previous curl request and check that you receive two entries, including the one you just created.
      32. Now, append the following to the curl request: &filters[0][name]=userid&filters[0][value]=ADMIN_USER_ID (replacing ADMIN_USER_ID) with the id of the admin user
      33. In the console execute the curl request and check that you receive just one entry (the entry created by the admin user)
      34. Now, from the curl output annotate some where the entries->id
      35. Replace the user with other id belonging to a user who didn’t create entries
      36. Execute the curl request and check that you don’t receive anything
      37. In the curl request replace the &filters[0][name] “userid” value with “entryid” and the filters[0][value] with the entries->id you annotated
        # Execute the curl console and check that you retrieve successfully one entry whose entries->id matches the one annotated
      38. Login as admin, Go to a course in the site -> Turn editing on and add the block “BLOG MENU”
      39. Once the block is created click on the “Add an entry about this course” link and create a new blog entry
      40. In the curl request replace the &filters[0][name] “entryid” value with “courseid” and the filters[0][value] with the courseid where you created the blog
      41. Execute the curl request and check that you receive just the entry you created for that course
      42. Replace the courseid with other id belonging to a course where the block is not enabled
      43. Execute the curl request and check that you don’t receive anything
      Show
      Login as admin Enable blogs in Site administration > Advanced features Go to Site administration > Appearance > Blog and enable “Enable blog associations” and set Blog visibility to “The world can read entries set to be world accessible” Go to Site administration > Security > Site policies and ensure that “Force users to log in” is not checked Go to the Admin profile (click on his name at the top of the right) > Profile > Blog entries and then Add a new entry Add a new Blog entry including images in the Blog entry body and attachments. Ensure that “Publish to” is set to Anyone in the world In a different browser (or incognito tab) where you are not logged to the site open the page YOUR_SITE_URL/blog/index.php and check that you see the entry you created (including the images and attachments) Open the console and execute the following curl request replacing localhost/m/stable_master with your site URL curl 'http://localhost/m/stable_master/lib/ajax/service.php' --data-binary ' [{"index":0,"methodname":"core_blog_get_entries","args":{}}] ' | python -m "json.tool" Confirm that: You receive a JSON structure and that in total entries you see 1, In data->entries->attachmentfiles you see the files you attached, In data->entries->summaryfiles you see the images you included in the post body The subject and summary match the text you entered when you created the post Now, as admin create a new entry (follow step 5) but this time setting “Publish to” to “Anyone on this site” In a different browser (or incognito tab) where you are not logged to the site open the page YOUR_SITE_URL/blog/index.php and check that you don’t see the new entry created (because you are not logged to the site) In the console, execute again the CURL request and check that you steel see only 1 entry (the first entry you created, not the last one) Login to the site using a normal user account (not admin) go to YOUR_SITE_URL/blog/index.ph and check that you see the two posts you created so far As admin, enable "Mobile services": Site administration ► Mobile app ► Mobile settings Create a Token in the mobile app service for the user used two steps above (the one not admin you check that you see all the posts in blog/index.php) Click on Site administration ► Plugins ► Web services ► Manage tokens Open the console an execute this new curl request, replacing wstoken with the token you just created and the site url with yours. curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_blog_get_entries&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' | python -m "json.tool" Confirm that: You receive a JSON structure with the two entries Now, append the following &page=0&perpage=1 just after the wstoken, execute the curl request in the console Confirm that: You see the latest entry you created Replace page=0 with page=1, execute the curl request in the console Confirm that: You see the first entry you created Login as admin. Go to Site administration > Appearance > Blog and enable “Enable blog associations” and set Blog visibility to “all site users can see all blog entries” Open the console and execute the following request curl 'http://localhost/m/stable_master/lib/ajax/service.php' --data-binary ' [{"index":0,"methodname":"core_blog_get_entries","args":{}}] ' | python -m "json.tool" Confirm that: You get an exception and the field exception.>errorcode is set to requireloginerror In a different browser (or incognito tab) where you are not logged to the site open the page YOUR_SITE_URL/blog/index.php and check that you are redirected to the log in page Open the console an execute this curl request, replacing wstoken with the token for the user you created and the site url with yours. curl 'http://localhost/m/stable_master/webservice/rest/server.php?moodlewsrestformat=json' --data 'wsfunction=core_blog_get_entries&wstoken=a70d553bbaf6d9b260a9e5c701b3c46e' | python -m "json.tool" Confirm that you only see your latest entry (the first entry is not displayed anymore) Now, login as the user you created the token for creating a new entry (follow step 5) setting “Publish to” to “Anyone on this site” Execute the previous curl request and check that you receive two entries, including the one you just created. Now, append the following to the curl request: &filters [0] [name] =userid&filters [0] [value] =ADMIN_USER_ID (replacing ADMIN_USER_ID) with the id of the admin user In the console execute the curl request and check that you receive just one entry (the entry created by the admin user) Now, from the curl output annotate some where the entries->id Replace the user with other id belonging to a user who didn’t create entries Execute the curl request and check that you don’t receive anything In the curl request replace the &filters [0] [name] “userid” value with “entryid” and the filters [0] [value] with the entries->id you annotated # Execute the curl console and check that you retrieve successfully one entry whose entries->id matches the one annotated Login as admin, Go to a course in the site -> Turn editing on and add the block “BLOG MENU” Once the block is created click on the “Add an entry about this course” link and create a new blog entry In the curl request replace the &filters [0] [name] “entryid” value with “courseid” and the filters [0] [value] with the courseid where you created the blog Execute the curl request and check that you receive just the entry you created for that course Replace the courseid with other id belonging to a course where the block is not enabled Execute the curl request and check that you don’t receive anything
    • Affected Branches:
      MOODLE_34_STABLE, MOODLE_36_STABLE
    • Fixed Branches:
      MOODLE_36_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-60425-master

      Description

      New Web Service for retrieving blog entries

        Attachments

        1. 1.PNG
          1.PNG
          126 kB
        2. 2.PNG
          2.PNG
          191 kB
        3. 3.PNG
          3.PNG
          403 kB
        4. 4.PNG
          4.PNG
          212 kB
        5. 5.PNG
          5.PNG
          320 kB

          Issue Links

            Activity

              People

              • Votes:
                2 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  3/Dec/18

                  Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 1 hour, 10 minutes
                  1h 10m