Skip to content
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

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

Open
westnz opened this issue Mar 13, 2024 · 16 comments · May be fixed by #2364
Open

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

westnz opened this issue Mar 13, 2024 · 16 comments · May be fixed by #2364
Assignees
Labels
[Component] Environment Website development issues related to Learn's local environment, or needs Meta team involvement. [Type] Bug Something isn't working on the Learn website.

Comments

@westnz
Copy link
Collaborator

westnz commented Mar 13, 2024

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 westnz added the Awaiting Triage Issues awaiting triage. See Training Team handbook for how to triage issues. label Mar 13, 2024
@github-actions github-actions bot added the [Type] Bug Something isn't working on the Learn website. label Mar 13, 2024
@westnz
Copy link
Collaborator Author

westnz commented Mar 13, 2024

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

@westnz westnz changed the title Feedback - Editor user can't view modules and add lessons to modules in a course Feedback - Editors can't view modules and add lessons to modules when editing courses Mar 13, 2024
@westnz westnz changed the title Feedback - Editors can't view modules and add lessons to modules when editing courses Feedback - Editors can't view modules and add lessons to modules when editing a course Mar 13, 2024
@cynthianorman
Copy link
Contributor

cynthianorman commented Mar 13, 2024

@bsanevans
Copy link
Contributor

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 😃

@jonathanbossenger jonathanbossenger added [Component] Environment Website development issues related to Learn's local environment, or needs Meta team involvement. and removed Awaiting Triage Issues awaiting triage. See Training Team handbook for how to triage issues. labels Mar 14, 2024
@cynthianorman
Copy link
Contributor

Thank you for your assistance @bsanevans

@unprintedch
Copy link

unprintedch commented Mar 28, 2024

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

@jonathanbossenger
Copy link
Collaborator

jonathanbossenger commented Apr 3, 2024

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.

@renatho
Copy link

renatho commented Apr 3, 2024

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

@jonathanbossenger
Copy link
Collaborator

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

@jonathanbossenger
Copy link
Collaborator

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

@unprintedch
Copy link

I'll take some time on that monday.

@unprintedch
Copy link

unprintedch commented Apr 7, 2024

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.

@jonathanbossenger
Copy link
Collaborator

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

@renatho
Copy link

renatho commented Apr 17, 2024

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

@jonathanbossenger
Copy link
Collaborator

Thanks @renatho

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

@unprintedch
Copy link

unprintedch commented Apr 21, 2024

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.

@jonathanbossenger
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Component] Environment Website development issues related to Learn's local environment, or needs Meta team involvement. [Type] Bug Something isn't working on the Learn website.
Projects
Status: To do
Development

Successfully merging a pull request may close this issue.

6 participants