From 17535d7f23fa18b4641bbcc21efa5b161f9e67a9 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 18 Dec 2019 17:59:46 -0800 Subject: [PATCH] Store 'permission' property for each form --- ext/afform/core/CRM/Afform/AfformScanner.php | 1 + ext/afform/core/Civi/Api4/Afform.php | 3 +++ ext/afform/mock/ang/mockPage.aff.json | 2 +- ext/afform/mock/tests/phpunit/api/v4/AfformTest.php | 12 ++++++++---- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/ext/afform/core/CRM/Afform/AfformScanner.php b/ext/afform/core/CRM/Afform/AfformScanner.php index f0cc0f6f4d..61ac85c95e 100644 --- a/ext/afform/core/CRM/Afform/AfformScanner.php +++ b/ext/afform/core/CRM/Afform/AfformScanner.php @@ -138,6 +138,7 @@ class CRM_Afform_AfformScanner { 'title' => '', 'description' => '', 'is_public' => FALSE, + 'permission' => 'access CiviCRM', ]; $metaFile = $this->findFilePath($name, self::METADATA_FILE); diff --git a/ext/afform/core/Civi/Api4/Afform.php b/ext/afform/core/Civi/Api4/Afform.php index 9dc720ddf8..cca20d19d3 100644 --- a/ext/afform/core/Civi/Api4/Afform.php +++ b/ext/afform/core/Civi/Api4/Afform.php @@ -107,6 +107,9 @@ class Afform extends AbstractEntity { [ 'name' => 'server_route', ], + [ + 'name' => 'permission', + ], [ 'name' => 'layout', ], diff --git a/ext/afform/mock/ang/mockPage.aff.json b/ext/afform/mock/ang/mockPage.aff.json index 9b45e0bfbe..de1f8212ec 100644 --- a/ext/afform/mock/ang/mockPage.aff.json +++ b/ext/afform/mock/ang/mockPage.aff.json @@ -1 +1 @@ -{"server_route": "civicrm/mock-page", "requires":["extraMock"]} +{"server_route": "civicrm/mock-page", "requires":["extraMock"], "permission": "access Foobar" } diff --git a/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php b/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php index c8645bf17b..cd1af772d2 100644 --- a/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php +++ b/ext/afform/mock/tests/phpunit/api/v4/AfformTest.php @@ -30,10 +30,10 @@ class api_v4_AfformTest extends api_v4_AfformTestCase { public function getBasicDirectives() { return [ - ['mockPage', ['title' => '', 'description' => '', 'server_route' => 'civicrm/mock-page']], - ['mockBareFile', ['title' => '', 'description' => '']], - ['mockFoo', ['title' => '', 'description' => '']], - ['mock-weird-name', ['title' => 'Weird Name', 'description' => '']], + ['mockPage', ['title' => '', 'description' => '', 'server_route' => 'civicrm/mock-page', 'permission' => 'access Foobar']], + ['mockBareFile', ['title' => '', 'description' => '', 'permission' => 'access CiviCRM']], + ['mockFoo', ['title' => '', 'description' => '', 'permission' => 'access CiviCRM']], + ['mock-weird-name', ['title' => 'Weird Name', 'description' => '', 'permission' => 'access CiviCRM']], ]; } @@ -58,6 +58,7 @@ class api_v4_AfformTest extends api_v4_AfformTestCase { $this->assertEquals($get($originalMetadata, 'title'), $get($result[0], 'title'), $message); $this->assertEquals($get($originalMetadata, 'description'), $get($result[0], 'description'), $message); $this->assertEquals($get($originalMetadata, 'server_route'), $get($result[0], 'server_route'), $message); + $this->assertEquals($get($originalMetadata, 'permission'), $get($result[0], 'permission'), $message); $this->assertTrue(is_array($result[0]['layout']), $message); $this->assertEquals(TRUE, $get($result[0], 'has_packaged'), $message); $this->assertEquals(FALSE, $get($result[0], 'has_local'), $message); @@ -66,6 +67,7 @@ class api_v4_AfformTest extends api_v4_AfformTestCase { $result = Civi\Api4\Afform::update() ->addWhere('name', '=', $formName) ->addValue('description', 'The temporary description') + ->addValue('permission', 'access foo') ->execute(); $this->assertEquals($formName, $result[0]['name'], $message); $this->assertEquals('The temporary description', $result[0]['description'], $message); @@ -76,6 +78,7 @@ class api_v4_AfformTest extends api_v4_AfformTestCase { $this->assertEquals($get($originalMetadata, 'title'), $get($result[0], 'title'), $message); $this->assertEquals('The temporary description', $get($result[0], 'description'), $message); $this->assertEquals($get($originalMetadata, 'server_route'), $get($result[0], 'server_route'), $message); + $this->assertEquals('access foo', $get($result[0], 'permission'), $message); $this->assertTrue(is_array($result[0]['layout']), $message); $this->assertEquals(TRUE, $get($result[0], 'has_packaged'), $message); $this->assertEquals(TRUE, $get($result[0], 'has_local'), $message); @@ -87,6 +90,7 @@ class api_v4_AfformTest extends api_v4_AfformTestCase { $this->assertEquals($get($originalMetadata, 'title'), $get($result[0], 'title'), $message); $this->assertEquals($get($originalMetadata, 'description'), $get($result[0], 'description'), $message); $this->assertEquals($get($originalMetadata, 'server_route'), $get($result[0], 'server_route'), $message); + $this->assertEquals($get($originalMetadata, 'permission'), $get($result[0], 'permission'), $message); $this->assertTrue(is_array($result[0]['layout']), $message); $this->assertEquals(TRUE, $get($result[0], 'has_packaged'), $message); $this->assertEquals(FALSE, $get($result[0], 'has_local'), $message); -- 2.25.1