Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 23 #934

Merged
merged 40 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ecb736e
Merge pull request #919 from bakaphp/feat-agent-owner-id
kaioken Feb 9, 2024
34fddea
build(deps): bump berkayk/onesignal-laravel from 2 to 2.0.1
dependabot[bot] Feb 9, 2024
d2806ab
build(deps-dev): bump spatie/laravel-ignition from 2.4.1 to 2.4.2
dependabot[bot] Feb 9, 2024
ba4d148
feat: delete record at the end in zoho
kaioken Feb 11, 2024
89ae5e1
fix: style
kaioken Feb 11, 2024
9b15df4
fix: style
kaioken Feb 11, 2024
227fa28
Merge pull request #924 from bakaphp/refact-test-
kaioken Feb 11, 2024
a08a133
Merge pull request #922 from bakaphp/dependabot/composer/spatie/larav…
kaioken Feb 11, 2024
7f4c9a0
Merge pull request #921 from bakaphp/dependabot/composer/berkayk/ones…
kaioken Feb 11, 2024
615c5ad
refact: feat 21
kaioken Feb 12, 2024
c1b4134
Merge pull request #925 from bakaphp/feat-enum-21
kaioken Feb 12, 2024
524dfdc
refactor: lead social channel
FredPeal Feb 12, 2024
d496593
fix: use has many in lead
FredPeal Feb 12, 2024
ad3da9e
feat: channel messages
FredPeal Feb 12, 2024
18f7649
build(deps-dev): bump phpstan/phpstan from 1.10.57 to 1.10.58
dependabot[bot] Feb 12, 2024
c7ec29c
fix: create slug
FredPeal Feb 12, 2024
4fbd327
refactor: add seeder
FredPeal Feb 12, 2024
6b890d1
refactor: remove test temporaly
FredPeal Feb 13, 2024
9de5c2f
refactor: camel case query and filter by company id
FredPeal Feb 13, 2024
3738368
Apply fixes from StyleCI
StyleCIBot Feb 13, 2024
08cb094
Merge pull request #929 from bakaphp/analysis-lZll2Q
FredPeal Feb 13, 2024
344098b
refactor: if user is not admin filter by companies id
FredPeal Feb 13, 2024
fcf3c5a
Merge branch 'channels-leads' of github.com:bakaphp/kanvas-ecosystem-…
FredPeal Feb 13, 2024
138a5cc
refactor: create default channel in lead observer
FredPeal Feb 13, 2024
6f8d367
Apply fixes from StyleCI
StyleCIBot Feb 13, 2024
08f539b
Merge pull request #930 from bakaphp/analysis-o7Bvgg
FredPeal Feb 13, 2024
88c8393
fix: use auth user
FredPeal Feb 13, 2024
0e5fa41
Merge branch 'channels-leads' of github.com:bakaphp/kanvas-ecosystem-…
FredPeal Feb 13, 2024
0317c73
refactor: lead user
FredPeal Feb 13, 2024
fe11088
refactor: debug relationship
FredPeal Feb 13, 2024
b6090d4
refactor: remove die
FredPeal Feb 13, 2024
f6c6058
fix: user lead
FredPeal Feb 13, 2024
41cbd85
refactor: create channel if user exist
FredPeal Feb 13, 2024
4873211
Apply fixes from StyleCI
StyleCIBot Feb 13, 2024
b3dfec1
Merge pull request #931 from bakaphp/analysis-9bYGP6
FredPeal Feb 13, 2024
2495093
Merge pull request #926 from bakaphp/channels-leads
FredPeal Feb 13, 2024
fdb35a4
Merge pull request #927 from bakaphp/dependabot/composer/phpstan/phps…
kaioken Feb 13, 2024
b0e8283
refact: lead zoho
kaioken Feb 13, 2024
cc60e02
fix
kaioken Feb 13, 2024
be3da4c
Merge pull request #933 from bakaphp/feat-enum-21
kaioken Feb 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function createAgent(AppInterface $app, ZohoService $zohoService, User
}
}

if ($companyDefaultUseRotation) {
if ($companyDefaultUseRotation && $ownerMemberNumber === null) {
try {
$rotation = LeadRotation::getByIdFromCompany($companyDefaultUseRotation, $company);
$agentUser = $rotation->getAgent();
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
Loading