Commit ef2ce910 authored by RoSk0's avatar RoSk0

Issue #2696661 by CTaPByK, RoSk0, slashrsm, thenchev: Use Entity module to...

Issue #2696661 by CTaPByK, RoSk0, slashrsm, thenchev: Use Entity module to provide Revision UI for individual entity
parent 7845856a
......@@ -4,15 +4,15 @@ administer individual types:
administer organization types:
title: 'Administer organization types'
description: 'Allows the user to edit the types of organization such as Supplier, etc.'
revert individual record:
title: 'Revert individual record'
description: 'Allows the user to have ability to revert individuals'
revert organization revisions:
title: 'Revert organization revisions'
description: 'Allows the user to have ability to revert organizations'
view all crm_core_individual revisions:
title: 'View all crm_core_individual revisions'
'restrict access': TRUE
revert all crm_core_individual revisions:
title: 'Revert all crm_core_individual revisions'
'restrict access': TRUE
view all crm_core_organization revisions:
title: 'View all crm_core_organization revisions'
'restrict access': TRUE
......
......@@ -210,16 +210,6 @@ class Individual extends RevisionableContentEntityBase implements IndividualInte
return $this->get('sex')->value;
}
/**
* {@inheritdoc}
*/
public function preSaveRevision(EntityStorageInterface $storage, \stdClass $record) {
parent::preSaveRevision($storage, $record);
$account = \Drupal::currentUser();
$record->uid = $account->id();
}
/**
* Gets the primary address.
*
......
......@@ -45,7 +45,7 @@ class IndividualAccessControlHandler extends EntityAccessControlHandler {
// generation for reverting bundles of individuals.
return AccessResult::allowedIfHasPermissions($account, [
'administer crm_core_individual entities',
'revert individual record',
'revert all crm_core_individual revisions',
], 'OR');
}
}
......
......@@ -312,8 +312,11 @@ class IndividualUiTest extends WebTestBase {
*/
public function testIndividualRevisions() {
$user = $this->drupalCreateUser([
'administer crm_core_individual entities',
'create crm_core_individual entities',
'view any crm_core_individual entity',
'edit any crm_core_individual entity',
'view all crm_core_individual revisions',
'revert all crm_core_individual revisions',
]);
$this->drupalLogin($user);
......@@ -333,6 +336,29 @@ class IndividualUiTest extends WebTestBase {
$this->assertText('rev 1');
$this->drupalGet('crm-core/individual/1/revisions/2/view');
$this->assertText('rev 2');
/** @var \Drupal\crm_core_contact\ContactInterface $individual */
$individual = Individual::create(['type' => 'customer']);
$individual->save();
$revision = clone $individual;
$revision->setNewRevision(TRUE);
$revision->isDefaultRevision(FALSE);
$revision->save();
$this->drupalGet($revision->toUrl('version-history'));
// Assert we have one revision link and current revision.
$this->assertLinkByHref('crm-core/individual/' . $individual->id() . '/revisions/5/view');
$this->assertLinkByHref('crm-core/individual/' . $individual->id());
// Assert we have revision revert link.
$this->assertLinkByHref('crm-core/individual/' . $individual->id() . '/revisions/5/revert');
$this->drupalGet('crm-core/individual/' . $individual->id() . '/revisions/5/revert');
$this->assertResponse(200);
// Check view revision route.
$this->drupalGet('crm-core/individual/' . $individual->id() . '/revisions/5/view');
$this->assertRaw('Nameless #2');
}
/**
......
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