@@ -56,15 +56,17 @@ function _unl_access_get_affiliations() {
56
56
function unl_access_node_grants(\Drupal\Core\Session\AccountInterface $account, $op) {
57
57
$grants = [];
58
58
// 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
+ }
67
68
}
69
+
68
70
return $grants;
69
71
}
70
72
@@ -103,7 +105,7 @@ function unl_access_node_access_records($node) {
103
105
);
104
106
}
105
107
// 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() ) {
107
109
$grants[] = [
108
110
'realm' => 'all',
109
111
'gid' => 0,
@@ -326,12 +328,10 @@ function unl_access_node_access($node, $op, \Drupal\Core\Session\AccountInterfac
326
328
foreach ($user_account_affiliations as $user_account_affiliation) {
327
329
foreach ($node_affiliations as $node_affiliation) {
328
330
if ($node_affiliation->affiliation == _unl_access_get_grant_id_from_affiliation($user_account_affiliation)) {
329
- // return \Drupal\Core\Access\AccessResult::allowed();
330
331
return \Drupal\Core\Access\AccessResult::neutral();
331
332
}
332
333
// If the logged-in user has any UNL affiliation and the node has the UNL_AFFILIATION_ACCESS grant, grant access.
333
334
if ($node_affiliation->affiliation == UNL_AFFILIATION_ANY) {
334
- // return \Drupal\Core\Access\AccessResult::allowed();
335
335
return \Drupal\Core\Access\AccessResult::neutral();
336
336
}
337
337
}
0 commit comments