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

SHS-6029: Platform: "Reviewer" default role for viewing unpublished content #1746

Merged
merged 3 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions config/default/samlauth.authentication.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ map_users_name: true
map_users_mail: true
map_users_roles:
administrator: administrator
anonymous: anonymous
author: author
contributor: contributor
intranet_viewer: intranet_viewer
reviewer: reviewer
site_manager: site_manager
stanford_faculty: stanford_faculty
stanford_staff: stanford_staff
Expand Down
14 changes: 14 additions & 0 deletions config/default/system.action.user_add_role_action.reviewer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uuid: 29f38ba1-cd6c-46e9-b812-c8da33f153b9
langcode: en
status: true
dependencies:
config:
- user.role.reviewer
module:
- user
id: user_add_role_action.reviewer
label: 'Add the Reviewer role to the selected user(s)'
type: user
plugin: user_add_role_action
configuration:
rid: reviewer
14 changes: 14 additions & 0 deletions config/default/system.action.user_remove_role_action.reviewer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uuid: 6dcefb9f-bc00-4298-8c7c-ff0d78bfc923
langcode: en
status: true
dependencies:
config:
- user.role.reviewer
module:
- user
id: user_remove_role_action.reviewer
label: 'Remove the Reviewer role from the selected user(s)'
type: user
plugin: user_remove_role_action
configuration:
rid: reviewer
28 changes: 28 additions & 0 deletions config/default/user.role.reviewer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
uuid: 8b80d51d-80d4-4c69-8d7e-7e2ee1e42eb0
langcode: en
status: true
dependencies:
config:
- node.type.hs_basic_page
- node.type.hs_course
- node.type.hs_event
- node.type.hs_event_series
- node.type.hs_news
- node.type.hs_person
- node.type.hs_publications
- node.type.hs_research
module:
- view_unpublished
id: reviewer
label: Reviewer
weight: 0
is_admin: null
permissions:
- 'view any unpublished hs_basic_page content'
- 'view any unpublished hs_course content'
- 'view any unpublished hs_event content'
- 'view any unpublished hs_event_series content'
- 'view any unpublished hs_news content'
- 'view any unpublished hs_person content'
- 'view any unpublished hs_publications content'
- 'view any unpublished hs_research content'
Original file line number Diff line number Diff line change
Expand Up @@ -1196,3 +1196,31 @@ function su_humsci_profile_update_9721() {
'paragraphs_browser',
]);
}

/**
* Create reviewer role and assign permissions.
*/
function su_humsci_profile_update_9722() {
$config_name = 'user.role.reviewer';
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable($config_name);
if ($config->isNew()) {
$config_storage = \Drupal::service('config.storage.sync');
$reviewer_role_config = $config_storage->read($config_name);
$config->setData($reviewer_role_config)->save();

// There might be custom content types in the site, so we need to manually
// add permissions to view any unpublished content (expect Private Page).
$content_types = \Drupal::entityTypeManager()
->getStorage('node_type')
->loadMultiple();
// Exclude 'Private Page' content type.
$ct_no_private_page = array_filter(array_keys($content_types), function ($ct) {
return $ct !== 'hs_private_page';
});
$permissions = array_map(function ($ct) {
return "view any unpublished $ct content";
}, $ct_no_private_page);
user_role_grant_permissions('reviewer', $permissions);
}
}
Loading