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

Create company from ip lookup switch #7482

Merged
merged 3 commits into from
May 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions app/bundles/CoreBundle/Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,7 @@
'ip_lookup_service' => 'maxmind_download',
'ip_lookup_auth' => '',
'ip_lookup_config' => [],
'ip_lookup_create_organization' => false,
'transifex_username' => '',
'transifex_password' => '',
'update_stability' => 'stable',
Expand Down
15 changes: 15 additions & 0 deletions app/bundles/CoreBundle/Form/Type/ConfigType.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,21 @@ public function buildForm(FormBuilderInterface $builder, array $options)
]
);

$builder->add(
'ip_lookup_create_organization',
YesNoButtonGroupType::class,
[
'label' => 'mautic.core.config.create.organization.from.ip.lookup',
'label_attr' => ['class' => 'control-label'],
'attr' => [
'class' => 'form-control',
'tooltip' => 'mautic.core.config.create.organization.from.ip.lookup.tooltip',
],
'data' => isset($options['data']['ip_lookup_create_organization']) ? (bool) $options['data']['ip_lookup_create_organization'] : false,
'required' => false,
]
);

$ipLookupFactory = $this->ipLookupFactory;
$formModifier = function (FormEvent $event) use ($ipLookupFactory) {
$data = $event->getData();
Expand Down
2 changes: 2 additions & 0 deletions app/bundles/CoreBundle/Translations/en_US/messages.ini
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ mautic.core.config.form.image.path="Relative path to the images directory"
mautic.core.config.form.image.path.tooltip="Set the relative path from the public web root to where images uploaded through the editors should be stored."
mautic.core.config.form.ip.lookup.auth="IP lookup service authentication"
mautic.core.config.form.ip.lookup.auth.tooltip="Set authentication credential(s) required by the selected service. For services that require a username and password, use the format username:password."
mautic.core.config.create.organization.from.ip.lookup="Create company from IP lookup"
mautic.core.config.create.organization.from.ip.lookup.tooltip="Although it may be useful to get the company from IP lookup, Mautic will consider such contact to be identified which may not be what you want."
mautic.core.config.form.ip.lookup.service="IP lookup service"
mautic.core.config.form.ip.lookup.service.tooltip="Set the service to use to lookup geographical information from an IP address. Note that some of the services listed are commercial services. Mautic is not affiliated with the listed services but provide them for convenience."
mautic.core.config.form.link.shortener="URL Shortener"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<div class="row">
<?php echo $view['form']->rowIfExists($fields, 'ip_lookup_service', $template); ?>
<?php echo $view['form']->rowIfExists($fields, 'ip_lookup_auth', $template); ?>
<?php echo $view['form']->rowIfExists($fields, 'ip_lookup_create_organization', $template); ?>
<div id="ip_lookup_config_container">
<?php echo $view['form']->rowIfExists($fields, 'ip_lookup_config', '<div class="col-md-12">{content}</div>'); ?>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/bundles/LeadBundle/Model/LeadModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public function saveEntity($entity, $unlock = true)
}
}

if (!$entity->getCompany() && !empty($details['organization'])) {
if (!$entity->getCompany() && !empty($details['organization']) && $this->coreParametersHelper->getParameter('ip_lookup_create_organization', false)) {
$entity->addUpdatedField('company', $details['organization']);
}
}
Expand Down
24 changes: 24 additions & 0 deletions app/bundles/LeadBundle/Tests/Model/LeadModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,27 @@ protected function setUp()
$this->companyModelMock->method('getCompanyLeadRepository')->willReturn($this->companyLeadRepositoryMock);
}

public function testIpLookupDoesNotAddCompanyIfConfiguredSo()
{
$entity = new Lead();
$ipAddress = new IpAddress();

$ipAddress->setIpDetails(['organization' => 'Doctors Without Borders']);

$entity->addIpAddress($ipAddress);

$this->coreParametersHelperMock->expects($this->once())->method('getParameter')->with('ip_lookup_create_organization', false)->willReturn(false);
$this->fieldModelMock->method('getFieldListWithProperties')->willReturn([]);
$this->fieldModelMock->method('getFieldList')->willReturn([]);
$this->companyLeadRepositoryMock->expects($this->never())->method('getEntitiesByLead');
$this->companyModelMock->expects($this->never())->method('getEntities');

$this->leadModel->saveEntity($entity);

$this->assertNull($entity->getCompany());
$this->assertTrue(empty($entity->getUpdatedFields()['company']));
}

public function testIpLookupAddsCompanyIfDoesNotExistInEntity()
{
$companyFromIpLookup = 'Doctors Without Borders';
Expand All @@ -133,9 +154,11 @@ public function testIpLookupAddsCompanyIfDoesNotExistInEntity()

$entity->addIpAddress($ipAddress);

$this->coreParametersHelperMock->expects($this->once())->method('getParameter')->with('ip_lookup_create_organization', false)->willReturn(true);
$this->fieldModelMock->method('getFieldListWithProperties')->willReturn([]);
$this->fieldModelMock->method('getFieldList')->willReturn([]);
$this->companyLeadRepositoryMock->method('getEntitiesByLead')->willReturn([]);
$this->companyModelMock->expects($this->once())->method('getEntities')->willReturn([]);

$this->leadModel->saveEntity($entity);

Expand All @@ -155,6 +178,7 @@ public function testIpLookupAddsCompanyIfExistsInEntity()

$entity->addIpAddress($ipAddress);

$this->coreParametersHelperMock->expects($this->never())->method('getParameter');
$this->fieldModelMock->method('getFieldListWithProperties')->willReturn([]);
$this->fieldModelMock->method('getFieldList')->willReturn([]);
$this->companyLeadRepositoryMock->method('getEntitiesByLead')->willReturn([]);
Expand Down