Learn
Learn copied to clipboard
Feedback - Editors can't view modules and add lessons to modules when editing a course
Type of feedback
//dev
Description
Editors can't seem to add lessons to modules and view modules in the backend when editing courses in Sensei.
Step-by-step reproduction instructions (optional)
- Log in as Editor and go to https://learn.wordpress.org/wp-admin/post.php?post=56187&action=edit
Other information (optional)
Editors should be able to edit courses, modules and lessons to perform their role as content creators.
Hey @cynthianorman Could you add a screenshot of what you see when you Edit a course in Learn?
Thank you for your help @westnz
https://drive.google.com/file/d/1qM4GrxB9foRiOVTrLSKtH5eZqFs7VksN/view?usp=sharing https://drive.google.com/file/d/1EhLhHUdXAxqz8HkZTFaNzIbpuiY31Z0_/view?usp=sharing
I will need access in order to add lessons to modules
Thanks for looking into this issue, folks 🙌
@cynthianorman Until we can identify what's going on, I've made you an Administrator on https://learn.wordpress.org/. You should be able to proceed with content creation for now 😃
Thank you for your assistance @bsanevans
I don't know if it helps, but:
As an editor: Adding a module, without any course added Reload No module listed
Adding a module, with a course from author admin added Reload No module listed
Adding a module, with a course for admin added Reload Listed
Looking at the output of the course in the code editor, it appears modules have teacherIds assigned to them
<!-- wp:sensei-lms/course-outline-module {"id":54489,"title":"A brief overview of how WordPress works","description":"Understand how a web server powers a WordPress site, from the hardware stack through to the database. Review and follow a standard front-end and admin page request.","teacherId":18873666,"lastTitle":"A brief overview of how WordPress works","defaultTextColor":"white"} -->
I'm going to post this question to the Sensei development team and see if we can get their insights.
Hi folks!
Here is a snippet that could be used as a workaround for this.
add_action( 'plugins_loaded', function() {
if ( current_user_can( 'editor' ) ) {
remove_filter( 'get_terms', [ Sensei()->modules, 'filter_module_terms' ], 20, 3 );
remove_filter( 'get_object_terms', [ Sensei()->modules, 'filter_course_selected_terms' ], 20, 3 );
}
} );
Basically, it will remove this module restriction for editors, similar to what is done for administrators. 😉
Thanks @renatho, we'll see if we can implement this workaround in the coming weeks.
@unprintedch I have created #2364 to implement @renatho's suggested fix.
Do you think you would be able to test this out for us and see if this resolves the issue?
I'll take some time on that monday.
So with this the PR on my local environement the previous tests still give the same results The only way to keep it displayed is to add some courses from the current logged in user.
BUT!
add_action('admin_init', __NAMESPACE__ . '\wporg_correct_sensei_editor_permissions');
Changing the action to admin_init seems to work.
@renatho can you think of any possible negative outcomes to hooking your solution into admin_init vs plugins_loaded?
Hi @jonathanbossenger!
The filters are added when the Sensei plugin runs, independent of any hook. So, ideally, it would be as soon as possible to make sure it would remove the filters for any situation.
But if it's not working for some reason, and in your tests the issue was fixed, I think that's fine since it's a "controlled environment". If we see another issue related to this, we know that it could be related to this.
And if it's fine, I'd suggest another tweak to catch more cases. We could do it with the init
hook instead of the admin_init
. I didn't test it, but I suspect the admin_init
wouldn't be called in the REST APIs endpoints when saving modules through the editor. And it could also be in a low priority action just to have more chances to be removed before a code using it runs. Something like this:
add_action('init', __NAMESPACE__ . '\wporg_correct_sensei_editor_permissions', 1);
Thanks @renatho
@unprintedch would you like to go ahead and test Renatho's alternative solution?
On my local install, with that drop at the bottom of the functions.php
add_action( 'init', function() {
if ( current_user_can( 'editor' ) ) {
remove_filter( 'get_terms', [ Sensei()->modules, 'filter_module_terms' ], 20, 3 );
remove_filter( 'get_object_terms', [ Sensei()->modules, 'filter_course_selected_terms' ], 20, 3 );
}
} );
A teacher can see modules he create in every cases.
Excellent, thanks @unprintedch. I've updated #2364, and I will do my best to test it myself this week, in order to get it merged.