Skip to content

Commit 18bb596

Browse files
committed
Added a published check, removed comments, and rearranged the code. Fixes #2.
1 parent 9c01e35 commit 18bb596

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

unl_access.module

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,17 @@ function _unl_access_get_affiliations() {
5656
function unl_access_node_grants(\Drupal\Core\Session\AccountInterface $account, $op) {
5757
$grants = [];
5858
// Always give the creator of the content owner grant access
59-
$grants['unl access owner'][] = $account->getAccount()->id();
60-
$affiliations = \Drupal::service('user.data')->get('unl_user', \Drupal::currentUser()->id(), 'eduPersonAffiliation');
61-
if (!$affiliations) {
62-
return $grants;
63-
}
64-
$grants['unl access affiliation'][] = UNL_AFFILIATION_ANY;
65-
foreach ($affiliations as $affiliation) {
66-
$grants['unl access affiliation'][] = _unl_access_get_grant_id_from_affiliation($affiliation);
59+
if($account->getAccount()->id() !== 0) {
60+
$grants['unl access owner'][] = $account->getAccount()->id();
61+
}
62+
$affiliations = \Drupal::service('user.data')->get('unl_user', \Drupal::currentUser()->id(), 'eduPersonAffiliation');
63+
if ($affiliations) {
64+
$grants['unl access affiliation'][] = UNL_AFFILIATION_ANY;
65+
foreach ($affiliations as $affiliation) {
66+
$grants['unl access affiliation'][] = _unl_access_get_grant_id_from_affiliation($affiliation);
67+
}
6768
}
69+
6870
return $grants;
6971
}
7072

@@ -103,7 +105,7 @@ function unl_access_node_access_records($node) {
103105
);
104106
}
105107
// If we aren't assigning any grants to the node, assign drupal's public grant.
106-
if (empty($grants)) {
108+
if (empty($grants) && $node->isPublished()) {
107109
$grants[] = [
108110
'realm' => 'all',
109111
'gid' => 0,
@@ -326,12 +328,10 @@ function unl_access_node_access($node, $op, \Drupal\Core\Session\AccountInterfac
326328
foreach ($user_account_affiliations as $user_account_affiliation) {
327329
foreach ($node_affiliations as $node_affiliation) {
328330
if ($node_affiliation->affiliation == _unl_access_get_grant_id_from_affiliation($user_account_affiliation)) {
329-
// return \Drupal\Core\Access\AccessResult::allowed();
330331
return \Drupal\Core\Access\AccessResult::neutral();
331332
}
332333
// If the logged-in user has any UNL affiliation and the node has the UNL_AFFILIATION_ACCESS grant, grant access.
333334
if ($node_affiliation->affiliation == UNL_AFFILIATION_ANY) {
334-
// return \Drupal\Core\Access\AccessResult::allowed();
335335
return \Drupal\Core\Access\AccessResult::neutral();
336336
}
337337
}

0 commit comments

Comments
 (0)