Skip to content

Added a published check, removed comments, and rearranged the code. #4

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

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from
Open
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
22 changes: 11 additions & 11 deletions unl_access.module
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,17 @@ function _unl_access_get_affiliations() {
function unl_access_node_grants(\Drupal\Core\Session\AccountInterface $account, $op) {
$grants = [];
// Always give the creator of the content owner grant access
$grants['unl access owner'][] = $account->getAccount()->id();
$affiliations = \Drupal::service('user.data')->get('unl_user', \Drupal::currentUser()->id(), 'eduPersonAffiliation');
if (!$affiliations) {
return $grants;
}
$grants['unl access affiliation'][] = UNL_AFFILIATION_ANY;
foreach ($affiliations as $affiliation) {
$grants['unl access affiliation'][] = _unl_access_get_grant_id_from_affiliation($affiliation);
if($account->getAccount()->id() !== 0) {
$grants['unl access owner'][] = $account->getAccount()->id();
}
$affiliations = \Drupal::service('user.data')->get('unl_user', \Drupal::currentUser()->id(), 'eduPersonAffiliation');
if ($affiliations) {
$grants['unl access affiliation'][] = UNL_AFFILIATION_ANY;
foreach ($affiliations as $affiliation) {
$grants['unl access affiliation'][] = _unl_access_get_grant_id_from_affiliation($affiliation);
}
}

return $grants;
}

Expand Down Expand Up @@ -103,7 +105,7 @@ function unl_access_node_access_records($node) {
);
}
// If we aren't assigning any grants to the node, assign drupal's public grant.
if (empty($grants)) {
if (empty($grants) && $node->isPublished()) {
$grants[] = [
'realm' => 'all',
'gid' => 0,
Expand Down Expand Up @@ -326,12 +328,10 @@ function unl_access_node_access($node, $op, \Drupal\Core\Session\AccountInterfac
foreach ($user_account_affiliations as $user_account_affiliation) {
foreach ($node_affiliations as $node_affiliation) {
if ($node_affiliation->affiliation == _unl_access_get_grant_id_from_affiliation($user_account_affiliation)) {
// return \Drupal\Core\Access\AccessResult::allowed();
return \Drupal\Core\Access\AccessResult::neutral();
}
// If the logged-in user has any UNL affiliation and the node has the UNL_AFFILIATION_ACCESS grant, grant access.
if ($node_affiliation->affiliation == UNL_AFFILIATION_ANY) {
// return \Drupal\Core\Access\AccessResult::allowed();
return \Drupal\Core\Access\AccessResult::neutral();
}
}
Expand Down