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

Fix taxonomy capabilities #7613

Merged
merged 6 commits into from
Jun 11, 2024
Merged

Fix taxonomy capabilities #7613

merged 6 commits into from
Jun 11, 2024

Conversation

renatho
Copy link
Contributor

@renatho renatho commented Jun 6, 2024

Proposed Changes

  • We received a report of Contributors (WordPress role) being able to access some taxonomy edit screens (/wp-admin/term.php?taxonomy=module&tag_ID=ID&post_type=course) directly through the edit URL, but not being able to save it.
    • The same applies for module, course-category, lesson-tag, and question-category.
  • In order to correct this behavior, updated the taxonomy capabilities and updated the roles to work properly. Notice that the only roles that have the manage_categories capability by default are admin and editor.. So adding the new roles to administrator, editor, and teacher looks a good solution to me.

Alternative approach

See #7613 (comment)

Context

The previous changes for the module taxonomy happened in this PR: #459

The first commit has the following description (the best context I could extract from the history):

give teacher access to modules on the edit course screen

Known issues

Testing Instructions

  1. Bump the version on SENSEI_LMS_VERSION, so the new capabilities are properly created.
  2. Create a module as admin.
  3. Edit the module and copy the URL of the editor.
  4. Try to access as a user with the role contributor, and make sure they don't have access to it anymore.

Now let's make sure everything continues working properly:

  1. As a teacher, create a course.
  2. Add some modules with lessons.
  3. Save the course, and make sure the modules were properly created.
  4. Add a new course category in the editor sidebar.
  5. Refresh the editor.
  6. It should create the new category, but don't assign it because of the known issue (Teacher can't add tags to lessons and categories to courses #7612).
  7. Add lessons.
  8. Open the lesson editor.
  9. Add a new lesson tag in the editor sidebar.
  10. Refresh the editor.
  11. It should create the new tag, but don't assign it because of the known issue (Teacher can't add tags to lessons and categories to courses #7612).
  12. Create a question.
  13. Add a category in the sidebar.
  14. Publish the question, and make sure the category was properly created.
  15. Create a new course, and remove all blocks to have a legacy course.
  16. Add a new module (sidebar).
  17. Create a lesson (meta boxes in the bottom of the editor).
  18. Add the module to a lesson and make sure it works properly.
  19. Repeat the tests with an admin and make sure it continues working properly.

Pre-Merge Checklist

  • PR title and description contain sufficient detail and accurately describe the changes
  • Acceptance criteria is met
  • Decisions are publicly documented
  • Adheres to coding standards (PHP, JavaScript, CSS, HTML)
  • All strings are translatable (without concatenation, handles plurals)
  • Follows our naming conventions (P6rkRX-4oA-p2)
  • Hooks (p6rkRX-1uS-p2) and functions are documented
  • New UIs are responsive and use a mobile-first approach
  • New UIs match the designs
  • Different user privileges (admin, teacher, subscriber) are tested as appropriate
  • Legacy courses (course without blocks) are tested
  • Code is tested on the minimum supported PHP and WordPress versions
  • User interface changes have been tested on the latest versions of Chrome, Firefox and Safari
  • "Needs Documentation" label is added if this change requires updates to documentation
  • Known issues are created as new GitHub issues

Copy link

github-actions bot commented Jun 6, 2024

Test the previous changes of this PR with WordPress Playground.

@renatho renatho force-pushed the fix/capability-issue branch from ec1b70e to 3e0bbe0 Compare June 6, 2024 19:38
Copy link

github-actions bot commented Jun 6, 2024

Test the previous changes of this PR with WordPress Playground.

Copy link

github-actions bot commented Jun 6, 2024

Test the previous changes of this PR with WordPress Playground.

@@ -1844,6 +1844,10 @@ public function add_editor_caps() {

if ( ! is_null( $role ) ) {
$role->add_cap( 'manage_sensei_grades' );

$role->add_cap( 'manage_lesson_categories' );
Copy link
Contributor Author

@renatho renatho Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admin and editor weren't receiving these capabilities previously. I think we didn't notice it before because we weren't explicitly using it, so it didn't cause any issue.

@@ -204,6 +204,7 @@ protected function add_capabilities() {

// Questions
'publish_questions' => true,
'manage_question_categories' => true,
Copy link
Contributor Author

@renatho renatho Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were already adding it for courses and lessons, but not for questions.

*
* @since 4.24.1
*/
private function v4_24_1_update_capabilities() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we changed capabilities, we need a migration to apply the changes. It only happens on the plugin activation.

@renatho renatho force-pushed the fix/capability-issue branch from 5860830 to e116930 Compare June 6, 2024 21:01
Copy link

github-actions bot commented Jun 6, 2024

Test the previous changes of this PR with WordPress Playground.

Copy link

github-actions bot commented Jun 6, 2024

Test the previous changes of this PR with WordPress Playground.

@@ -2180,9 +2180,9 @@ public function setup_modules_taxonomy() {
'hierarchical' => true,
'show_admin_column' => false,
'capabilities' => array(
Copy link
Contributor Author

@renatho renatho Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first try was to just remove the capabilities to use the default ones. It would use just use the manage_categories for edit_terms.

But since teachers don't have the capability manage_categories, it was hiding the buttons to add the categories through the editor sidebar.

@renatho renatho force-pushed the fix/capability-issue branch from e116930 to 64dd35f Compare June 6, 2024 21:13
Copy link

github-actions bot commented Jun 6, 2024

Test the previous changes of this PR with WordPress Playground.

@renatho renatho marked this pull request as ready for review June 6, 2024 21:45
@renatho renatho requested a review from a team June 6, 2024 21:45
@renatho renatho changed the title Update taxonomies to have the default capability Fix taxonomy capabilities Jun 6, 2024
@renatho
Copy link
Contributor Author

renatho commented Jun 7, 2024

I started it without a changelog entry because users probably won't notice that, but thinking more I decided to add an entry (bbc71c7), in case someone has special customizations with roles and capabilities.

Copy link

github-actions bot commented Jun 7, 2024

Test the previous changes of this PR with WordPress Playground.

@merkushin merkushin self-requested a review June 10, 2024 21:34
Copy link
Member

@merkushin merkushin left a 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 👍

I had three observations during the tests.

1. It is related to the test instructions.

CleanShot 2024-06-10 at 22 17 51@2x

It looks like I cannot follow the instruction not to assign the tag:
CleanShot 2024-06-10 at 22 19 09@2x

2. Course Outline in the lesson preview for teacher

I previewed the draft lesson as a teacher and found the course outline was empty. Checked in Safari and Chrome in case it was an issue with styles: same result.
And then tested with an admin account: everything is in its place.
CleanShot 2024-06-10 at 22 34 48@2x

3. Assign module in the lesson for a legacy course

I found that when I first open the lesson in the editor I can't assign the module. It says set the course first, even though it the course is set. But it works fine after saving the draft and refreshing.

@renatho
Copy link
Contributor Author

renatho commented Jun 11, 2024

Thank you for the review, @merkushin!

It looks like I cannot follow the instruction not to assign the tag

Do you mean you couldn't reproduce the known issue and after the refresh, the lesson tag persisted for you?

And then tested with an admin account: everything is in its place.

I think it's an expected behavior because of this:

$published_lessons_only = 'view' === $context && ! current_user_can( 'read_private_posts' );

But I agree that it could be better, offering the same behavior to teachers. Do you think it's worth an enhancement issue for it?

I found that when I first open the lesson in the editor I can't assign the module. It says set the course first, even though it the course is set. But it works fine after saving the draft and refreshing.

I believe it was aways the behavior. Since it's for the legacy way to do it, I think it's not worth an issue. WDYT?

@renatho renatho merged commit 982fbd4 into trunk Jun 11, 2024
23 checks passed
@renatho renatho deleted the fix/capability-issue branch June 11, 2024 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants