From 18bb5964a992d5719e5a7e9d0cc83ec2b103154b Mon Sep 17 00:00:00 2001 From: Saron Gebre Date: Wed, 6 Nov 2024 09:07:56 -0600 Subject: [PATCH] Added a published check, removed comments, and rearranged the code. Fixes #2. --- unl_access.module | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/unl_access.module b/unl_access.module index cef983b..110e656 100644 --- a/unl_access.module +++ b/unl_access.module @@ -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; } @@ -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, @@ -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(); } }