Commit 04fc7879 authored by alexpott's avatar alexpott

Issue #2405691 by larowlan: CommentAccessControlHandler checks for an invalid...

Issue #2405691 by larowlan: CommentAccessControlHandler checks for an invalid setting (anonymous_contact)
parent 978116ea
......@@ -100,7 +100,7 @@ protected function checkFieldAccess($operation, FieldDefinitionInterface $field_
/** @var \Drupal\comment\CommentInterface $entity */
$entity = $items->getEntity();
$commented_entity = $entity->getCommentedEntity();
$anonymous_contact = $commented_entity->get($entity->getFieldName())->getFieldDefinition()->getSetting('anonymous_contact');
$anonymous_contact = $commented_entity->get($entity->getFieldName())->getFieldDefinition()->getSetting('anonymous');
$admin_access = AccessResult::allowedIfHasPermission($account, 'administer comments');
$anonymous_access = AccessResult::allowedIf($entity->isNew() && $account->isAnonymous() && $anonymous_contact != COMMENT_ANONYMOUS_MAYNOT_CONTACT && $account->hasPermission('post comments'))
->cachePerRole()
......
......@@ -40,7 +40,6 @@ class CommentFieldAccessTest extends EntityUnitTestBase {
'uid',
'status',
'created',
'name',
);
/**
......@@ -135,7 +134,8 @@ public function testAccessToAdministrativeFields() {
// Change the second field's anonymous contact setting.
$instance = FieldConfig::loadByName('entity_test', 'entity_test', 'comment_other');
$instance->settings['anonymous'] = COMMENT_ANONYMOUS_MAYNOT_CONTACT;
// Default is 'May not contact', for this field - they may contact.
$instance->settings['anonymous'] = COMMENT_ANONYMOUS_MAY_CONTACT;
$instance->save();
// Create three "Comments". One is owned by our edit-enabled user.
......@@ -263,7 +263,7 @@ public function testAccessToAdministrativeFields() {
$set['user']->isAnonymous() &&
$set['comment']->isNew() &&
$set['user']->hasPermission('post comments') &&
$set['comment']->getFieldName() != 'comment_other'
$set['comment']->getFieldName() == 'comment_other'
), String::format('User @user !state update field !field on comment @comment', [
'@user' => $set['user']->getUsername(),
'!state' => $may_update ? 'can' : 'cannot',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment