Learn icon indicating copy to clipboard operation
Learn copied to clipboard

Feedback - Editors can't view modules and add lessons to modules when editing a course

Open westnz opened this issue 11 months ago • 16 comments

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)

  1. 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.

westnz avatar Mar 13 '24 07:03 westnz

Hey @cynthianorman Could you add a screenshot of what you see when you Edit a course in Learn?

westnz avatar Mar 13 '24 07:03 westnz

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

cynthianorman avatar Mar 13 '24 10:03 cynthianorman

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 😃

kaitohm avatar Mar 14 '24 00:03 kaitohm

Thank you for your assistance @bsanevans

cynthianorman avatar Mar 14 '24 11:03 cynthianorman

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

Image

unprintedch avatar Mar 28 '24 09:03 unprintedch

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.

jonathanbossenger avatar Apr 03 '24 08:04 jonathanbossenger

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. 😉

renatho avatar Apr 03 '24 17:04 renatho

Thanks @renatho, we'll see if we can implement this workaround in the coming weeks.

jonathanbossenger avatar Apr 03 '24 18:04 jonathanbossenger

@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?

jonathanbossenger avatar Apr 04 '24 07:04 jonathanbossenger

I'll take some time on that monday.

unprintedch avatar Apr 05 '24 13:04 unprintedch

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.

unprintedch avatar Apr 07 '24 15:04 unprintedch

@renatho can you think of any possible negative outcomes to hooking your solution into admin_init vs plugins_loaded?

jonathanbossenger avatar Apr 17 '24 08:04 jonathanbossenger

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);

renatho avatar Apr 17 '24 14:04 renatho

Thanks @renatho

@unprintedch would you like to go ahead and test Renatho's alternative solution?

jonathanbossenger avatar Apr 19 '24 06:04 jonathanbossenger

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.

unprintedch avatar Apr 21 '24 00:04 unprintedch

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.

jonathanbossenger avatar Apr 22 '24 09:04 jonathanbossenger