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
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions includes/class-sensei-data-cleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class Sensei_Data_Cleaner {
// Teacher caps.
'manage_lesson_categories',
'manage_course_categories',
'manage_question_categories',
'publish_quizzes',
'edit_quizzes',
'edit_published_quizzes',
Expand Down
6 changes: 0 additions & 6 deletions includes/class-sensei-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -2179,12 +2179,6 @@ public function setup_modules_taxonomy() {
'public' => true,
'hierarchical' => true,
'show_admin_column' => false,
'capabilities' => array(
'manage_terms' => 'manage_categories',
'edit_terms' => 'edit_courses',
'delete_terms' => 'manage_categories',
'assign_terms' => 'edit_courses',
),
'show_in_nav_menus' => false,
'show_in_quick_edit' => false,
'show_ui' => true,
Expand Down
10 changes: 2 additions & 8 deletions includes/class-sensei-posttypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ public function setup_course_category_taxonomy() {
'show_in_nav_menus' => true,
'capabilities' => array(
'manage_terms' => 'manage_categories',
'edit_terms' => 'edit_courses',
'edit_terms' => 'manage_course_categories',
'delete_terms' => 'manage_categories',
'assign_terms' => 'edit_courses',
),
Expand Down Expand Up @@ -840,7 +840,7 @@ public function setup_question_category_taxonomy() {
'show_in_rest' => true,
'capabilities' => array(
'manage_terms' => 'manage_categories',
'edit_terms' => 'edit_questions',
'edit_terms' => 'manage_question_categories',
'delete_terms' => 'manage_categories',
'assign_terms' => 'edit_questions',
),
Expand Down Expand Up @@ -891,12 +891,6 @@ public function setup_lesson_tag_taxonomy() {
'show_ui' => true,
'query_var' => true,
'show_in_nav_menus' => true,
'capabilities' => array(
'manage_terms' => 'manage_categories',
'edit_terms' => 'edit_lessons',
'delete_terms' => 'manage_categories',
'assign_terms' => 'edit_lessons',
),
'rewrite' => array(
/**
* Filter the rewrite slug for the lesson tag taxonomy.
Expand Down
1 change: 1 addition & 0 deletions includes/class-sensei-teacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

'edit_questions' => true,
'edit_published_questions' => true,
'edit_private_questions' => true,
Expand Down
15 changes: 15 additions & 0 deletions includes/class-sensei-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,26 @@ public function run_updates() {
$this->v4_10_update_install_time();
$this->v4_12_create_default_emails();
$this->v4_19_2_update_legacy_quiz_data();
$this->v4_24_1_update_capabilities();

// Flush rewrite cache.
Sensei()->initiate_rewrite_rules_flush();
}

/**
* Update capabilities.
*
* @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.

// Add new `manage_question_categories` capabilitiy to teacher.
Sensei()->teacher->create_role();

// Update the other roles capabilities.
Sensei()->add_sensei_admin_caps();
Sensei()->add_editor_caps();
}

/**
* Enqueue job to update the legacy quiz data.
*
Expand Down
8 changes: 8 additions & 0 deletions includes/class-sensei.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.

$role->add_cap( 'manage_course_categories' );
$role->add_cap( 'manage_question_categories' );
}

return true;
Expand All @@ -1860,6 +1864,10 @@ public function add_sensei_admin_caps() {
if ( ! is_null( $role ) ) {
$role->add_cap( 'manage_sensei' );
$role->add_cap( 'manage_sensei_grades' );

$role->add_cap( 'manage_lesson_categories' );
$role->add_cap( 'manage_course_categories' );
$role->add_cap( 'manage_question_categories' );
}

return true;
Expand Down
Loading