Skip to content

Commit

Permalink
OXDEV-8213 Set permission for themesList query
Browse files Browse the repository at this point in the history
  • Loading branch information
RahatHameed committed Jun 19, 2024
1 parent c6ec8d3 commit f6ad5e6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/Theme/Controller/ThemeListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use TheCodingMachine\GraphQLite\Annotations\Logged;
use TheCodingMachine\GraphQLite\Annotations\Query;
use OxidEsales\GraphQL\ConfigurationAccess\Theme\DataType\ThemeFilterList;
use TheCodingMachine\GraphQLite\Annotations\Right;

final class ThemeListController
{
Expand All @@ -29,6 +30,7 @@ public function __construct(
*/
#[Query]
#[Logged]
#[Right('CHANGE_CONFIGURATION')]
public function themesList(?ThemeFilterList $filters = null): array
{
return $this->themeListService->getThemeList($filters ?? new ThemeFilterList());
Expand Down
3 changes: 3 additions & 0 deletions tests/Codeception/Acceptance/NotAuthorizedAccessCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OxidEsales\GraphQL\ConfigurationAccess\Tests\Codeception\AcceptanceTester;

/**
* @group theme_list
* @group theme_setting
* @group setting_access
* @group oe_graphql_configuration_access
Expand Down Expand Up @@ -80,6 +81,7 @@ protected function themeGettersDataProvider(): \Generator
yield ['queryName' => 'themeSettingSelect', 'field' => 'name', 'location' => 'theme'];
yield ['queryName' => 'themeSettingCollection', 'field' => 'name', 'location' => 'theme'];
yield ['queryName' => 'themeSettingAssocCollection', 'field' => 'name', 'location' => 'theme'];
yield ['queryName' => 'themeSettingAssocCollection', 'field' => 'name', 'location' => 'theme'];
}

protected function themeMutationsDataProvider(): \Generator
Expand Down Expand Up @@ -123,6 +125,7 @@ protected function listQueriesDataProvider(): \Generator
yield ['queryName' => 'themeSettings', 'field' => 'name', 'location' => 'theme'];
yield ['queryName' => 'moduleSettings', 'field' => 'name', 'location' => 'module'];
yield ['queryName' => 'shopSettings', 'field' => 'name', 'location' => 'shop'];
yield ['queryName' => 'themesList', 'field' => 'title', 'location' => ''];
}

protected function moduleGettersDataProvider(): \Generator
Expand Down
29 changes: 19 additions & 10 deletions tests/Codeception/Acceptance/Theme/ThemeListCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,23 @@
*/
final class ThemeListCest extends BaseCest
{
public function testThemeList(AcceptanceTester $I): void
public function testThemeListAuthorized(AcceptanceTester $I): void
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());

$result = $this->runThemeListQuery($I);

$I->assertArrayNotHasKey('errors', $result);
$themeList = $result['data']['themesList'];
$I->assertCount(1, $themeList);

$I->assertEquals("APEX Theme", $themeList[0]['title']);
$I->assertEquals("apex", $themeList[0]['identifier']);
$I->assertEquals("APEX - Bootstrap 5 TWIG Theme", $themeList[0]['description']);
$I->assertTrue($themeList[0]['active']);
}

public function runThemeListQuery(AcceptanceTester $I): array
{
$I->login($this->getAdminUsername(), $this->getAdminPassword());
$I->sendGQLQuery(
Expand All @@ -43,15 +59,8 @@ public function testThemeList(AcceptanceTester $I): void
}
}'
);
$I->seeResponseIsJson();
$result = $I->grabJsonResponseAsArray();
$I->assertArrayNotHasKey('errors', $result);
$themeList = $result['data']['themesList'];
$I->assertCount(1, $themeList);

$I->assertEquals("APEX Theme", $themeList[0]['title']);
$I->assertEquals("apex", $themeList[0]['identifier']);
$I->assertEquals("APEX - Bootstrap 5 TWIG Theme", $themeList[0]['description']);
$I->assertTrue($themeList[0]['active']);
$I->seeResponseIsJson();
return $I->grabJsonResponseAsArray();
}
}

0 comments on commit f6ad5e6

Please sign in to comment.