Commit 0f81027e authored by RoSk0's avatar RoSk0

Issue #2926665 by RoSk0: Remove ability to turn off contact bundle.

parent 7d8eeeb1
......@@ -4,12 +4,6 @@ administer individual types:
administer organization types:
title: 'Administer organization types'
description: 'Allows the user to edit the types of organization such as Supplier, etc.'
view disabled individual types:
title: 'View disabled individual types'
description: 'Allows the user to view disabled individual types'
view disabled organization types:
title: 'View disabled organization types'
description: 'Allows the user to view disabled organization types'
revert individual record:
title: 'Revert individual record'
description: 'Allows the user to have ability to revert individuals'
......
......@@ -29,39 +29,3 @@ entity.crm_core_organization_type.collection:
_entity_list: 'crm_core_organization_type'
requirements:
_permission: 'administer organization types'
entity.crm_core_individual_type.enable:
path: '/admin/structure/crm-core/individual-types/{crm_core_individual_type}/enable'
defaults:
_entity_form: 'crm_core_individual_type.toggle'
_title: 'Enable individual type'
op: 'enable'
requirements:
_entity_access: 'crm_core_individual_type.enable'
entity.crm_core_individual_type.disable:
path: '/admin/structure/crm-core/individual-types/{crm_core_individual_type}/disable'
defaults:
_entity_form: 'crm_core_individual_type.toggle'
_title: 'Disable individual type'
op: 'disable'
requirements:
_entity_access: 'crm_core_individual_type.disable'
entity.crm_core_organization_type.enable:
path: '/admin/structure/crm-core/organization-types/{crm_core_organization_type}/enable'
defaults:
_entity_form: 'crm_core_organization_type.toggle'
_title: 'Enable organization type'
op: 'enable'
requirements:
_entity_access: 'crm_core_organization_type.enable'
entity.crm_core_organization_type.disable:
path: '/admin/structure/crm-core/organization-types/{crm_core_organization_type}/disable'
defaults:
_entity_form: 'crm_core_organization_type.toggle'
_title: 'Disable organization type'
op: 'disable'
requirements:
_entity_access: 'crm_core_organization_type.disable'
<?php
/**
* @file
* Altering queries.
*/
/**
* Implements hook_views_query_alter
*/
function crm_core_contact_ui_views_query_alter(&$view, &$query) {
// we are limiting the visibility of the contact listing
// view to people without proper permissions
if ($view->name == 'crm_core_contacts') {
if (!user_access('view disabled contact types')) {
// we will have to join the tables first
// we have to respect if any filter has already created the join
if (!array_key_exists('crm_core_contact_type', $query->table_queue)) {
$query->table_queue['crm_core_contact_type'] = array(
'table' => 'crm_core_contact_type',
'num' => 1,
'alias' => 'crm_core_contact_type',
'relationship' => 'crm_core_contact',
);
$query->table_queue['crm_core_contact_type']['join'] = new views_join();
$query->table_queue['crm_core_contact_type']['join']->definition = array(
'left_field' => 'type',
'field' => 'type',
'table' => 'crm_core_contact_type',
'left_table' => 'crm_core_contact',
);
$query->table_queue['crm_core_contact_type']['join']->extra_type = 'AND';
$query->table_queue['crm_core_contact_type']['join']->table = 'crm_core_contact_type';
$query->table_queue['crm_core_contact_type']['join']->left_table = 'crm_core_contact';
$query->table_queue['crm_core_contact_type']['join']->left_field = 'type';
$query->table_queue['crm_core_contact_type']['join']->field = 'type';
$query->table_queue['crm_core_contact_type']['join']->type = 'LEFT';
$query->table_queue['crm_core_contact_type']['join']->adjusted = 1;
}
if (!array_key_exists('crm_core_contact_type', $query->tables['crm_core_contact'])) {
$query->tables['crm_core_contact']['crm_core_contact_type'] = array(
'count' => '1',
'alias' => 'crm_core_contact_type',
);
}
// let's construct another where clause component
$count = (empty($query->where)) ? 0 : count($query->where);
$query->where[$count]['type'] = 'AND';
$query->where[$count]['args'] = array();
$query->where[$count]['conditions'][0] = array(
'field' => 'crm_core_contact_type.disabled',
'value' => 0,
'operator' => '=',
);
}
}
}
\ No newline at end of file
......@@ -15,12 +15,4 @@ interface ContactTypeInterface {
*/
public static function getNames();
/**
* Loads all enabled Contact|Organization Types.
*
* @return \Drupal\crm_core_contact\ContactTypeInterface[]
* An array of contact|organization types indexed by their IDs.
*/
public static function loadActive();
}
......@@ -21,7 +21,6 @@ use Drupal\crm_core_contact\ContactTypeInterface;
* "form" = {
* "default" = "Drupal\crm_core_contact\Form\IndividualTypeForm",
* "delete" = "Drupal\Core\Entity\EntityDeleteForm",
* "toggle" = "Drupal\crm_core_contact\Form\IndividualTypeToggleForm",
* },
* "list_builder" = "Drupal\crm_core_contact\ContactTypeListBuilder",
* "route_provider" = {
......@@ -32,7 +31,6 @@ use Drupal\crm_core_contact\ContactTypeInterface;
* entity_keys = {
* "id" = "type",
* "label" = "name",
* "status" = "disabled",
* },
* config_export = {
* "name",
......@@ -45,8 +43,6 @@ use Drupal\crm_core_contact\ContactTypeInterface;
* "add-form" = "/admin/structure/crm-core/individual-types/add",
* "edit-form" = "/admin/structure/crm-core/individual-types/{crm_core_individual_type}",
* "delete-form" = "/admin/structure/crm-core/individual-types/{crm_core_individual_type}/delete",
* "enable" = "/admin/structure/crm-core/individual-types/{crm_core_individual_type}/enable",
* "disable" = "/admin/structure/crm-core/individual-types/{crm_core_individual_type}/disable",
* }
* )
*/
......@@ -112,17 +108,6 @@ class IndividualType extends ConfigEntityBundleBase implements ContactTypeInterf
);
}
/**
* {@inheritdoc}
*/
public static function loadActive() {
$ids = \Drupal::entityQuery('crm_core_individual')
->condition('status', TRUE)
->execute();
return IndividualType::loadMultiple($ids);
}
/**
* {@inheritdoc}
*/
......
......@@ -21,7 +21,6 @@ use Drupal\entity\Entity\RevisionableEntityBundleInterface;
* "form" = {
* "default" = "Drupal\crm_core_contact\Form\OrganizationTypeForm",
* "delete" = "Drupal\Core\Entity\EntityDeleteForm",
* "toggle" = "Drupal\crm_core_contact\Form\OrganizationTypeToggleForm",
* },
* "list_builder" = "Drupal\crm_core_contact\OrganizationTypeListBuilder",
* "route_provider" = {
......@@ -32,7 +31,6 @@ use Drupal\entity\Entity\RevisionableEntityBundleInterface;
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "status" = "disabled",
* },
* config_export = {
* "label",
......@@ -45,8 +43,6 @@ use Drupal\entity\Entity\RevisionableEntityBundleInterface;
* "add-form" = "/admin/structure/crm-core/organization-types/add",
* "edit-form" = "/admin/structure/crm-core/organization-types/{crm_core_organization_type}",
* "delete-form" = "/admin/structure/crm-core/organization-types/{crm_core_organization_type}/delete",
* "enable" = "/admin/structure/crm-core/organization-types/{crm_core_organization_type}/enable",
* "disable" = "/admin/structure/crm-core/organization-types/{crm_core_organization_type}/disable",
* }
* )
*/
......@@ -119,17 +115,6 @@ class OrganizationType extends ConfigEntityBundleBase implements ContactTypeInte
);
}
/**
* {@inheritdoc}
*/
public static function loadActive() {
$ids = \Drupal::entityQuery('crm_core_organization_type')
->condition('status', TRUE)
->execute();
return OrganizationType::loadMultiple($ids);
}
/**
* {@inheritdoc}
*/
......
<?php
namespace Drupal\crm_core_contact\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Form for enable/disable individual types.
*/
class IndividualTypeToggleForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
$args = array(
'%toggle' => $this->getRequest()->get('op'),
'%type' => $this->getEntity()->label(),
);
$question = '';
switch ($this->getRequest()->get('op')) {
case 'enable':
$question = $this->t('Are you sure you want to enable the individual type %type?', $args);
break;
case 'disable':
$question = $this->t('Are you sure you want to disable the individual type %type?', $args);
break;
}
return $question;
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->t('When a individual type is disabled, you cannot add any individuals to this individual type. You will also not be able to search for individuals of disabled individual type.');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
switch ($this->getRequest()->get('op')) {
case 'disable':
$text = $this->t('Disable');
break;
default:
case 'enable':
$text = $this->t('Enable');
break;
}
return $text;
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.crm_core_individual_type.collection');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
switch ($this->getRequest()->get('op')) {
case 'disable':
$action = $this->t('disabled');
$this->entity->disable()->save();
break;
default:
case 'enable':
$action = $this->t('enabled');
$this->entity->enable()->save();
break;
}
$t_args = array(
'%name' => $this->entity->label(),
'%toggle' => $action,
);
drupal_set_message($this->t('The individual type %name has been %toggle.', $t_args));
$form_state->setRedirect('entity.crm_core_individual_type.collection');
}
}
<?php
namespace Drupal\crm_core_contact\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Class OrganizationTypeToggleForm.
*
* Form for enable/disable organization types.
*
* @package Drupal\crm_core_contact\Form
*/
class OrganizationTypeToggleForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
$args = array(
'%toggle' => $this->getRequest()->get('op'),
'%type' => $this->getEntity()->label(),
);
$question = '';
switch ($this->getRequest()->get('op')) {
case 'enable':
$question = $this->t('Are you sure you want to enable the organization type %type?', $args);
break;
case 'disable':
$question = $this->t('Are you sure you want to disable the organization type %type?', $args);
break;
}
return $question;
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->t('When a organization type is disabled, you cannot add any organizations to this organization type. You will also not be able to search for organizations of disabled organization type.');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
switch ($this->getRequest()->get('op')) {
case 'disable':
$text = $this->t('Disable');
break;
default:
case 'enable':
$text = $this->t('Enable');
break;
}
return $text;
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.crm_core_organization_type.collection');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
switch ($this->getRequest()->get('op')) {
case 'disable':
$action = $this->t('disabled');
$this->entity->disable()->save();
break;
default:
case 'enable':
$action = $this->t('enabled');
$this->entity->enable()->save();
break;
}
$t_args = array(
'%name' => $this->entity->label(),
'%toggle' => $action,
);
drupal_set_message($this->t('The organization type %name has been %toggle.', $t_args));
$form_state->setRedirect('entity.crm_core_organization_type.collection');
}
}
......@@ -24,13 +24,6 @@ class IndividualTypeAccessControlHandler extends EntityAccessControlHandler {
}
switch ($operation) {
case 'enable':
// Only disabled individual type can be enabled.
return AccessResult::allowedIf(!$entity->status());
case 'disable':
return AccessResult::allowedIf($entity->status());
case 'delete':
// If individual instance of this individual type exist, you can't
// delete it.
......
......@@ -24,19 +24,12 @@ class OrganizationTypeAccessControlHandler extends EntityAccessControlHandler {
}
switch ($operation) {
case 'enable':
// Only disabled organization type can be enabled.
return AccessResult::allowedIf(!$entity->status());
case 'disable':
return AccessResult::allowedIf($entity->status());
case 'delete':
// If organization instance of this organization type exist, you can't
// delete it.
$results = \Drupal::entityQuery('crm_core_organization')
->condition('type', $entity->id())
->execute();
->condition('type', $entity->id())
->execute();
return AccessResult::allowedIf(empty($results));
case 'view':
......
......@@ -259,28 +259,9 @@ class IndividualUiTest extends WebTestBase {
// When I visit the individual type admin page.
$this->drupalGet('admin/structure/crm-core/individual-types');
// Then I should see edit, enable, delete but no enable links for existing
// contacts.
// Then I should see edit, and delete links for existing contacts.
$this->assertIndividualTypeLink('customer', 'Edit link for customer.');
$this->assertIndividualTypeLink('customer/disable', 'Disable link for customer.');
$this->assertNoIndividualTypeLink('customer/enable', 'No enable link for customer.');
$this->assertIndividualTypeLink('customer/delete', 'Delete link for customer.');
// Given the 'customer' individual type is disabled.
$this->drupalPostForm('admin/structure/crm-core/individual-types/customer/disable', [], 'Disable');
// When I visit the individual type admin page.
$this->drupalGet('admin/structure/crm-core/individual-types');
// Then I should see an enable link.
$this->assertIndividualTypeLink('customer/enable', 'Enable link for customer.');
// And I should not see a disable link.
$this->assertNoIndividualTypeLink('customer/disable', 'No disable link for customer.');
// When I enable 'customer'.
$this->drupalPostForm('admin/structure/crm-core/individual-types/customer/enable', [], 'Enable');
// Then I should see a disable link.
$this->assertIndividualTypeLink('customer/disable', 'Disable link for customer.');
// Given there is a individual of type 'customer.'.
Individual::create(['type' => 'customer'])->save();
......@@ -295,10 +276,12 @@ class IndividualUiTest extends WebTestBase {
// When I edit the individual type.
$this->drupalGet('admin/structure/crm-core/individual-types/customer');
$this->assertResponse(200);
// @todo Assert for a positive fact to ensure being on the correct page.
// Then I should see "Save customer type" button.
$this->assertRaw(t('Save individual type'), 'Save individual type button is present.');
// Then I should not see a delete link.
$this->assertNoIndividualTypeLink('individual/delete', 'No delete link on individual type form.');
$this->assertNoIndividualTypeLink('customer/delete', 'No delete link on individual type form.');
}
/**
......
......@@ -198,22 +198,13 @@ class OrganizationUiTest extends WebTestBase {
$this->drupalGet('admin/structure/crm-core/organization-types');
// Test that there are edit, disable, delete but no enable links for
// existing organizations.
// Test that there are edit, delete links for existing organizations.
$this->assertOrganizationTypeLink('supplier', 'Edit link for supplier.');
$this->assertOrganizationTypeLink('supplier/disable', 'Disable link for supplier.');
$this->assertNoOrganizationTypeLink('supplier/enable', 'No enable link for supplier.');
$this->assertOrganizationTypeLink('supplier/delete', 'Delete link for supplier.');
$this->assertOrganizationTypeLink('household', 'Edit link for household.');
$this->assertOrganizationTypeLink('household/disable', 'Disable link for household.');
$this->assertNoOrganizationTypeLink('household/enable', 'No enable link for household.');
$this->assertOrganizationTypeLink('household/delete', 'Delete link for household.');
// Test OrganizationType::loadActive().
$active_organization_types = OrganizationType::loadActive();
$this->assertEqual(count($active_organization_types), 2, 'There are two active organization types.');
// Add another organization type.
$second_organization_type = OrganizationType::create([
'id' => 'new_organization_type',
......@@ -222,40 +213,8 @@ class OrganizationUiTest extends WebTestBase {
]);
$second_organization_type->save();
// Test that there are two active organization types.
$active_organization_types = OrganizationType::loadActive();
$this->assertEqual(count($active_organization_types), 3, 'There are three active organization types.');
// Disable the 'supplier' organization type.
$this->drupalPostForm('admin/structure/crm-core/organization-types/supplier/disable', array(), 'Disable');
$this->drupalGet('admin/structure/crm-core/organization-types');
// Test that there are two active organization type.
$active_organization_types = OrganizationType::loadActive();
$this->assertEqual(count($active_organization_types), 2, 'There are two active organization types.');
$this->assertEqual($active_organization_types['new_organization_type']->id(), $second_organization_type->id());
$this->assertEqual($active_organization_types['household']->id(), 'household');
// Disable the 'New organization type'.
$this->drupalPostForm('admin/structure/crm-core/organization-types/new_organization_type/disable', array(), 'Disable');
// Disable the 'household type'.
$this->drupalPostForm('admin/structure/crm-core/organization-types/household/disable', array(), 'Disable');
// Test that there are no active types.
$active_organization_types = OrganizationType::loadActive();
$this->assertEqual(count($active_organization_types), 0, 'There are no active organization types.');
// Test that there is now an enable and no disable link.
$this->assertOrganizationTypeLink('supplier/enable', 'Enable link for supplier.');
$this->assertNoOrganizationTypeLink('supplier/disable', 'No disable link for supplier.');
// Enable 'supplier'.
$this->drupalPostForm('admin/structure/crm-core/organization-types/supplier/enable', array(), 'Enable');
// Test that there is now a disable link.
$this->assertOrganizationTypeLink('supplier/disable', 'Disable link for supplier.');
// Create organization of type 'supplier.'.
Organization::create(array('type' => 'supplier'))->save();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment