From cef7256c3e3a56b54f370dac1ad3482eebaedbb7 Mon Sep 17 00:00:00 2001 From: kaioken Date: Mon, 26 Feb 2024 18:50:37 -0400 Subject: [PATCH 1/4] fix; sponsor link --- .../Connectors/Zoho/Workflows/ZohoAgentActivity.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Domains/Connectors/Zoho/Workflows/ZohoAgentActivity.php b/src/Domains/Connectors/Zoho/Workflows/ZohoAgentActivity.php index ec2b42f92..a84fdcf66 100644 --- a/src/Domains/Connectors/Zoho/Workflows/ZohoAgentActivity.php +++ b/src/Domains/Connectors/Zoho/Workflows/ZohoAgentActivity.php @@ -114,10 +114,17 @@ protected function createAgent(AppInterface $app, ZohoService $zohoService, User } $sponsorsPage = $company->get('sponsors_page') ?? []; + $sponsorsPageLandingPages = $company->get('sponsors_page_landing') ?? []; $agentPage = $user->get('agent_website'); $agentPageUserId = $sponsorsPage[$agentPage] ?? null; + $agentPageLandingPage = $sponsorsPageLandingPages[$agentPage] ?? null; + + if ($agentPageLandingPage !== null) { + $user->set('landing_page', $agentPageLandingPage); + } + //@todo this is ugly , testing it out - if ($agentPageUserId) { + if ($agentPageUserId !== null) { try { $agentOwner = Agent::fromCompany($company)->where('users_id', $agentPageUserId)->firstOrFail(); $ownerMemberNumber = $agentOwner->member_id; @@ -129,7 +136,7 @@ protected function createAgent(AppInterface $app, ZohoService $zohoService, User } } - if ($companyDefaultUseRotation && $ownerMemberNumber === null) { + if ($companyDefaultUseRotation !== false && $ownerMemberNumber === null) { try { $rotation = LeadRotation::getByIdFromCompany($companyDefaultUseRotation, $company); $agentUser = $rotation->getAgent(); From 29ee126292f621c7f10a15a0dd555e046106a11c Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 27 Feb 2024 11:26:32 -0400 Subject: [PATCH 2/4] refact: region crud --- .../Inventory/Mutations/Regions/Region.php | 21 ++++++++----------- graphql/schemas/Ecosystem/city.graphql | 2 +- graphql/schemas/Ecosystem/country.graphql | 2 +- graphql/schemas/Ecosystem/currency.graphql | 21 +++++++++++++++++++ graphql/schemas/Ecosystem/states.graphql | 2 +- graphql/schemas/Inventory/region.graphql | 8 +++---- 6 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 graphql/schemas/Ecosystem/currency.graphql diff --git a/app/GraphQL/Inventory/Mutations/Regions/Region.php b/app/GraphQL/Inventory/Mutations/Regions/Region.php index c494d3389..4b53b2ac8 100644 --- a/app/GraphQL/Inventory/Mutations/Regions/Region.php +++ b/app/GraphQL/Inventory/Mutations/Regions/Region.php @@ -15,25 +15,25 @@ class Region /** * create. * - * @param mixed $root - * @param array $request - * * @return Regions */ public function create(mixed $root, array $request): RegionModel { $request = $request['input']; $currency = Currencies::findOrFail($request['currency_id']); + $user = auth()->user(); + if (! $user->isAppOwner()) { + unset($request['companies_id']); + } + $regionDto = RegionDto::viaRequest($request); - return (new CreateRegionAction($regionDto, auth()->user()))->execute(); + + return (new CreateRegionAction($regionDto, $user))->execute(); } /** * update. * - * @param mixed $root - * @param array $request - * * @return Regions */ public function update(mixed $root, array $request): RegionModel @@ -42,22 +42,19 @@ public function update(mixed $root, array $request): RegionModel $request = $request['input']; $region = RegionRepository::getById($id, auth()->user()->getCurrentCompany()); $region->update($request); + return $region; } /** * delete. - * - * @param mixed $root - * @param array $request - * - * @return bool */ public function delete(mixed $root, array $request): bool { $id = $request['id']; $region = RegionRepository::getById($id, auth()->user()->getCurrentCompany()); $region->delete(); + return true; } } diff --git a/graphql/schemas/Ecosystem/city.graphql b/graphql/schemas/Ecosystem/city.graphql index ad70d5f77..86759e8fd 100644 --- a/graphql/schemas/Ecosystem/city.graphql +++ b/graphql/schemas/Ecosystem/city.graphql @@ -17,7 +17,7 @@ extend type Query { city(id: Int!): Cities @find(model: "Kanvas\\Locations\\Models\\Cities") } -extend type Mutation { +extend type Mutation @guardByAppKey { createCities( name: String! latitude: Float! diff --git a/graphql/schemas/Ecosystem/country.graphql b/graphql/schemas/Ecosystem/country.graphql index eb27acac8..92533c3c3 100644 --- a/graphql/schemas/Ecosystem/country.graphql +++ b/graphql/schemas/Ecosystem/country.graphql @@ -57,7 +57,7 @@ input CreateCityInput { longitude: Float } -extend type Mutation { +extend type Mutation @guardByAppKey { createCountry( name: String! code: String! diff --git a/graphql/schemas/Ecosystem/currency.graphql b/graphql/schemas/Ecosystem/currency.graphql new file mode 100644 index 000000000..e02014bb5 --- /dev/null +++ b/graphql/schemas/Ecosystem/currency.graphql @@ -0,0 +1,21 @@ +type Currency { + id: Int! + code: String! + currency: String! +} + +extend type Query @guard { + currencies( + orderBy: _ @orderBy(columns: ["id", "country", "currency", "code"]) + where: _ + @whereConditions( + columns: [ + "country" + "currency" + "code" + "id" + ] + ) + ): [Currency!]! + @paginate(defaultCount: 25, model: "Kanvas\\Currencies\\Models\\Currencies") +} diff --git a/graphql/schemas/Ecosystem/states.graphql b/graphql/schemas/Ecosystem/states.graphql index b695ac2ed..f89544437 100644 --- a/graphql/schemas/Ecosystem/states.graphql +++ b/graphql/schemas/Ecosystem/states.graphql @@ -15,7 +15,7 @@ extend type Query { state(id: Int!): States @find(model: "\\Kanvas\\Locations\\Models\\States") } -extend type Mutation { +extend type Mutation @guardByAppKey { createState(countries_id: Int!, name: String!, code: String!): States @create(model: "\\Kanvas\\Locations\\Models\\States") updateState( diff --git a/graphql/schemas/Inventory/region.graphql b/graphql/schemas/Inventory/region.graphql index 4bb140f0a..73a68650f 100644 --- a/graphql/schemas/Inventory/region.graphql +++ b/graphql/schemas/Inventory/region.graphql @@ -3,7 +3,7 @@ type Region { companies_id: Int! currency_id: Int! companies: Company! @belongsTo(relation: "company") - currencies: Currency! + currencies: Currency! @belongsTo(relation: "currencies") uuid: String! name: String! slug: String! @@ -11,14 +11,12 @@ type Region { settings: String is_default: Boolean! } -type Currency { - id: Int! - name: String! -} + input RegionInput { currency_id: Int! name: String! slug: String + companies_id: Int short_slug: String! settings: String is_default: Int! From fb649968ea81bf153edebacf969982bcc41d15ad Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 27 Feb 2024 11:34:16 -0400 Subject: [PATCH 3/4] refact: region crud --- .../Ecosystem/CountriesGraphqlTest.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/GraphQL/Ecosystem/CountriesGraphqlTest.php b/tests/GraphQL/Ecosystem/CountriesGraphqlTest.php index 9ba57b195..547f02f21 100644 --- a/tests/GraphQL/Ecosystem/CountriesGraphqlTest.php +++ b/tests/GraphQL/Ecosystem/CountriesGraphqlTest.php @@ -4,6 +4,9 @@ namespace Tests\GraphQL\Ecosystem; +use Kanvas\AccessControlList\Enums\RolesEnums; +use Kanvas\Apps\Models\Apps; +use Kanvas\Enums\AppEnums; use Kanvas\Locations\Models\Countries; use Kanvas\Locations\Models\States; use Tests\TestCase; @@ -18,6 +21,9 @@ public function testCreate(): void $name = fake()->name; $stateName = fake()->name; $cityName = fake()->name; + $app = app(Apps::class); + $app->keys()->first()->user()->firstOrFail()->assign(RolesEnums::OWNER->value); + $response = $this->graphQL(/** @lang GraphQL */ ' mutation( $name: String! @@ -48,7 +54,11 @@ public function testCreate(): void 'name' => $name, 'stateName' => $stateName, 'cityName' => $cityName, - ])->assertJson([ + ], [], + [ + AppEnums::KANVAS_APP_KEY_HEADER->getValue() => $app->keys()->first()->client_secret_id, + ] + )->assertJson([ 'data' => [ 'createCountry' => [ 'name' => $name, @@ -97,6 +107,10 @@ public function testUpdate(): void { $country = Countries::orderBy('id', 'desc')->first(); $name = fake()->name; + $app = app(Apps::class); + $app->keys()->first()->user()->firstOrFail()->assign(RolesEnums::OWNER->value); + + $response = $this->graphQL(/** @lang GraphQL */ ' mutation( $id: ID! @@ -119,6 +133,9 @@ public function testUpdate(): void 'name' => $name, 'code' => $country->code, 'flag' => $country->flag, + ],[], + [ + AppEnums::KANVAS_APP_KEY_HEADER->getValue() => $app->keys()->first()->client_secret_id, ]); $this->assertArrayHasKey('data', $response); } From 973d2c717d8bc402434dac9d277afd83300830df Mon Sep 17 00:00:00 2001 From: kaioken Date: Tue, 27 Feb 2024 11:35:44 -0400 Subject: [PATCH 4/4] refact: region crud --- .../Ecosystem/CountriesGraphqlTest.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/GraphQL/Ecosystem/CountriesGraphqlTest.php b/tests/GraphQL/Ecosystem/CountriesGraphqlTest.php index 547f02f21..9e84a98d3 100644 --- a/tests/GraphQL/Ecosystem/CountriesGraphqlTest.php +++ b/tests/GraphQL/Ecosystem/CountriesGraphqlTest.php @@ -50,12 +50,14 @@ public function testCreate(): void flag } } - ', [ + ', + [ 'name' => $name, 'stateName' => $stateName, 'cityName' => $cityName, - ], [], - [ + ], + [], + [ AppEnums::KANVAS_APP_KEY_HEADER->getValue() => $app->keys()->first()->client_secret_id, ] )->assertJson([ @@ -128,15 +130,18 @@ public function testUpdate(): void name } } - ', [ + ', + [ 'id' => $country->id, 'name' => $name, 'code' => $country->code, 'flag' => $country->flag, - ],[], - [ + ], + [], + [ AppEnums::KANVAS_APP_KEY_HEADER->getValue() => $app->keys()->first()->client_secret_id, - ]); + ] + ); $this->assertArrayHasKey('data', $response); }