From 413320addf7ef41dfde8989f90155f0487a5d47a Mon Sep 17 00:00:00 2001
From: William Hearn <sylus1984@gmail.com>
Date: Sun, 16 Jul 2017 11:04:51 -0400
Subject: [PATCH] Voting API: Getting an access denied or 403 response using
 GET method

---
 src/Entity/Vote.php                    |  1 +
 src/Entity/VoteResult.php              |  5 +++--
 src/VoteAccessControlHandler.php       | 40 ++++++++++++++++++++++++++++++++++
 src/VoteResultAccessControlHandler.php | 40 ++++++++++++++++++++++++++++++++++
 4 files changed, 84 insertions(+), 2 deletions(-)
 create mode 100644 src/VoteAccessControlHandler.php
 create mode 100644 src/VoteResultAccessControlHandler.php

diff --git a/src/Entity/Vote.php b/src/Entity/Vote.php
index 7e8ea06..16a1e5d 100644
--- a/src/Entity/Vote.php
+++ b/src/Entity/Vote.php
@@ -27,6 +27,7 @@ use Drupal\votingapi\VoteInterface;
  *   bundle_entity_type = "vote_type",
  *   handlers = {
  *     "storage" = "Drupal\votingapi\VoteStorage",
+ *     "access" = "Drupal\votingapi\VoteAccessControlHandler",
  *     "views_data" = "Drupal\votingapi\Entity\VoteViewsData",
  *   },
  *   base_table = "votingapi_vote",
diff --git a/src/Entity/VoteResult.php b/src/Entity/VoteResult.php
index f418d95..95c5fc7 100644
--- a/src/Entity/VoteResult.php
+++ b/src/Entity/VoteResult.php
@@ -23,6 +23,7 @@ use Drupal\votingapi\VoteResultInterface;
  *   label = @Translation("Vote Result"),
  *   handlers = {
  *     "storage" = "Drupal\votingapi\VoteResultStorage",
+ *     "access" = "Drupal\votingapi\VoteResultAccessControlHandler",
  *     "views_data" = "Drupal\votingapi\Entity\VoteResultViewsData",
  *   },
  *   base_table = "votingapi_result",
@@ -193,7 +194,7 @@ class VoteResult extends ContentEntityBase implements VoteResultInterface {
       ->setLabel(t('Function'))
       ->setDescription(t('Function to apply to the numbers.'))
       ->setSettings(array(
-        'max_length' => 50
+        'max_length' => 100
       ))
       ->setRequired(TRUE);
 
@@ -204,4 +205,4 @@ class VoteResult extends ContentEntityBase implements VoteResultInterface {
 
     return $fields;
   }
-}
\ No newline at end of file
+}
diff --git a/src/VoteAccessControlHandler.php b/src/VoteAccessControlHandler.php
new file mode 100644
index 0000000..521c8be
--- /dev/null
+++ b/src/VoteAccessControlHandler.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Drupal\votingapi;
+
+use Drupal\Core\Access\AccessResult;
+use Drupal\Core\Entity\EntityAccessControlHandler;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Field\FieldDefinitionInterface;
+use Drupal\Core\Field\FieldItemListInterface;
+use Drupal\Core\Session\AccountInterface;
+
+/**
+ * Defines the access control handler for the vote entity type.
+ *
+ * @see \Drupal\votingapi\Entity\Vote
+ */
+class VoteAccessControlHandler extends EntityAccessControlHandler {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
+    return AccessResult::allowed();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
+    return AccessResult::allowed();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
+    return AccessResult::allowed();
+  }
+
+}
diff --git a/src/VoteResultAccessControlHandler.php b/src/VoteResultAccessControlHandler.php
new file mode 100644
index 0000000..b9d84b4
--- /dev/null
+++ b/src/VoteResultAccessControlHandler.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Drupal\votingapi;
+
+use Drupal\Core\Access\AccessResult;
+use Drupal\Core\Entity\EntityAccessControlHandler;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Field\FieldDefinitionInterface;
+use Drupal\Core\Field\FieldItemListInterface;
+use Drupal\Core\Session\AccountInterface;
+
+/**
+ * Defines the access control handler for the vote entity type.
+ *
+ * @see \Drupal\votingapi\Entity\Vote
+ */
+class VoteResultAccessControlHandler extends EntityAccessControlHandler {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
+    return AccessResult::allowed();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
+    return AccessResult::allowed();
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function checkFieldAccess($operation, FieldDefinitionInterface $field_definition, AccountInterface $account, FieldItemListInterface $items = NULL) {
+    return AccessResult::allowed();
+  }
+
+}
-- 
2.5.4 (Apple Git-61)

