From e9590b4072a0f6c6de22018deaa404e9f78c56eb Mon Sep 17 00:00:00 2001
From: Christoph Reiter <reiter.christoph@gmail.com>
Date: Wed, 27 Oct 2021 11:05:38 +0200
Subject: [PATCH] Remove roles

The roles have moved to the frontend bundle for now, which makes
them work for all API users, not jsut the ones that have a Person object
associated.

In the future we also don't want to expose the roles directly but
add one more layer, some kind of API "capabilities".
---
 src/Entity/PersonTrait.php            | 17 -----------------
 src/Service/DummyPersonProvider.php   | 17 -----------------
 src/TestUtils/DummyPersonProvider.php | 10 ----------
 tests/ExtTest.php                     | 13 -------------
 tests/PersonTest.php                  |  6 ------
 5 files changed, 63 deletions(-)

diff --git a/src/Entity/PersonTrait.php b/src/Entity/PersonTrait.php
index a363e39..761a5e0 100644
--- a/src/Entity/PersonTrait.php
+++ b/src/Entity/PersonTrait.php
@@ -42,12 +42,6 @@ trait PersonTrait
      */
     private $email;
 
-    /**
-     * @var array
-     * @Groups({"BasePerson:current-user"})
-     */
-    private $roles;
-
     /**
      * @var string
      * @ApiProperty(iri="http://schema.org/birthDate")
@@ -63,7 +57,6 @@ trait PersonTrait
     public function __construct()
     {
         $this->extraData = [];
-        $this->roles = [];
     }
 
     public function setIdentifier(string $identifier)
@@ -125,16 +118,6 @@ trait PersonTrait
         return $this->extraData[$key] ?? null;
     }
 
-    public function getRoles(): array
-    {
-        return $this->roles;
-    }
-
-    public function setRoles(array $roles)
-    {
-        $this->roles = $roles;
-    }
-
     public function getBirthDate(): ?string
     {
         return $this->birthDate;
diff --git a/src/Service/DummyPersonProvider.php b/src/Service/DummyPersonProvider.php
index 285268f..ca67953 100644
--- a/src/Service/DummyPersonProvider.php
+++ b/src/Service/DummyPersonProvider.php
@@ -63,21 +63,4 @@ class DummyPersonProvider implements PersonProviderInterface
     {
         $this->currentIdentifier = $identifier;
     }
-
-    public function getRolesForCurrentPerson(): array
-    {
-        if ($this->currentIdentifier === null) {
-            return [];
-        }
-
-        return $this->getCurrentPerson()->getRoles();
-    }
-
-    public function setRolesForCurrentPerson(array $roles): void
-    {
-        if ($this->currentIdentifier === null) {
-            return;
-        }
-        $this->getCurrentPerson()->setRoles($roles);
-    }
 }
diff --git a/src/TestUtils/DummyPersonProvider.php b/src/TestUtils/DummyPersonProvider.php
index 31c1290..62f2e10 100644
--- a/src/TestUtils/DummyPersonProvider.php
+++ b/src/TestUtils/DummyPersonProvider.php
@@ -52,14 +52,4 @@ class DummyPersonProvider implements PersonProviderInterface
     {
         $this->person->setIdentifier($identifier);
     }
-
-    public function getRolesForCurrentPerson(): array
-    {
-        return $this->person->getRoles();
-    }
-
-    public function setRolesForCurrentPerson(array $roles): void
-    {
-        $this->person->setRoles($roles);
-    }
 }
diff --git a/tests/ExtTest.php b/tests/ExtTest.php
index 9147388..5d25ff8 100644
--- a/tests/ExtTest.php
+++ b/tests/ExtTest.php
@@ -20,7 +20,6 @@ class ExtTest extends ApiTestCase
     {
         $person = new Person();
         $person->setIdentifier($user->getUserIdentifier());
-        $person->setRoles($user->getRoles());
         $personProvider = new DummyPersonProvider($person);
         $container = $client->getContainer();
         $container->set('test.PersonProviderInterface', $personProvider);
@@ -79,18 +78,6 @@ class ExtTest extends ApiTestCase
         $this->assertArrayHasKey('etag', $header);
     }
 
-    public function testGetPersonRoles()
-    {
-        $client = $this->withUser('foobar', ['ROLE'], '42');
-        $user = $this->getUser($client);
-        $this->withPerson($client, $user);
-        $response = $client->request('GET', '/base/people/foobar', ['headers' => [
-            'Authorization' => 'Bearer 42',
-        ]]);
-        $data = json_decode($response->getContent(), true, 512, JSON_THROW_ON_ERROR);
-        $this->assertEquals(['ROLE'], $data['roles']);
-    }
-
     public function testAuthChecks()
     {
         $client = self::createClient();
diff --git a/tests/PersonTest.php b/tests/PersonTest.php
index 1ea58f8..eb71385 100644
--- a/tests/PersonTest.php
+++ b/tests/PersonTest.php
@@ -21,10 +21,4 @@ class PersonTest extends TestCase
 
         $this->assertSame(null, $person->getExtraData('nope'));
     }
-
-    public function testRoles()
-    {
-        $person = new Person();
-        $this->assertSame([], $person->getRoles());
-    }
 }
-- 
GitLab