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

LOOP-904: Added permission to view notify users checkbox #274

Merged
merged 2 commits into from
Nov 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 config/sync/user.role.os2loop_user_administrator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ permissions:
- 'oauth authorize any consumers'
- 'oauth register any consumers'
- 'opt-in or out of tracking'
- 'os2loop see notify users option'
- 'os2loop send alert'
- 'publish any os2loop_documents_collection content'
- 'publish any os2loop_documents_document content'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ permissions:
- 'edit own os2loop_documents_document content'
- 'flag os2loop_upvote_correct_answer'
- 'menu view unpublished'
- 'os2loop see notify users option'
- 'os2loop send alert'
- 'publish any os2loop_documents_collection content'
- 'publish any os2loop_documents_document content'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'os2loop see notify users option':
title: 'See notify users option'
description: 'Whether the user can see notify users option on content'
restrict access: TRUE
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ services:
class: Drupal\os2loop_messages\Helper\Helper
arguments:
- '@Drupal\os2loop_settings\Settings'
- '@current_user'
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\comment\CommentInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\message\Entity\Message;
use Drupal\node\NodeInterface;
use Drupal\os2loop_settings\Settings;
Expand All @@ -22,11 +23,19 @@ class Helper extends ControllerBase {
*/
protected $config;

/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;

/**
* Constructor.
*/
public function __construct(Settings $settings) {
public function __construct(Settings $settings, AccountProxyInterface $currentUser) {
$this->config = $settings->getConfig('os2loop_subscriptions.settings');
$this->currentUser = $currentUser;
}

/**
Expand Down Expand Up @@ -144,6 +153,11 @@ public function formAlter(array &$form, string $form_id) {
if ($nodeSubscriptions[$contentType] !== $contentType) {
$form['os2loop_notify_users']['#access'] = FALSE;
}

// Hide field if user does not have permission to see it.
if (!$this->currentUser->hasPermission('os2loop see notify users option')) {
$form['os2loop_notify_users']['widget']['value']['#access'] = FALSE;
}
}
}
}
Expand Down