Skip to content

Commit

Permalink
Merge pull request #1445 from bakaphp/development
Browse files Browse the repository at this point in the history
v1.0-BETA35
  • Loading branch information
kaioken committed Jun 6, 2024
2 parents 3e65984 + 01d2a52 commit 8c60a56
Show file tree
Hide file tree
Showing 74 changed files with 1,539 additions and 364 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ec2-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Deploy to EC2

on:
workflow_dispatch:

jobs:
deploy-to-ec2:
runs-on: ubuntu-latest
environment: ${{ github.ref_name }}
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Copy folder content recursively to remote VM
uses: appleboy/[email protected]
with:
host: ${{ secrets.AWS_EC2_HOST }}
username: ${{ secrets.AWS_EC2_USERNAME }}
key: ${{ secrets.AWS_EC2_PRIVATE_SSH_KEY }}
source: .
target: ${{secrets.AWS_EC2_TARGET_DIR}}
7 changes: 4 additions & 3 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ jobs:
DB_COMMERCE_USERNAME: root
DB_COMMERCE_PASSWORD: password
KANVAS_APP_ID: 059ddaaf-89b5-4158-a85a-90cbd69aa34b
APP_KEY: base64:4QZVysw1MIFmwZi0KvEOaHs0leAix3U6zueUZJtQYjY=
APP_JWT_TOKEN: 4QZVysw1MIFmwZi0KvEOaHs0leAix3U6zueUZJtQYjY4QZVysw1MIFmwZi0KvEOaHs0leAix3U6zueUZJtQYjY
APP_KEY: base64:Wm5KmkE4aWFjdFUzU2o3SElYNGc0QlpLcXNWR0hMME0=
APP_JWT_TOKEN: Wm5KmkE4aWFjdFUzU2o3SElYNGc0QlpLcXNWR0hMME0=4QZVysw1MIFmwZi0KvEOaHs0leAix3U6zueUZJtQYjYj
TOKEN_PASSWORD: base64:Z1dVYk5TcEZWUVhMNHZCUllIc3JQTVg0ZEdWTTh5eDg=
TOKEN_AUDIENCE: http://localhost
TOKEN_PASSWORD: base64:4QZVysw1MIFmwZi0KvEOaHs0leAix3U6zueUZJtQYjY=
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
Expand All @@ -56,6 +56,7 @@ jobs:
TEST_SHOPIFY_API_KEY: ${{ secrets.TEST_SHOPIFY_API_KEY }}
TEST_SHOPIFY_API_SECRET: ${{ secrets.TEST_SHOPIFY_API_SECRET }}
TEST_SHOPIFY_SHOP_URL: ${{ secrets.TEST_SHOPIFY_SHOP_URL }}
TEST_APPLE_LOGIN_TOKEN: ${{ secrets.TEST_APPLE_LOGIN_TOKEN }}
strategy:
fail-fast: false
matrix:
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ jobs:
DB_COMMERCE_USERNAME: root
DB_COMMERCE_PASSWORD: password
KANVAS_APP_ID: 059ddaaf-89b5-4158-a85a-90cbd69aa34b
APP_KEY: base64:4QZVysw1MIFmwZi0KvEOaHs0leAix3U6zueUZJtQYjY=
APP_JWT_TOKEN: 4QZVysw1MIFmwZi0KvEOaHs0leAix3U6zueUZJtQYjY4QZVysw1MIFmwZi0KvEOaHs0leAix3U6zueUZJtQYjY
APP_KEY: base64:Wm5KmkE4aWFjdFUzU2o3SElYNGc0QlpLcXNWR0hMME0=
APP_JWT_TOKEN: Wm5KmkE4aWFjdFUzU2o3SElYNGc0QlpLcXNWR0hMME0=4QZVysw1MIFmwZi0KvEOaHs0leAix3U6zueUZJtQYjYj
TOKEN_PASSWORD: base64:Z1dVYk5TcEZWUVhMNHZCUllIc3JQTVg0ZEdWTTh5eDg=
TOKEN_AUDIENCE: http://localhost
TOKEN_PASSWORD: base64:4QZVysw1MIFmwZi0KvEOaHs0leAix3U6zueUZJtQYjY=
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
Expand All @@ -64,6 +64,7 @@ jobs:
TEST_SHOPIFY_API_KEY: ${{ secrets.TEST_SHOPIFY_API_KEY }}
TEST_SHOPIFY_API_SECRET: ${{ secrets.TEST_SHOPIFY_API_SECRET }}
TEST_SHOPIFY_SHOP_URL: ${{ secrets.TEST_SHOPIFY_SHOP_URL }}
TEST_APPLE_LOGIN_TOKEN: ${{ secrets.TEST_APPLE_LOGIN_TOKEN }}
strategy:
fail-fast: false
matrix:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Todo:
- [x] CRM (in progress)
- [x] Social (in progress)
- [x] Workflow
- [ ] Action Engine
- [x] Action Engine
- [x] GraphQL Documentation (in progress)

## Prerequisites
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MailCaddieLabCommand extends Command
public function handle()
{
$this->info('Sending internal mail to Caddie Lab');
dump($this->argument('email'));
//dump($this->argument('email'));
$app = AppsRepository::findFirstByKey($this->argument('apps_id'));
$email = $this->argument('email');
MailCaddieLabJob::dispatch($app, $email);
Expand Down
1 change: 1 addition & 0 deletions app/Console/Commands/Guild/AgentsImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function handle(): void
[
'users_id' => $user->getId(),
'companies_id' => $company->getId(),
'apps_id' => $app->getId(),
],
[
'name' => $record['Agent Name'],
Expand Down
16 changes: 9 additions & 7 deletions app/GraphQL/Ecosystem/Mutations/Auth/AuthManagementMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Kanvas\Auth\Traits\AuthTrait;
use Kanvas\Auth\Traits\TokenTrait;
use Kanvas\Companies\Models\CompaniesBranches;
use Kanvas\Enums\AppEnums;
use Kanvas\Enums\AppSettingsEnums;
use Kanvas\Sessions\Models\Sessions;
use Kanvas\Users\Actions\SwitchCompanyBranchAction;
Expand Down Expand Up @@ -57,7 +58,7 @@ public function loginMutation(
])
);

return $user->createToken(name: 'kanvas-login', deviceId: $deviceId)->toArray();
return $user->createToken(name: AppEnums::DEFAULT_APP_JWT_TOKEN_NAME->getValue(), deviceId: $deviceId)->toArray();
}

/**
Expand Down Expand Up @@ -132,7 +133,7 @@ public function register(
$request = request();

$registeredUser = $user->execute();
$tokenResponse = $registeredUser->createToken('kanvas-login')->toArray();
$tokenResponse = $registeredUser->createToken(AppEnums::DEFAULT_APP_JWT_TOKEN_NAME->getValue())->toArray();

return [
'user' => $registeredUser,
Expand All @@ -151,7 +152,7 @@ public function refreshToken(mixed $rootValue, array $req): array
}
$user = UsersRepository::getByEmail($token->claims()->get('email'));

return $user->createToken('kanvas-login')->toArray();
return $user->createToken(AppEnums::DEFAULT_APP_JWT_TOKEN_NAME->getValue())->toArray();
}

/**
Expand All @@ -172,11 +173,12 @@ public function socialLogin(mixed $root, array $req): array
$data = $req['data'];
$token = $data['token'];
$provider = $data['provider'];
$user = SocialManager::getDriver($provider)->getUserFromToken($token);
$socialLogin = new SocialLoginAction($user, $provider);
$app = app(Apps::class);
$user = SocialManager::getDriver($provider, $app)->getUserFromToken($token);
$socialLogin = new SocialLoginAction($user, $provider, $app);

$loggedUser = $socialLogin->execute();
$tokenResponse = $loggedUser->createToken(name: 'kanvas-login')->toArray();
$tokenResponse = $loggedUser->createToken(name: AppEnums::DEFAULT_APP_JWT_TOKEN_NAME->getValue())->toArray();

return $tokenResponse;
}
Expand All @@ -195,7 +197,7 @@ public function forgot(
$user = new ForgotPasswordService();

$registeredUser = $user->forgot($request['data']['email']);
$tokenResponse = $registeredUser->createToken('kanvas-login')->toArray();
$tokenResponse = $registeredUser->createToken(AppEnums::DEFAULT_APP_JWT_TOKEN_NAME->getValue())->toArray();

$request = request();

Expand Down
10 changes: 8 additions & 2 deletions app/GraphQL/Guild/Mutations/Leads/LeadManagementMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\GraphQL\Guild\Mutations\Leads;

use Kanvas\Apps\Models\Apps;
use Kanvas\Guild\Leads\Actions\CreateLeadAction;
use Kanvas\Guild\Leads\Actions\CreateLeadAttemptAction;
use Kanvas\Guild\Leads\Actions\UpdateLeadAction;
Expand All @@ -19,17 +20,19 @@ class LeadManagementMutation
public function create(mixed $root, array $req): ModelsLead
{
$user = auth()->user();
$app = app(Apps::class);
$leadAttempt = new CreateLeadAttemptAction(
$req,
request()->headers->all(),
$user->getCurrentCompany(),
$app,
request()->ip(),
'API'
'API - Create'
);
$attempt = $leadAttempt->execute();

$createLead = new CreateLeadAction(
Lead::viaRequest($user, $req['input']),
Lead::viaRequest($user, $app, $req['input']),
$attempt
);
$lead = $createLead->execute();
Expand All @@ -40,7 +43,9 @@ public function create(mixed $root, array $req): ModelsLead
public function update(mixed $root, array $req): ModelsLead
{
$user = auth()->user();
$app = app(Apps::class);

//@todo get from app
$lead = ModelsLead::getByIdFromBranch(
$req['id'],
$user->getCurrentBranch()
Expand All @@ -50,6 +55,7 @@ public function update(mixed $root, array $req): ModelsLead
$req,
request()->headers->all(),
$user->getCurrentCompany(),
$app,
request()->ip(),
'API - Update'
);
Expand Down
3 changes: 2 additions & 1 deletion app/GraphQL/Guild/Mutations/Leads/ParticipantMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Kanvas\Guild\Leads\Actions\AddLeadParticipantAction;
use Kanvas\Guild\Leads\Actions\RemoveLeadParticipantAction;
use Kanvas\Guild\Leads\DataTransferObject\LeadsParticipant;
use Kanvas\Guild\Leads\Models\LeadParticipant;

class ParticipantMutation
{
Expand All @@ -19,7 +20,7 @@ public function add(mixed $root, array $req): bool

$action = new AddLeadParticipantAction($leadParticipant);

return $action->execute() instanceof LeadsParticipant;
return $action->execute() instanceof LeadParticipant;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\GraphQL\Guild\Mutations\Organizations;

use Kanvas\Apps\Models\Apps;
use Kanvas\Guild\Organizations\Actions\CreateOrganizationAction;
use Kanvas\Guild\Organizations\Actions\UpdateOrganizationAction;
use Kanvas\Guild\Organizations\DataTransferObject\Organization as DataTransferObjectOrganization;
Expand All @@ -18,10 +19,12 @@ public function create(mixed $root, array $req): Organization
{
$user = auth()->user();
$data = $req['input'];
$app = app(Apps::class);

$organizationData = new DataTransferObjectOrganization(
$user->getCurrentCompany(),
$user,
$app,
$data['name'],
$data['address'] ?? null
);
Expand All @@ -35,12 +38,14 @@ public function update(mixed $root, array $req): Organization
{
$user = auth()->user();
$data = $req['input'];
$app = app(Apps::class);

$organization = Organization::getByIdFromCompany((int) $req['id'], $user->getCurrentCompany());
$organization = Organization::getByIdFromCompanyApp((int) $req['id'], $user->getCurrentCompany(), $app);

$organizationData = new DataTransferObjectOrganization(
$user->getCurrentCompany(),
$user,
$app,
$data['name'],
$data['address'] ?? null
);
Expand All @@ -53,18 +58,21 @@ public function update(mixed $root, array $req): Organization
public function delete(mixed $root, array $req): bool
{
$user = auth()->user();
$app = app(Apps::class);

$organization = Organization::getByIdFromCompany((int) $req['id'], $user->getCurrentCompany());
$organization = Organization::getByIdFromCompanyApp((int) $req['id'], $user->getCurrentCompany(), $app);

return $organization->softDelete();
}

public function restore(mixed $root, array $req): bool
{
$user = auth()->user();
$app = app(Apps::class);

$organization = Organization::where('id', (int) $req['id'])
->where('companies_id', $user->getCurrentCompany()->getId())
->fromCompany($user->getCurrentCompany())
->fromApp($app)
->firstOrFail();

return $organization->restoreRecord();
Expand Down
39 changes: 39 additions & 0 deletions app/GraphQL/Guild/Mutations/Peoples/PeopleImportMutation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace App\GraphQL\Guild\Mutations\Peoples;

use Baka\Support\Str;
use Kanvas\Apps\Models\Apps;
use Kanvas\Companies\Models\Companies;
use Kanvas\Companies\Repositories\CompaniesRepository;
use Kanvas\Guild\Customers\Jobs\CustomerImporterJob;

class PeopleImportMutation
{
/**
* Create new customer
*/
public function import(mixed $root, array $req): string
{
$user = auth()->user();
$company = isset($req['companyId']) ? Companies::getById($req['companyId']) : $user->getCurrentCompany();

CompaniesRepository::userAssociatedToCompany(
$company,
$user
);

$jobUuid = Str::uuid()->toString();

CustomerImporterJob::dispatch(
$jobUuid,
$req['input'],
$company->branch,
$user,
app(Apps::class)
);
return $jobUuid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function create(mixed $root, array $req): ModelsPeople
'user' => $user,
'firstname' => $data['firstname'],
'middlename' => $data['middlename'] ?? null,
'lastname' => $data['lastname'],
'lastname' => $data['lastname'] ?? null,
'contacts' => Contact::collect($data['contacts'] ?? [], DataCollection::class),
'address' => Address::collect($data['address'] ?? [], DataCollection::class),
'id' => $data['id'] ?? 0,
Expand Down Expand Up @@ -60,7 +60,7 @@ public function update(mixed $root, array $req): ModelsPeople
'user' => $user,
'firstname' => $data['firstname'],
'middlename' => $data['middlename'] ?? null,
'lastname' => $data['lastname'],
'lastname' => $data['lastname'] ?? null,
'contacts' => Contact::collect($data['contacts'] ?? [], DataCollection::class),
'address' => Address::collect($data['address'] ?? [], DataCollection::class),
'id' => $people->getId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\GraphQL\Guild\Mutations\Pipelines;

use Kanvas\Apps\Models\Apps;
use Kanvas\Exceptions\ValidationException;
use Kanvas\Guild\Pipelines\Actions\CreatePipelineAction;
use Kanvas\Guild\Pipelines\Actions\UpdatePipelineAction;
Expand All @@ -20,11 +21,13 @@ public function create(mixed $root, array $req): ModelsPipeline
{
$user = auth()->user();
$branch = $user->getCurrentBranch();
$app = app(Apps::class);

$pipeline = new CreatePipelineAction(
Pipeline::viaRequest(
$user,
$branch,
$app,
$req['input']
)
);
Expand All @@ -38,6 +41,7 @@ public function update(mixed $root, array $req): ModelsPipeline
$company = $user->getCurrentCompany();
$branch = $user->getCurrentBranch();
$id = (int) $req['id'];
$app = app(Apps::class);

$pipeline = ModelsPipeline::getByIdFromCompany($id, $company);

Expand All @@ -46,6 +50,7 @@ public function update(mixed $root, array $req): ModelsPipeline
Pipeline::viaRequest(
$user,
$branch,
$app,
$req['input']
)
);
Expand Down
4 changes: 2 additions & 2 deletions app/GraphQL/Inventory/Mutations/Variants/Variants.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function addToWarehouse(mixed $root, array $req): VariantModel
$company = auth()->user()->getCurrentCompany();
$variant = VariantsRepository::getById((int) $req['id'], $company);

$warehouse = WarehouseRepository::getById((int) $req['input']['warehouse_id']);
$warehouse = WarehouseRepository::getById((int) $req['input']['id']);
if (isset($req['input']['status'])) {
$req['input']['status_id'] = StatusRepository::getById((int) $req['input']['status']['id'], $company)->getId();
}
Expand All @@ -153,7 +153,7 @@ public function updateVariantInWarehouse(mixed $root, array $req): VariantModel
$company = auth()->user()->getCurrentCompany();

$variant = VariantsRepository::getById((int) $req['id'], $company);
$warehouse = WarehouseRepository::getById((int) $req['input']['warehouse_id'], $company);
$warehouse = WarehouseRepository::getById((int) $req['input']['id'], $company);

return VariantService::updateWarehouseVariant($variant, $warehouse, $req['input']);
}
Expand Down
Loading

0 comments on commit 8c60a56

Please sign in to comment.