Skip to content

Commit

Permalink
Merge pull request #1571 from bakaphp/development
Browse files Browse the repository at this point in the history
Release RC2
  • Loading branch information
kaioken authored Jun 30, 2024
2 parents 5da3c7a + d884832 commit 58f4744
Show file tree
Hide file tree
Showing 89 changed files with 2,586 additions and 467 deletions.
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'on_multiline' => 'ensure_fully_multiline',
'keep_multiple_spaces_after_comma' => true,
],
'no_extra_blank_lines' => ['tokens' => ['attribute', 'break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use']],
])
->setFinder(
PhpCsFixer\Finder::create()
Expand Down
20 changes: 12 additions & 8 deletions 1.x.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,29 @@ RUN apt-get update && apt-get install -y \
vim

# Set working directory
WORKDIR /app
COPY . /var/www/html/
# COPY chown -R unit:unit /var/www/html/

# Add user for laravel application
# RUN addgroup -g 1000 www
# RUN adduser -u 1000 -s /bin/sh --disabled-password -G www www
# add root to www group
# RUN chmod -R ug+w var/www/html/storage
# RUN cp docker/php-fpm.conf /usr/local/etc/php-fpm.d/zzz-php-fpm-production.conf

COPY . /app
WORKDIR /var/www/html/

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

RUN composer install --no-dev --optimize-autoloader

# add root to www group
RUN chmod -R ug+w /app/storage
# RUN chmod -R ug+w /app/storage

RUN cp docker/docker-php-ext-opcache-prod.ini /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
RUN cp docker/php.ini /usr/local/etc/php/conf.d/zx-app-config.ini
# RUN cp docker/php-fpm.conf /usr/local/etc/php-fpm.d/zzz-php-fpm-production.conf

WORKDIR /var/www/html
RUN chmod -R 755 /var/www/html/
RUN chmod -R 777 /var/www/html/storage/
RUN chmod -R 777 /var/www/html/storage/logs/

RUN composer install --no-dev --optimize-autoloader

EXPOSE 8080
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Illuminate\Console\Command;
use Kanvas\Apps\Models\Apps;
use Kanvas\Companies\Models\CompaniesBranches;
use Kanvas\Connectors\Shopify\Actions\DownloadShopifyProductsAction;
use Kanvas\Connectors\Shopify\Actions\DownloadAllShopifyProductsAction;
use Kanvas\Inventory\Warehouses\Models\Warehouses;

class ShopifyInventoryDownloadCommand extends Command
Expand Down Expand Up @@ -35,9 +35,9 @@ public function handle()
{
$app = Apps::getById((int) $this->argument('app_id'));
$branch = CompaniesBranches::getById((int) $this->argument('branch_id'));
$warehouse = Warehouses::getById((int) $this->argument('warehouse_id'));
$warehouse = Warehouses::fromApp($app)->where('id', $this->argument('warehouse_id'))->firstOrFail();

$downloadProduct = new DownloadShopifyProductsAction(
$downloadProduct = new DownloadAllShopifyProductsAction(
$warehouse->app,
$warehouse,
$branch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ShopifyInventorySyncCommand extends Command
*
* @var string|null
*/
protected $description = 'Set defaults entities value for inventory companies';
protected $description = 'Send all our local inventory to shopify';

/**
* Execute the console command.
Expand Down
1 change: 0 additions & 1 deletion app/GraphQL/Inventory/Mutations/Products/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace App\GraphQL\Inventory\Mutations\Products;

use Kanvas\Companies\Models\Companies;
use Kanvas\Connectors\Shopify\ShopifyService;
use Kanvas\Inventory\Attributes\Repositories\AttributesRepository;
use Kanvas\Inventory\Products\Actions\AddAttributeAction;
use Kanvas\Inventory\Products\Actions\CreateProductAction;
Expand Down
9 changes: 8 additions & 1 deletion app/GraphQL/Inventory/Mutations/Variants/Variants.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

namespace App\GraphQL\Inventory\Mutations\Variants;

use Kanvas\Companies\Repositories\CompaniesRepository;
use Kanvas\Inventory\Attributes\Repositories\AttributesRepository;
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\CreateVariantsAction;
use Kanvas\Inventory\Variants\Actions\DeleteVariantsAction;
use Kanvas\Inventory\Variants\Actions\UpdateVariantsAction;
use Kanvas\Inventory\Variants\DataTransferObject\VariantChannel;
use Kanvas\Inventory\Variants\DataTransferObject\Variants as VariantDto;
Expand Down Expand Up @@ -130,7 +132,12 @@ public function delete(mixed $root, array $req): bool
{
$variant = VariantsRepository::getById((int) $req['id'], auth()->user()->getCurrentCompany());

return $variant->delete();
CompaniesRepository::userAssociatedToCompany(
$variant->company,
auth()->user()
);

return (new DeleteVariantsAction($variant, auth()->user()))->execute();
}

/**
Expand Down
27 changes: 24 additions & 3 deletions app/GraphQL/Social/Builders/Messages/MessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use GraphQL\Type\Definition\ResolveInfo;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
use Kanvas\Social\Messages\Models\Message;
use Nuwave\Lighthouse\Support\Contracts\GraphQLContext;

Expand All @@ -17,9 +18,12 @@ public function getAll(
GraphQLContext $context,
ResolveInfo $resolveInfo
): Builder {
/**
* @psalm-suppress MixedReturnStatement
*/
$user = auth()->user();

if (! $user->isAppOwner()) {
return Message::fromApp()->fromCompany($user->getCurrentCompany());
}

return Message::fromApp();
}

Expand All @@ -37,4 +41,21 @@ public function getChannelMessages(
})
->select('messages.*');
}

public function getGroupByDate(
mixed $root,
array $args,
GraphQLContext $context,
ResolveInfo $resolveInfo
) {
return Message::select(
DB::raw('*, CASE
WHEN created_at >= CURDATE() THEN "Today"
WHEN created_at >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) THEN "Past 7 Days"
WHEN created_at >= DATE_SUB(CURDATE(), INTERVAL 30 DAY) THEN "Past 30 Days"
ELSE DATE_FORMAT(created_at, "%M %Y")
END as additional_field')
)
->orderBy('created_at', 'desc');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,72 @@

namespace App\GraphQL\Social\Mutations\Messages;

use Exception;
use Illuminate\Support\Facades\Validator;
use Kanvas\Apps\Models\Apps;
use Kanvas\Auth\Exceptions\AuthenticationException;
use Kanvas\Exceptions\ValidationException;
use Kanvas\Social\Messages\Models\Message;
use Kanvas\Social\Messages\Validations\ValidParentComment;
use Kanvas\Social\MessagesComments\Actions\CreateMessageComment;
use Kanvas\Social\MessagesComments\DataTransferObject\MessageComment as CommentsDto;
use Kanvas\Social\MessagesComments\Models\MessageComment;

class MessageCommentManagementMutation
{
public function addComment(mixed $root, array $request): Message
public function addComment(mixed $root, array $request): MessageComment
{
$message = Message::getById((int)$request['input']['message_id'], app(Apps::class));

$parentId = key_exists('parent_id', $request['input']) ? MessageComment::getById($request['input']['parent_id'])->id : 0;

$dto = CommentsDto::from([
'apps' => app(Apps::class),
'companies' => auth()->user()->getCurrentCompany(),
'users' => auth()->user(),
'messages' => $message,
'message' => $request['input']['message'],
'app' => app(Apps::class),
'company' => auth()->user()->getCurrentCompany(),
'user' => auth()->user(),
'message' => $message,
'comment' => $request['input']['comment'],
'parent_id' => $parentId,
]);

(new CreateMessageComment($dto))->execute();
return (new CreateMessageComment($dto))->execute();

return $message;
}

public function updateComment(mixed $root, array $request): Message
public function updateComment(mixed $root, array $request): MessageComment
{
$comment = MessageComment::getById($request['comment_id'], app(Apps::class));
if ($comment->users_id != auth()->user()->id) {
throw new Exception('You are not allowed to update this comment');
$comment = MessageComment::getById($request['id'], app(Apps::class));
$user = auth()->user();

if (! $comment->canEdit($user)) {
throw new AuthenticationException('You are not allowed to update this comment');
}

$validator = Validator::make($request, [
'parent_id' => [new ValidParentComment($comment->app->getId())],
]);

if ($validator->fails()) {
throw new ValidationException($validator->messages()->__toString());
}

$parentId = key_exists('parent_id', $request['input']) ? MessageComment::getById($request['input']['parent_id'])->id : $comment->parent_id;

$comment->update([
'message' => $request['input']['message'],
'message' => $request['input']['comment'],
'parent_id' => $parentId,
]);

return $comment->messages;
return $comment;
}

public function delete(mixed $root, array $request): bool
{
$comment = MessageComment::getById($request['id'], app(Apps::class));
if (! $comment->canDelete(auth()->user())) {
throw new AuthenticationException('You are not allowed to delete this message');
}

return $comment->delete();
}
}
78 changes: 59 additions & 19 deletions app/GraphQL/Social/Mutations/Messages/MessageManagementMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,25 @@
namespace App\GraphQL\Social\Mutations\Messages;

use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Support\Facades\Validator;
use Kanvas\Apps\Models\Apps;
use Kanvas\Auth\Exceptions\AuthenticationException;
use Kanvas\Exceptions\ValidationException;
use Kanvas\Social\Messages\Actions\CreateMessageAction;
use Kanvas\Social\Messages\Actions\DistributeChannelAction;
use Kanvas\Social\Messages\Actions\DistributeToUsers;
use Kanvas\Social\Messages\DataTransferObject\MessageInput;
use Kanvas\Social\Messages\Enums\ActivityTypeEnum;
use Kanvas\Social\Messages\Enums\DistributionTypeEnum;
use Kanvas\Social\Messages\Models\Message;
use Kanvas\Social\Messages\Validations\ValidParentMessage;
use Kanvas\Social\MessagesTypes\Actions\CreateMessageTypeAction;
use Kanvas\Social\MessagesTypes\DataTransferObject\MessageTypeInput;
use Kanvas\Social\MessagesTypes\Repositories\MessagesTypesRepository;
use Kanvas\SystemModules\Models\SystemModules;

class MessageManagementMutation
{
public function interaction(mixed $root, array $request): Message
{
$message = Message::getById((int)$request['id']);
$action = new CreateMessageAction($message, auth()->user(), ActivityTypeEnum::from($request['type']));
$action->execute();

return $message;
}

/**
* create
*/
public function create(mixed $root, array $request): Message
{
$app = app(Apps::class);
Expand All @@ -50,9 +41,22 @@ public function create(mixed $root, array $request): Message
]);
$messageType = (new CreateMessageTypeAction($messageTypeDto))->execute();
}
$systemModule = key_exists('system_modules_id', $messageData) ? SystemModules::getById((int)$messageData['system_modules_id'], $app) : null;
$data = MessageInput::fromArray($messageData, $user, $messageType, $company, $app);
$action = new CreateMessageAction($data, $systemModule, $messageData['entity_id']);

$systemModuleId = $messageData['system_modules_id'] ?? null;
$systemModule = $systemModuleId ? SystemModules::getById((int)$systemModuleId, $app) : null;
$data = MessageInput::fromArray(
$messageData,
$user,
$messageType,
$company,
$app
);

$action = new CreateMessageAction(
$data,
$systemModule,
$messageData['entity_id']
);
$message = $action->execute();

if (! key_exists('distribution', $messageData)) {
Expand Down Expand Up @@ -81,20 +85,47 @@ public function update(mixed $root, array $request): Message
if (! $message->canEdit(auth()->user())) {
throw new AuthenticationException('You are not allowed to edit this message');
}

$validator = Validator::make($request, [
'parent_id' => [new ValidParentMessage($message->app->getId())],
]);

if ($validator->fails()) {
throw new ValidationException($validator->messages()->__toString());
}

$message->update($request['input']);

return $message;
}

public function delete(mixed $root, array $request): Message
public function delete(mixed $root, array $request): bool
{
$message = Message::getById((int)$request['id'], app(Apps::class));
if (! $message->canEdit(auth()->user())) {
if (! $message->canDelete(auth()->user())) {
throw new AuthenticationException('You are not allowed to delete this message');
}
$message->delete();

return $message;
return $message->delete();
}

public function deleteMultiple(mixed $root, array $request): bool
{
$user = auth()->user();
$app = app(Apps::class);
$messages = Message::fromApp($app)->whereIn('id', $request['ids'])->get();

$total = 0;

foreach ($messages as $message) {
if (! $message->canEdit($user)) {
throw new AuthenticationException('You are not allowed to delete this message');
}
$message->delete();
$total++;
}

return $total > 0;
}

public function attachTopicToMessage(mixed $root, array $request): Message
Expand All @@ -112,4 +143,13 @@ public function detachTopicToMessage(mixed $root, array $request): Message

return $message;
}

public function interaction(mixed $root, array $request): Message
{
$message = Message::getById((int)$request['id']);
$action = new CreateMessageAction($message, auth()->user(), ActivityTypeEnum::from($request['type']));
$action->execute();

return $message;
}
}
Loading

0 comments on commit 58f4744

Please sign in to comment.