Skip to content

Commit

Permalink
Merge pull request #1472 from bakaphp/development
Browse files Browse the repository at this point in the history
v1.0-BETA36
  • Loading branch information
kaioken committed Jun 16, 2024
2 parents 28d1015 + 6e94a39 commit 5262ddd
Show file tree
Hide file tree
Showing 107 changed files with 2,512 additions and 193 deletions.
1 change: 0 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches:
- '1.x'
- 'development'

workflow_dispatch:

Expand Down
27 changes: 26 additions & 1 deletion .github/workflows/ec2-deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Deploy to EC2

on:
push:
branches:
- 'development'

workflow_dispatch:

jobs:
Expand All @@ -20,4 +24,25 @@ jobs:
username: ${{ secrets.AWS_EC2_USERNAME }}
key: ${{ secrets.AWS_EC2_PRIVATE_SSH_KEY }}
source: .
target: ${{secrets.AWS_EC2_TARGET_DIR}}
target: ${{secrets.AWS_EC2_TARGET_DIR}}
docker-command:
name: Docker commands
runs-on: ubuntu-latest
needs: deploy-to-ec2
environment: ${{ github.ref_name }}
steps:
- name: executing remote ssh commands using password
uses: appleboy/[email protected]
with:
host: ${{ secrets.AWS_EC2_HOST }}
username: ${{ secrets.AWS_EC2_USERNAME }}
key: ${{ secrets.AWS_EC2_PRIVATE_SSH_KEY }}
script: |
cd ${{secrets.AWS_EC2_TARGET_DIR}}
docker compose -f docker-compose.dev.yml up -d
docker exec -i phpkanvas-ecosystem php artisan lighthouse:cache
docker exec -i phpkanvas-ecosystem php artisan config:cache
docker restart queue
docker restart queue-notifications
docker restart queue-social
docker restart laravel-scheduler
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use Kanvas\Apps\Repositories\AppsRepository;
use Kanvas\Connectors\Notifications\Jobs\MailCaddieLabJob;
use Kanvas\Guild\Customers\Repositories\PeoplesRepository;

class MailCaddieLabCommand extends Command
{
Expand All @@ -13,9 +14,21 @@ class MailCaddieLabCommand extends Command
public function handle()
{
$this->info('Sending internal mail to Caddie Lab');
//dump($this->argument('email'));

$app = AppsRepository::findFirstByKey($this->argument('apps_id'));
$email = $this->argument('email');
MailCaddieLabJob::dispatch($app, $email);

$peoplesIn7Days = PeoplesRepository::getByDaysCreated(7, $app);
$peoplesIn28Days = PeoplesRepository::getByDaysCreated(28, $app);

$this->info('We will be sending email to ' . count($peoplesIn7Days) . ' people that have been created in the last 7 days');
$this->info('We will be sending email to ' . count($peoplesIn28Days) . ' people that have been created in the last 28 days');

if ($this->confirm('Are you sure you want to send this email?')) {
MailCaddieLabJob::dispatch($app, $email);
$this->info('Emails have been dispatched.');
} else {
$this->info('Email sending has been canceled.');
}
}
}
52 changes: 52 additions & 0 deletions app/Console/Commands/DeleteUsersRequestedCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Kanvas\Apps\Repositories\AppsRepository;
use Kanvas\Users\Models\RequestDeletedAccount;
use Illuminate\Support\Facades\DB;
use Kanvas\Apps\Models\Apps;

class DeleteUsersRequestedCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'kanvas:user:delete {apps_id?}';

/**
* The console command description.
*
* @var string|null
*/
protected $description = 'Delete a user';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$appsId = $this->argument('apps_id');
if ($appsId) {
$app = Apps::findFirstOrFail($appsId);
$this->info('Deleting user from app: ' . $app->name);
}
$days = $appsId ? $app->get('days_to_delete') : 30;
$users = RequestDeletedAccount::when($appsId, function ($query) use ($appsId) {
return $query->where('apps_id', $appsId);
})->where(DB::raw('DATEDIFF(request_date, CURDATE())'), '>', $days)
->where('is_deleted', 0)
->get();
foreach ($users as $user) {
echo 'Deleting user: ' . $user->email . PHP_EOL;
$user->associateUsers()->deActive();
}
}
}
2 changes: 2 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Spatie\Health\Commands\DispatchQueueCheckJobsCommand;
use Spatie\Health\Commands\RunHealthChecksCommand;
use Spatie\Health\Commands\ScheduleCheckHeartbeatCommand;
use App\Console\Commands\DeleteUsersRequestedCommand;

class Kernel extends ConsoleKernel
{
Expand All @@ -20,6 +21,7 @@ protected function schedule(Schedule $schedule)
$schedule->command(RunHealthChecksCommand::class)->everyMinute();
$schedule->command(DispatchQueueCheckJobsCommand::class)->everyMinute();
$schedule->command(ScheduleCheckHeartbeatCommand::class)->everyMinute();
$schedule->command(DeleteUsersRequestedCommand::class)->dailyAt('00:00');
/* $schedule->command(MailCaddieLabCommand::class, [getenv('CADDIE_APP_KEY')])
->dailyAt('13:00')
->timezone('America/Santo_Domingo') ; */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace App\GraphQL\ActionEngine\Builders\Engagements;

use GraphQL\Type\Definition\ResolveInfo;
use Illuminate\Database\Eloquent\Builder;
use Kanvas\ActionEngine\Tasks\Models\TaskListItem;
use Kanvas\Apps\Models\Apps;
use Kanvas\Guild\Leads\Models\Lead;
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;

class TaskEngagementBuilder
{
public function getLeadTaskItems(
mixed $root,
array $args,
GraphQLContext $context,
ResolveInfo $resolveInfo
): Builder {
$company = auth()->user()->getCurrentCompany();
$user = auth()->user();
$app = app(Apps::class);

$lead = Lead::getByIdFromCompanyApp($args['lead_id'], $company, $app);
$leadId = $lead->getId();

return TaskListItem::leftJoin('company_task_engagement_items', function ($join) use ($lead) {
$join->on('company_task_list_items.id', '=', 'company_task_engagement_items.task_list_item_id')
->where('company_task_engagement_items.lead_id', '=', $lead->getId());
})
->select(
'company_task_list_items.*',
'company_task_engagement_items.lead_id',
'company_task_engagement_items.status',
'company_task_engagement_items.engagement_start_id',
'company_task_engagement_items.engagement_end_id',
'company_task_engagement_items.created_at',
'company_task_engagement_items.updated_at'
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace App\GraphQL\ActionEngine\Mutations\Engagements;

use Kanvas\ActionEngine\Tasks\Models\TaskEngagementItem;
use Kanvas\ActionEngine\Tasks\Models\TaskListItem;
use Kanvas\Apps\Models\Apps;
use Kanvas\Exceptions\ValidationException;
use Kanvas\Guild\Leads\Models\Lead;

class TaskEngagementMutation
{
public function changeEngagementTaskItemStatus(mixed $rootValue, array $request): bool
{
$id = (int) $request['id'];
$user = auth()->user();
$company = $user->getCurrentCompany();
$app = app(Apps::class);
$status = $request['status'];
$lead = Lead::getByIdFromCompanyApp($request['lead_id'], $company, $app);

$taskListItem = TaskListItem::getById($id);

if ($taskListItem->companyAction->companies_id != $company->getId()) {
throw new ValidationException('You are not allowed to change the status of this task , company mismatch');
}

if ($taskListItem->companyAction->apps_id != $app->getId()) {
throw new ValidationException('You are not allowed to change the status of this task , app mismatch');
}

$taskEngagementItem = TaskEngagementItem::fromCompany($company)
->fromApp($app)
->where('task_list_item_id', $taskListItem->getId())
->where('lead_id', $lead->getId())
->first();

if (! $taskEngagementItem) {
$taskEngagementItem = new TaskEngagementItem();
$taskEngagementItem->task_list_item_id = $taskListItem->getId();
$taskEngagementItem->lead_id = $lead->getId();
$taskEngagementItem->companies_id = $company->getId();
$taskEngagementItem->apps_id = $app->getId();
$taskEngagementItem->users_id = $user->getId();
}

$taskEngagementItem->status = $status;

return $taskEngagementItem->saveOrFail();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Kanvas\Notifications\Templates\ChangePasswordUserLogged;
use Kanvas\Users\Actions\CreateInviteAction;
use Kanvas\Users\Actions\ProcessInviteAction;
use Kanvas\Users\Actions\RequestDeleteAccountAction as RequestDeleteAction;
use Kanvas\Users\DataTransferObject\CompleteInviteInput;
use Kanvas\Users\DataTransferObject\Invite as InviteDto;
use Kanvas\Users\Models\Users;
Expand Down Expand Up @@ -184,4 +185,9 @@ public function updatePhotoProfile(mixed $rootValue, array $request): Users

return $user;
}

public function requestDeleteAccount(mixed $rootValue, array $request): bool
{
return (new RequestDeleteAction(app(Apps::class), auth()->user()))->execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function create(mixed $root, array $req): ModelsPeople
'google_contact_id' => $data['google_contact_id'] ?? null,
'apple_contact_id' => $data['apple_contact_id'] ?? null,
'linkedin_contact_id' => $data['linkedin_contact_id'] ?? null,
'tags' => $data['tags'] ?? [],
'custom_fields' => $data['custom_fields'] ?? [],
]);

Expand Down Expand Up @@ -69,6 +70,7 @@ public function update(mixed $root, array $req): ModelsPeople
'google_contact_id' => $data['google_contact_id'] ?? null,
'apple_contact_id' => $data['apple_contact_id'] ?? null,
'linkedin_contact_id' => $data['linkedin_contact_id'] ?? null,
'tags' => $data['tags'] ?? [],
'custom_fields' => $data['custom_fields'] ?? [],
]);

Expand Down
19 changes: 13 additions & 6 deletions app/GraphQL/Inventory/Mutations/Variants/Variants.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
namespace App\GraphQL\Inventory\Mutations\Variants;

use Kanvas\Inventory\Attributes\Repositories\AttributesRepository;
use Kanvas\Inventory\Channels\Models\Channels;
use Kanvas\Inventory\Channels\Repositories\ChannelRepository;
use Kanvas\Inventory\Channels\Services\ChannelService;
use Kanvas\Inventory\Status\Repositories\StatusRepository;
use Kanvas\Inventory\Variants\Actions\AddAttributeAction;
use Kanvas\Inventory\Variants\Actions\AddToWarehouseAction as AddToWarehouse;
use Kanvas\Inventory\Variants\Actions\AddVariantToChannelAction;
use Kanvas\Inventory\Variants\Actions\CreateVariantsAction;
use Kanvas\Inventory\Variants\Actions\UpdateVariantsAction;
use Kanvas\Inventory\Variants\DataTransferObject\VariantChannel;
use Kanvas\Inventory\Variants\DataTransferObject\Variants as VariantDto;
use Kanvas\Inventory\Variants\DataTransferObject\VariantsWarehouses;
Expand Down Expand Up @@ -89,6 +89,7 @@ public function create(mixed $root, array $req): VariantModel
);
}
}

return $variantModel;
}

Expand All @@ -103,17 +104,23 @@ public function update(mixed $root, array $req): VariantModel
}

$variant = VariantsRepository::getById((int) $req['id'], $company);
$variant->update($req['input']);
$req['input']['products_id'] = $variant->product->getId();
$variantDto = VariantDto::viaRequest($req['input'], auth()->user());
$variantModel = (new UpdateVariantsAction($variant, $variantDto, auth()->user()))->execute();

if (isset($req['input']['attributes'])) {
$variant->addAttributes(auth()->user(), $req['input']['attributes']);
$variantModel->addAttributes(auth()->user(), $req['input']['attributes']);
}

if (isset($req['input']['warehouses'])) {
WarehouseService::updateWarehouseVariant($variant, auth()->user(), $req['input']['warehouses']);
WarehouseService::updateWarehouseVariant($variantModel, auth()->user(), $req['input']['warehouses']);
}

return $variant;
if (isset($req['input']['channels'])) {
ChannelService::updateChannelVariant($variantModel, $req['input']['channels']);
}

return $variantModel;
}

/**
Expand Down
Loading

0 comments on commit 5262ddd

Please sign in to comment.