Skip to content

Commit

Permalink
Merge pull request #934 from bakaphp/development
Browse files Browse the repository at this point in the history
release 23
  • Loading branch information
kaioken authored Feb 13, 2024
2 parents 7500f69 + be3da4c commit de6f64a
Show file tree
Hide file tree
Showing 22 changed files with 360 additions and 85 deletions.
15 changes: 15 additions & 0 deletions app/GraphQL/Social/Builders/Messages/MessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,19 @@ public function getAll(
*/
return Message::fromApp();
}

public function getChannelMessages(
mixed $root,
array $args,
GraphQLContext $context,
ResolveInfo $resolveInfo
): Builder {
return Message::fromApp()->whereHas('channels', function ($query) use ($args) {
$query->where('channels.uuid', $args['channel_uuid']);
})
->when(! auth()->user()->isAdmin(), function ($query) {
$query->where('companies_id', auth()->user()->currentCompanyId());
})
->select('messages.*');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Kanvas\Social\Channels\Repositories\ChannelRepository;
use Kanvas\SystemModules\Repositories\SystemModulesRepository;
use Kanvas\Users\Models\Users;
use Baka\Support\Str;

class ChannelsManagementMutation
{
Expand All @@ -26,6 +27,7 @@ public function createChannel(mixed $rootValue, array $request): Channel
description: $request['input']['description'],
entity_id: $request['input']['entity_id'],
entity_namespace: $systemModule->uuid,
slug: $request['input']['slug'] ?? Str::slug($request['input']['name'])
);

$createChannel = new CreateChannelAction($channelDto);
Expand Down
154 changes: 77 additions & 77 deletions composer.lock

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions database/migrations/Social/2024_02_12_172534_uuid_channel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('channels', function (Blueprint $table) {
$table->uuid('uuid')->after('id');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('channels', function (Blueprint $table) {
$table->dropColumn('uuid');
});
}
};
19 changes: 19 additions & 0 deletions database/seeders/SystemModuleSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Kanvas\Guild\Leads\Models\Lead;

class SystemModuleSeeder extends Seeder
{
Expand Down Expand Up @@ -195,6 +196,24 @@ public function run()
'mobile_component_type' => null,
'mobile_navigation_type' => null,
'mobile_tab_index' => '0',
],
[
'name' => 'Leads',
'slug' => 'leads',
'model_name' => Lead::class,
'uuid' => (string) Str::uuid(),
'apps_id' => '1',
'parents_id' => '0',
'menu_order' => null,
'show' => '0',
'use_elastic' => '0',
'browse_fields' => '[{"name":"name","title":"Name","sortField":"name","filterable":true,"searchable":true},{"name":"email","title":"Email","sortField":"email","filterable":true,"searchable":true},{"name":"phone","title":"Phone","sortField":"phone","filterable":true,"searchable":true},{"name":"status","title":"Status","sortField":"status","filterable":true,"searchable":true},{"name":"created_at","title":"Created At","sortField":"created_at","filterable":true,"searchable":true}]',
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => null,
'is_deleted' => '0',
'mobile_component_type' => null,
'mobile_navigation_type' => null,
'mobile_tab_index' => '0',
]
);
}
Expand Down
19 changes: 17 additions & 2 deletions graphql/schemas/Guild/lead.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ type Lead {
pipeline: LeadPipeline @belongsTo
stage: LeadPipelineStage @belongsTo(relation: "stage")
participants: [LeadsParticipants!]! @hasMany
channels: [SocialChannel]! @hasMany
files: [Filesystem!]!
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Ecosystem\\Queries\\Filesystem\\FilesystemQuery@getFileByGraphType"
)
followers: [User!]!
followers: [User!]!
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Social\\Builders\\Follows\\FollowBuilder@getEntityFollowers"
Expand Down Expand Up @@ -180,7 +181,21 @@ extend type Query @guard {
"status"
]
)
orderBy: _ @orderBy(columns: ["id", "created_at", "updated_at", "title", "status", "pipeline_stage_id", "firstname", "lastname", "email", "phone"])
orderBy: _
@orderBy(
columns: [
"id"
"created_at"
"updated_at"
"title"
"status"
"pipeline_stage_id"
"firstname"
"lastname"
"email"
"phone"
]
)
): [Lead!]!
@paginate(
model: "Kanvas\\Guild\\Leads\\Models\\Lead"
Expand Down
1 change: 1 addition & 0 deletions graphql/schemas/Social/channels.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extend type User {
type SocialChannel {
id: ID!
name: String!
uuid: String
slug: String
description: String!
entity_namespace: String!
Expand Down
26 changes: 26 additions & 0 deletions graphql/schemas/Social/message.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,30 @@ extend type Query @guard {
builder: "App\\GraphQL\\Social\\Builders\\Messages\\MessageBuilder@getAll"
scopes: ["fromApp"]
)

channelMessages(
channel_uuid: String!
where: _
@whereConditions(
columns: [
"id"
"parent_id"
"parent_unique_id"
"companies_id"
"uuid"
"message_types_id"
"message"
"reactions_count"
"comments_count"
"total_liked"
"total_saved"
"total_shared"
]
)
): [Message!]!
@paginate(
defaultCount: 25
builder: "App\\GraphQL\\Social\\Builders\\Messages\\MessageBuilder@getChannelMessages"
scopes: ["fromApp"]
)
}
1 change: 1 addition & 0 deletions src/Domains/Connectors/Zoho/Enums/CustomFieldEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ enum CustomFieldEnum: string
case ZOHO_LEAD_ID = 'ZOHO_LEAD_ID';
case DEFAULT_OWNER = 'ZOHO_DEFAULT_OWNER';
case ZOHO_DEFAULT_LEAD_SOURCE = 'ZOHO_DEFAULT_LEAD_SOURCE';
case ZOHO_USE_AGENT_NAME = 'ZOHO_USE_AGENT_NAME';
case FIELDS_MAP = 'ZOHO_FIELDS_MAP';
case ZOHO_MEMBER_FIELD = 'ZOHO_MEMBER_FIELD';
case ZOHO_USER_OWNER_ID = 'ZOHO_USER_OWNER_ID';
Expand Down
10 changes: 7 additions & 3 deletions src/Domains/Connectors/Zoho/Workflows/ZohoLeadActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function assignAgent(

$defaultLeadSource = $company->get(CustomFieldEnum::ZOHO_DEFAULT_LEAD_SOURCE->value);
if (! empty($defaultLeadSource)) {
$zohoData['Lead_Source'] = $defaultLeadSource;
$zohoData['Lead_Source'] = $lead->receiver ? $lead->receiver->name : $defaultLeadSource;
}

if ($agent && $agent->count()) {
Expand All @@ -119,14 +119,18 @@ protected function assignAgent(
}
} elseif ($agentInfo) {
$zohoData['Owner'] = (int) $agentInfo->owner_linked_source_id;
$zohoData['Lead_Source'] = $agentInfo->name;
if (empty($defaultLeadSource)) {
$zohoData['Lead_Source'] = $agentInfo->name;
}

if ($agentInfo->user && $agentInfo->user->get('sponsor')) {
$zohoData['Sponsor'] = (string) $agent->user->get('sponsor');
}
}


if ($company->get(CustomFieldEnum::ZOHO_USE_AGENT_NAME->value)) {
$zohoData['Agent_Name'] = $agentInfo->name;
}

//if value is 0 or empty, remove it
if (empty($zohoData['Owner'])) {
Expand Down
19 changes: 19 additions & 0 deletions src/Domains/Connectors/Zoho/ZohoService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Exception;
use Kanvas\Connectors\Zoho\Enums\CustomFieldEnum;
use Kanvas\Guild\Agents\Models\Agent;
use Kanvas\Guild\Leads\Models\Lead;
use Webleit\ZohoCrmApi\ZohoCrm;

class ZohoService
Expand Down Expand Up @@ -78,4 +79,22 @@ public function createAgent(UserInterface $user, Agent $agentInfo, ?object $zoho

return $zohoAgent;
}

public function deleteLead(Lead $lead): void
{
$zohoLeadId = $lead->get(CustomFieldEnum::ZOHO_LEAD_ID->value);
if ($zohoLeadId) {
$this->zohoCrm->leads->delete((string) $zohoLeadId);
}
}

public function deleteAgent(Agent $agent): void
{
$zohoAgentId = $agent->users_linked_source_id;
if ($this->zohoAgentModule == self::DEFAULT_AGENT_MODULE) {
$this->zohoCrm->agents->delete($zohoAgentId);
} else {
$this->zohoCrm->vendors->delete($zohoAgentId);
}
}
}
2 changes: 1 addition & 1 deletion src/Domains/Guild/Agents/Models/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function status(): Attribute
);
}

public static function getByMemberNumber(string $memberNumber, CompanyInterface $company): self
public static function getByMemberNumber(string|int $memberNumber, CompanyInterface $company): self
{
return self::where('member_id', $memberNumber)
->fromCompany($company)
Expand Down
7 changes: 7 additions & 0 deletions src/Domains/Guild/Leads/Models/Lead.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Baka\Users\Contracts\UserInterface;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Kanvas\Apps\Models\Apps;
use Kanvas\Guild\Customers\Models\People;
Expand All @@ -19,6 +20,7 @@
use Kanvas\Guild\Organizations\Models\Organization;
use Kanvas\Guild\Pipelines\Models\Pipeline;
use Kanvas\Guild\Pipelines\Models\PipelineStage;
use Kanvas\Social\Channels\Models\Channel;
use Kanvas\Social\Follows\Traits\FollowersTrait;
use Kanvas\Users\Models\Users;
use Kanvas\Workflow\Traits\CanUseWorkflow;
Expand Down Expand Up @@ -105,6 +107,11 @@ public function owner(): BelongsTo
return $this->belongsTo(Users::class, 'leads_owner_id', 'id');
}

public function socialChannels(): HasMany
{
return $this->hasMany(Channel::class, 'entity_id', 'id')->where('entity_namespace', self::class);
}

public function receiver(): BelongsTo
{
return $this->belongsTo(LeadReceiver::class, 'leads_receivers_id', 'id');
Expand Down
19 changes: 19 additions & 0 deletions src/Domains/Guild/Leads/Observers/LeadObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
namespace Kanvas\Guild\Leads\Observers;

use Baka\Support\Str;
use Kanvas\Apps\Models\Apps;
use Kanvas\Guild\Customers\Repositories\PeoplesRepository;
use Kanvas\Guild\Leads\Models\Lead;
use Kanvas\Guild\Leads\Models\LeadReceiver;
use Kanvas\Guild\Leads\Models\LeadStatus;
use Kanvas\Guild\Pipelines\Models\Pipeline;
use Kanvas\Social\Channels\Actions\CreateChannelAction;
use Kanvas\Social\Channels\DataTransferObject\Channel;
use Kanvas\Workflow\Enums\WorkflowEnum;

class LeadObserver
Expand Down Expand Up @@ -64,6 +67,22 @@ public function creating(Lead $lead): void
public function created(Lead $lead): void
{
$lead->fireWorkflow(WorkflowEnum::CREATED->value);
if ($lead->user) {
(
new CreateChannelAction(
new Channel(
app(Apps::class),
$lead->company,
$lead->user,
(string)$lead->id,
Lead::class,
'Default Channel',
$lead->description ?? '',
$lead->uuid->toString()
)
)
)->execute();
}
}

public function updated(Lead $lead): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function execute(): Channel
'apps_id' => $this->channelDto->apps->id,
'companies_id' => $this->channelDto->companies->id,
'name' => $this->channelDto->name,
'slug' => Str::slug($this->channelDto->name),
'slug' => $this->channelDto->slug ?? Str::slug($this->channelDto->name),
'description' => $this->channelDto->description,
'entity_id' => $this->channelDto->entity_id,
'entity_namespace' => $this->channelDto->entity_namespace,
Expand Down
1 change: 1 addition & 0 deletions src/Domains/Social/Channels/DataTransferObject/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function __construct(
public string $entity_namespace,
public string $name = '',
public string $description = '',
public ?string $slug = null
) {
}
}
3 changes: 3 additions & 0 deletions src/Domains/Social/Channels/Models/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Kanvas\Social\Channels\Models;

use Baka\Traits\UuidTrait;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Kanvas\Social\Messages\Models\Message;
Expand All @@ -24,6 +25,8 @@
*/
class Channel extends BaseModel
{
use UuidTrait;

protected $table = 'channels';

protected $guarded = [];
Expand Down
9 changes: 9 additions & 0 deletions src/Domains/Social/Messages/Models/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Kanvas\Apps\Models\Apps;
use Kanvas\Social\Channels\Models\Channel;
use Kanvas\Social\Messages\Factories\MessageFactory;
use Kanvas\Social\MessagesComments\Models\MessageComment;
use Kanvas\Social\MessagesTypes\Models\MessageType;
Expand Down Expand Up @@ -85,6 +86,14 @@ public function topics(): BelongsToMany
->where('entity_namespace', self::class);
}

/**
* The roles that belong to the Message
*/
public function channels(): BelongsToMany
{
return $this->belongsToMany(Channel::class, 'channel_messages', 'messages_id', 'channel_id');
}

/**
* messageType
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Kanvas/Enums/AppEnums.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function getValue(): mixed
self::KANVAS_APP_BRANCH_HEADER => 'X-Kanvas-Location',
self::KANVAS_APP_COMPANY_AUTH_HEADER => 'Company-Authorization', //@deprecated
self::DISPLAYNAME_LOGIN => 'displayname_login',
self::VERSION => '1.0-BETA-21',
self::VERSION => '1.0-BETA-22',
self::ANONYMOUS_USER_ID => -1
};
}
Expand Down
Loading

0 comments on commit de6f64a

Please sign in to comment.