Skip to content

Commit

Permalink
Merge pull request #1531 from bakaphp/development
Browse files Browse the repository at this point in the history
Version 1.0 Stable - Release for amazon EC2 deploy
  • Loading branch information
kaioken authored Jun 24, 2024
2 parents b7bc5f5 + 9854326 commit e904aa1
Show file tree
Hide file tree
Showing 68 changed files with 1,365 additions and 805 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

- id: docker-push-tagged
name: Tag Docker image and push to Google Artifact Registry
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
push: true
file: ${{ github.ref_name }}.Dockerfile
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ec2-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Deploy to EC2
on:
push:
branches:
- '1.x'
- 'development'

workflow_dispatch:
Expand Down Expand Up @@ -39,7 +40,7 @@ jobs:
key: ${{ secrets.AWS_EC2_PRIVATE_SSH_KEY }}
script: |
cd ${{secrets.AWS_EC2_TARGET_DIR}}
docker compose -f docker-compose.dev.yml up -d
docker compose -f docker-compose.${{ github.ref_name }}.yml up -d
docker exec -i phpkanvas-ecosystem php artisan lighthouse:cache
docker exec -i phpkanvas-ecosystem php artisan config:cache
docker restart queue
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ jobs:
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 }}
TEST_APOLLO_KEY: ${{ secrets.TEST_APOLLO_KEY }}
strategy:
fail-fast: false
matrix:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ jobs:
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 }}
TEST_APOLLO_KEY: ${{ secrets.TEST_APOLLO_KEY }}
strategy:
fail-fast: false
matrix:
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cSpell.words": [
"hashtable",
"indice",
"Meili",
"Nuwave"
]
Expand Down
6 changes: 3 additions & 3 deletions app/Console/Commands/KanvasAppCreateKeyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class KanvasAppCreateKeyCommand extends Command
*
* @var string
*/
protected $signature = 'kanvas:app-key {name} {app_uuid} {email}';
protected $signature = 'kanvas:app-key {name} {app_id} {email}';

/**
* The console command description.
Expand All @@ -36,9 +36,9 @@ public function handle()
{
$name = $this->argument('name');
$email = $this->argument('email');
$appUid = $this->argument('app_uuid');
$appId = $this->argument('app_id');

$app = Apps::getByUuid($appUid);
$app = Apps::getById($appId);
$user = Users::getByEmail($email);

UsersRepository::belongsToThisApp($user, $app);
Expand Down
75 changes: 75 additions & 0 deletions app/Console/Commands/KanvasEmailTemplateSync.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use Baka\Users\Contracts\UserInterface;
use Illuminate\Console\Command;
use Kanvas\Apps\Actions\SyncEmailTemplateAction;
use Kanvas\Apps\Models\Apps;
use Kanvas\Templates\Models\Templates;
use Kanvas\Users\Models\Users;

class KanvasEmailTemplateSync extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'kanvas:email-template-sync {app_id} {user_id}';

/**
* The console command description.
*
* @var string|null
*/
protected $description = 'Sync email templates from the app to the email service provider';

/**
* Execute the console command.
*/
public function handle(): int
{
$appId = $this->argument('app_id');
$app = Apps::getById($appId);
$user = Users::getById($this->argument('user_id'));

if (! $app) {
$this->error("App with ID $appId not found.");

return 1;
}

$this->info("Sync email templates from the app: {$app->name}");
$this->newLine();

$defaultTemplate = Templates::notDeleted()->fromApp($app)->where('parent_template_id', 0)->first();

if (! $defaultTemplate) {
$this->error('Default template not found.');
$this->syncTemplates($app, $user);

return 1;
}

if ($this->confirm('Do you want to sync the email templates? This will overwrite the existing email templates.')) {
$this->syncTemplates($app, $user);
$this->info('Email templates have been synced.');
} else {
$this->info('Email templates syncing has been canceled.');
}

return 0;
}

/**
* Sync the email templates.
*/
protected function syncTemplates(Apps $app, UserInterface $user): void
{
$syncEmailTemplate = new SyncEmailTemplateAction($app, $user);
$syncEmailTemplate->execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Kanvas\Apps\Models\Apps;
use Kanvas\Companies\Actions\CreateCompaniesAction;
use Kanvas\Companies\Actions\UpdateCompaniesAction;
use Kanvas\Companies\DataTransferObject\CompaniesPostData;
use Kanvas\Companies\DataTransferObject\CompaniesPutData;
use Kanvas\Companies\DataTransferObject\Company;
use Kanvas\Companies\Jobs\DeleteCompanyJob;
use Kanvas\Companies\Models\Companies;
use Kanvas\Companies\Models\CompaniesBranches;
Expand All @@ -34,11 +34,10 @@ public function createCompany(mixed $root, array $request): Companies
if (auth()->user()->isAdmin() && key_exists('users_id', $request['input'])) {
$user = Users::getById($request['input']['users_id']);
UsersRepository::belongsToThisApp($user, app(Apps::class)) ;
$request['input']['users_id'] = $user->getKey();
} else {
$request['input']['users_id'] = Auth::user()->getKey();
$user = auth()->user();
}
$dto = CompaniesPostData::fromArray($request['input']);
$dto = Company::viaRequest($request['input'], $user);
$action = new CreateCompaniesAction($dto);

return $action->execute();
Expand All @@ -52,12 +51,10 @@ public function updateCompany(mixed $root, array $request): Companies
if (auth()->user()->isAdmin() && key_exists('users_id', $request['input'])) {
$user = Users::getById($request['input']['users_id']);
UsersRepository::belongsToThisApp($user, app(Apps::class)) ;
$request['input']['users_id'] = $user->getKey();
} else {
$request['input']['users_id'] = Auth::user()->getKey();
$user = Auth::user();
$user = auth()->user();
}
$dto = CompaniesPutData::fromArray($request['input']);
$dto = Company::viaRequest($request['input'], $user);
$action = new UpdateCompaniesAction($user, $dto);

return $action->execute((int) $request['id']);
Expand Down
65 changes: 39 additions & 26 deletions app/GraphQL/Ecosystem/Queries/Companies/UserManagementQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Baka\Enums\StateEnums;
use GraphQL\Type\Definition\ResolveInfo;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
use Kanvas\Apps\Models\Apps;
use Kanvas\Users\Models\Users;
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;

Expand All @@ -19,49 +19,62 @@ class UserManagementQuery
public function getAllCompanyUsers(mixed $root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): Builder
{
$companiesId = auth()->user()->isAdmin() && ! empty($args['companies_id']) ? $args['companies_id'] : auth()->user()->currentCompanyId();
$app = app(Apps::class);

/**
* @var Builder
*/
return Users::select('users.*')
->join(
'users_associated_company',
'users_associated_company.users_id',
'users.id'
)
->where(
'users_associated_company.companies_id',
$companiesId
)
->where(
'users_associated_company.is_deleted',
StateEnums::NO->getValue()
)
->groupBy('users.id');
return Users::select('users.id', 'users.uuid', 'users.dob', 'users.sex', 'users_associated_apps.*')
->join(
'users_associated_company',
'users_associated_company.users_id',
'users.id'
)
->join(
'users_associated_apps',
'users_associated_apps.users_id',
'users.id'
)
->where('users_associated_company.companies_id', $companiesId)
->where('users_associated_apps.apps_id', $app->getId())
->where('users_associated_company.is_deleted', StateEnums::NO->getValue())
->where('users_associated_apps.is_deleted', StateEnums::NO->getValue())
->groupBy('users.id');
}

/**
* Get the current users from this branch.
*/
public function getAllCompanyBranchUsers(mixed $root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): Builder
{
$companiesId = auth()->user()->isAdmin() && ! empty($args['companies_id']) ? $args['companies_id'] : auth()->user()->currentCompanyId();
$branchId = auth()->user()->isAdmin() && ! empty($args['getCurrentBranch']) ? $args['getCurrentBranch'] : auth()->user()->currentBranchId();
$app = app(Apps::class);

/**
* @var Builder
*/
return Users::join(
return Users::select('users.id', 'users.uuid', 'users.dob', 'users.sex', 'users_associated_apps.*')
->join(
'users_associated_company',
'users_associated_company.users_id',
'users.id'
)
->join(
'users_associated_apps',
'users_associated_apps.users_id',
'users.id'
)
->where(
'users_associated_company.is_deleted',
StateEnums::NO->getValue()
)
->where(
'users_associated_company.companies_branches_id',
$companiesId
);
$branchId
)
->where(
'users_associated_apps.is_deleted',
StateEnums::NO->getValue()
)
->where(
'users_associated_apps.apps_id',
$app->getId()
)
->groupBy('users.id')
->select('users.*');
}
}
5 changes: 3 additions & 2 deletions app/GraphQL/Ecosystem/Queries/Filesystem/FilesystemQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Baka\Enums\StateEnums;
use GraphQL\Type\Definition\ResolveInfo;
use Illuminate\Database\Eloquent\Builder;
use Kanvas\Enums\AppSettingsEnums;
use Kanvas\Filesystem\Models\Filesystem;
use Kanvas\SystemModules\DataTransferObject\SystemModuleEntityInput;
use Kanvas\SystemModules\Repositories\SystemModulesRepository;
Expand All @@ -24,6 +25,7 @@ public function getFileByGraphType(
ResolveInfo $resolveInfo
): Builder {
$systemModule = SystemModulesRepository::getByModelName($root::class);
$app = $systemModule->app;

/**
* @var Builder
Expand All @@ -44,8 +46,7 @@ public function getFileByGraphType(
->where('filesystem_entities.is_deleted', '=', StateEnums::NO->getValue())
->where('filesystem.is_deleted', '=', StateEnums::NO->getValue());

//@todo allow to share media between company only of it the apps specifies it
$files->when(isset($root->companies_id), function ($query) use ($root) {
$files->when(isset($root->companies_id) && ! $app->get(AppSettingsEnums::GLOBAL_APP_IMAGES->getValue()), function ($query) use ($root) {
$query->where('filesystem_entities.companies_id', $root->companies_id);
});

Expand Down
4 changes: 2 additions & 2 deletions app/GraphQL/Guild/Builders/Leads/DashboardBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getCompanyInfo(
COUNT(CASE WHEN leads_status.name = ? THEN 1 END) + COUNT(CASE WHEN leads_status.name = ? THEN 1 END) as total_active_leads,
COUNT(CASE WHEN leads_status.name = ? THEN 1 END) as total_closed_leads,
(SELECT count(*) FROM agents where owner_linked_source_id = ? AND companies_id = ? and status_id = 1) as total_agents
', ['active', 'created', 'closed', $agentInfo->users_linked_source_id, $company->getId()])
', ['active', 'created', 'complete', $agentInfo->users_linked_source_id, $company->getId()])
->join('leads_status', 'leads.leads_status_id', '=', 'leads_status.id')
->fromCompany($company);
}
Expand All @@ -47,7 +47,7 @@ public function getCompanyInfo(
COUNT(CASE WHEN leads_status.name = ? THEN 1 END) + COUNT(CASE WHEN leads_status.name = ? THEN 1 END) as total_active_leads,
COUNT(CASE WHEN leads_status.name = ? THEN 1 END) as total_closed_leads,
(SELECT count(*) FROM agents where owner_id = ? AND companies_id = ? and status_id = 1) as total_agents
', ['active', 'created', 'closed', $memberId, $company->getId()])
', ['active', 'created', 'complete', $memberId, $company->getId()])
->join('leads_status', 'leads.leads_status_id', '=', 'leads_status.id')
->fromCompany($company);
}
Expand Down
9 changes: 9 additions & 0 deletions app/Http/Controllers/ReceiverController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Support\Facades\Auth;
use Kanvas\Apps\Models\Apps;
use Kanvas\Connectors\Zoho\Actions\SyncZohoAgentAction;
use Kanvas\Connectors\Zoho\Actions\SyncZohoLeadAction;
use Kanvas\Connectors\Zoho\Workflows\ZohoLeadOwnerWorkflow;
use Kanvas\Guild\Leads\Models\LeadReceiver;
use Workflow\WorkflowStub;
Expand All @@ -32,6 +33,7 @@ public function store(string $uuid, Request $request): JsonResponse
}

$tempSubSystem = $uuid == $app->get('subsystem-temp-uuid');
$zohoLeadTempSubSystem = $uuid == $app->get('zoho-lead-temp-uuid');

Auth::loginUsingId($receiver->users_id);

Expand Down Expand Up @@ -61,6 +63,13 @@ public function store(string $uuid, Request $request): JsonResponse
return response()->json(['message' => 'Receiver processed']);
}

if ($zohoLeadTempSubSystem) {
$syncLead = new SyncZohoLeadAction($app, $receiver->company, $leadExternalId);
$syncLead->execute();

return response()->json(['message' => 'Receiver processed']);
}

$workflow = WorkflowStub::make(ZohoLeadOwnerWorkflow::class);
$workflow->start($leadExternalId, $receiver, app(Apps::class), []);

Expand Down
8 changes: 6 additions & 2 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
use Kanvas\Companies\Models\Companies;
use Kanvas\Companies\Models\CompaniesGroups;
use Kanvas\Companies\Observers\CompaniesObserver;
use Kanvas\Guild\Customers\Models\People;
use Kanvas\Guild\Customers\Models\PeopleEmploymentHistory;
use Kanvas\Guild\Customers\Observers\PeopleEmploymentHistoryObserver;
use Kanvas\Guild\Customers\Observers\PeopleObserver;
use Kanvas\Guild\Leads\Models\Lead;
use Kanvas\Guild\Leads\Observers\LeadObserver;
use Kanvas\Inventory\Categories\Observers\ProductsCategoriesObserver;
Expand All @@ -29,8 +33,6 @@
use Kanvas\Inventory\Warehouses\Observers\WarehouseObserver;
use Kanvas\Notifications\Events\PushNotificationsEvent;
use Kanvas\Notifications\Listeners\NotificationsListener;
use Kanvas\Sessions\Models\Sessions;
use Kanvas\Sessions\Observers\SessionObserver;
use Kanvas\Social\Messages\Models\UserMessage;
use Kanvas\Social\Messages\Models\UserMessageActivity;
use Kanvas\Social\Messages\Observers\UserMessageActivityObserver;
Expand Down Expand Up @@ -81,6 +83,8 @@ public function boot()
UsersAssociatedApps::observe(UsersAssociatedAppsObserver::class);
UserCompanyApps::observe(UsersAssociatedCompaniesObserver::class);
ProductsCategories::observe(ProductsCategoriesObserver::class);
PeopleEmploymentHistory::observe(PeopleEmploymentHistoryObserver::class);
People::observe(PeopleObserver::class);
}

/**
Expand Down
Loading

0 comments on commit e904aa1

Please sign in to comment.