-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Api for removing multiple users from multiple courses #4976
Api for removing multiple users from multiple courses #4976
Conversation
/** | ||
* Check if the current user can add users to courses. | ||
* | ||
* @param WP_REST_Request $request Request object. | ||
* | ||
* @return bool | ||
* @return bool|WP_Error | ||
*/ | ||
public function batch_create_items_permissions_check( WP_REST_Request $request ): bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a better name for this method :)
Maybe batch_permissions_check
?
@@ -117,4 +117,45 @@ public function testAddUsersToCourses_RequestGiven_EnrolsUserForCourse() { | |||
$enrolment = Sensei_Course_Enrolment::get_course_instance( $course_id ); | |||
$this->assertTrue( $enrolment->is_enrolled( $user_id ) ); | |||
} | |||
|
|||
public function testRemoveUsersFromCoursesApi_AfterApiExecution_StudentsAreActuallyRemoved() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As Gabriel suggested in my PR, it might be a good idea to add tests for sad paths. WDYT?
Hmm, DELETE method doesn't work for me for some reason right now (I get 405 Not Allowed). I suppose that's because of Local configuration. I'll check it one more time a bit later. |
Hi @merkushin , Thanks for your suggestions. I've updated the PR accordingly, can you kindly take another look? I've also added a zip in the description that you can use with vscode's Thunder Client for testing the API |
The problem with executing custom requests (I mean custom methods, like DELETE) was somewhere in the Nginx configuration. I failed finding the exact problem, but solved it by switching from nginx to Apache. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and works well 👍
Fixes part of #4959
Changes proposed in this Pull Request
Add REST API endpoint to add users to courses
Testing instructions
Create a few users and a few courses
Enroll those users to those courses, either from the UI or by using the rest API here Add REST API for adding students to courses #4968
Get WP REST nonce (make sure you're logged in): http://devwp.local/wp-admin/admin-ajax.php?action=rest-nonce (replace devwp.local with your domain)
Copy Cookie name and value
Execute in terminal (replace WPNONCE, COOKIE-NAME & COOKIE-VALUE, USER_ID, COURSE_ID with actual values):
Make sure you get status code 200 and your users are removed from the courses.
If you use vscode's thunder client, you can import the following collection for testing the API. Change the URL and the variables as per your system config
thunder-collection_Sensei.json.zip