Skip to content
Snippets Groups Projects
Commit fd8cc397 authored by Brian Canini's avatar Brian Canini
Browse files

Merge branch 'field_permissions' into module-updates-rc

parents e4cf1304 8b2a61b3
No related branches found
No related tags found
No related merge requests found
Showing
with 139 additions and 101 deletions
......@@ -4876,44 +4876,48 @@
},
{
"name": "drupal/field_permissions",
"version": "1.0.0-rc2",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/field_permissions.git",
"reference": "8.x-1.0-rc2"
"reference": "8.x-1.0"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/field_permissions-8.x-1.0-rc2.zip",
"reference": "8.x-1.0-rc2",
"shasum": "bbc0d4215b24f2613a02a365a22f2039ebcea421"
"url": "https://ftp.drupal.org/files/projects/field_permissions-8.x-1.0.zip",
"reference": "8.x-1.0",
"shasum": "637895909b2877a69e04f76446addb4abc7492c5"
},
"require": {
"drupal/core": "~8.0"
"drupal/core": "^8 || ^9"
},
"type": "drupal-module",
"extra": {
"branch-alias": {
"dev-1.x": "1.x-dev"
},
"drupal": {
"version": "8.x-1.0-rc2",
"datestamp": "1545332280",
"version": "8.x-1.0",
"datestamp": "1591319671",
"security-coverage": {
"status": "not-covered",
"message": "RC releases are not covered by Drupal security advisories."
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
},
"branch-alias": {
"dev-8.x-1.x": "1.x-dev"
}
},
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0+"
"GPL-2.0-or-later"
],
"authors": [
{
"name": "RobLoach",
"homepage": "https://www.drupal.org/user/61114"
},
{
"name": "japerry",
"homepage": "https://www.drupal.org/user/45640"
},
{
"name": "jhedstrom",
"homepage": "https://www.drupal.org/user/208732"
......
......@@ -5020,46 +5020,50 @@
},
{
"name": "drupal/field_permissions",
"version": "1.0.0-rc2",
"version_normalized": "1.0.0.0-RC2",
"version": "1.0.0",
"version_normalized": "1.0.0.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/field_permissions.git",
"reference": "8.x-1.0-rc2"
"reference": "8.x-1.0"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/field_permissions-8.x-1.0-rc2.zip",
"reference": "8.x-1.0-rc2",
"shasum": "bbc0d4215b24f2613a02a365a22f2039ebcea421"
"url": "https://ftp.drupal.org/files/projects/field_permissions-8.x-1.0.zip",
"reference": "8.x-1.0",
"shasum": "637895909b2877a69e04f76446addb4abc7492c5"
},
"require": {
"drupal/core": "~8.0"
"drupal/core": "^8 || ^9"
},
"type": "drupal-module",
"extra": {
"branch-alias": {
"dev-1.x": "1.x-dev"
},
"drupal": {
"version": "8.x-1.0-rc2",
"datestamp": "1545332280",
"version": "8.x-1.0",
"datestamp": "1591319671",
"security-coverage": {
"status": "not-covered",
"message": "RC releases are not covered by Drupal security advisories."
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
},
"branch-alias": {
"dev-8.x-1.x": "1.x-dev"
}
},
"installation-source": "dist",
"notification-url": "https://packages.drupal.org/8/downloads",
"license": [
"GPL-2.0+"
"GPL-2.0-or-later"
],
"authors": [
{
"name": "RobLoach",
"homepage": "https://www.drupal.org/user/61114"
},
{
"name": "japerry",
"homepage": "https://www.drupal.org/user/45640"
},
{
"name": "jhedstrom",
"homepage": "https://www.drupal.org/user/208732"
......
......@@ -6,5 +6,10 @@
"support": {
"issues": "https://www.drupal.org/project/issues/field_permissions"
},
"license": "GPL-2.0+"
"license": "GPL-2.0-or-later",
"extra": {
"branch-alias": {
"dev-8.x-1.x": "1.x-dev"
}
}
}
......@@ -3,10 +3,10 @@ type: module
description: 'Set field-level permissions to create, update or view fields.'
configure: field_permissions.reports
package: field
# core: '8.x'
# Information added by Drupal.org packaging script on 2018-12-20
version: '8.x-1.0-rc2'
core: '8.x'
core_version_requirement: ^8 || ^9
# Information added by Drupal.org packaging script on 2020-06-05
version: '8.x-1.0'
project: 'field_permissions'
datestamp: 1545332284
datestamp: 1591319673
......@@ -29,7 +29,7 @@ interface FieldPermissionsServiceInterface {
* difficult to abstract down to the plugin level the way the report
* currently works.
*
* @deprecated This function will be removed before 8.x-1.0
* @deprecated This function will be removed before 8.x-2.0
*/
public static function getList($field_label = '');
......@@ -39,7 +39,7 @@ public static function getList($field_label = '');
* @return array
* An array of permission information keyed by role ID.
*
* @deprecated This function will be removed before 8.x-1.0
* @deprecated This function will be removed before 8.x-2.0
*/
public function getPermissionsByRole();
......@@ -52,7 +52,7 @@ public function getPermissionsByRole();
* An array of all permissions for all fields that implement the custom
* permission type.
*
* @deprecated This function will be removed before 8.x-1.0
* @deprecated This function will be removed before 8.x-2.0
*/
public function getAllPermissions();
......
......@@ -2,12 +2,10 @@ name: 'Field permissions test module'
type: module
description: 'Provides a test field permission plugin type.'
package: Testing
# core: '8.x'
dependencies:
- field_permissions:field_permissions
# Information added by Drupal.org packaging script on 2018-12-20
version: '8.x-1.0-rc2'
core: '8.x'
# Information added by Drupal.org packaging script on 2020-06-05
version: '8.x-1.0'
project: 'field_permissions'
datestamp: 1545332284
datestamp: 1591319673
......@@ -24,6 +24,13 @@ class FieldPermissionsCommentTest extends FieldPermissionsTestBase {
*/
protected $commentSubject;
/**
* The entity display repository.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
protected $entityDisplayRepository;
/**
* {@inheritdoc}
*/
......@@ -52,6 +59,8 @@ public function setUp() {
$this->fieldName = 'comment_body';
$this->commentSubject = 'Test subject comment';
$this->fieldText = 'A comment';
$this->entityDisplayRepository = $this->container->get('entity_display.repository');
}
/**
......@@ -113,7 +122,7 @@ protected function addCommentField() {
])->save();
// Entity form displays: assign widget settings for the 'default' form
// mode, and hide the field in all other form modes.
entity_get_form_display($entity_type, $bundle, 'default')
$this->entityDisplayRepository->getFormDisplay($entity_type, $bundle, 'default')
->setComponent($field_name, [
'type' => 'comment_default',
'weight' => 20,
......@@ -121,7 +130,7 @@ protected function addCommentField() {
->save();
// Entity view displays: assign widget settings for the 'default' view
// mode, and hide the field in all other view modes.
entity_get_display($entity_type, $bundle, 'default')
$this->entityDisplayRepository->getViewDisplay($entity_type, $bundle)
->setComponent($field_name, [
'label' => 'above',
'type' => 'comment_default',
......@@ -136,13 +145,13 @@ protected function addCommentField() {
]);
$field->save();
// Assign widget settings for the 'default' form mode.
entity_get_form_display('comment', $comment_type_id, 'default')
$this->entityDisplayRepository->getFormDisplay('comment', $comment_type_id, 'default')
->setComponent($this->fieldName, [
'type' => 'text_textarea',
])
->save();
// Assign display settings for the 'default' view mode.
entity_get_display('comment', $comment_type_id, 'default')
$this->entityDisplayRepository->getViewDisplay('comment', $comment_type_id)
->setComponent($this->fieldName, [
'label' => 'hidden',
'type' => 'text_default',
......@@ -189,15 +198,15 @@ protected function checkBaseCommentFieldFunctionality() {
$edit[$this->fieldName . '[0][value]'] = $this->fieldText;
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->drupalGet('node/' . $this->node->id());
$this->assertEscaped($this->fieldText);
$this->assertEscaped($this->commentSubject);
$this->assertSession()->assertEscaped($this->fieldText);
$this->assertSession()->assertEscaped($this->commentSubject);
$this->drupalLogout();
$this->drupalLogin($this->limitedUser);
// Test visibility first comment by admin.
$this->drupalGet('node/' . $this->node->id());
$this->assertEscaped($this->fieldText);
$this->assertText($this->commentSubject);
$this->assertSession()->assertEscaped($this->fieldText);
$this->assertSession()->pageTextContains($this->commentSubject);
// Add second comment to node.
$edit = [];
$edit['subject[0][value]'] = 'Limit User comment subject';
......@@ -205,8 +214,8 @@ protected function checkBaseCommentFieldFunctionality() {
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->drupalGet('node/' . $this->node->id());
// Test visibility second comment by limituser..
$this->assertText('Limit User comment subject');
$this->assertText('Limit User comment body');
$this->assertSession()->pageTextContains('Limit User comment subject');
$this->assertSession()->pageTextContains('Limit User comment body');
$this->drupalLogout();
}
......@@ -226,20 +235,20 @@ protected function checkPrivateCommentField() {
$this->drupalLogin($this->limitedUser);
$this->drupalGet('node/' . $this->node->id());
// Test hide body comment post by Adminuser but display subject..
$this->assertText($this->commentSubject);
$this->assertNoText($this->fieldText);
$this->assertSession()->pageTextContains($this->commentSubject);
$this->assertSession()->pageTextNotContains($this->fieldText);
// Test view your comment.
$this->assertText('Limit User comment subject');
$this->assertText('Limit User comment body');
$this->assertSession()->pageTextContains('Limit User comment subject');
$this->assertSession()->pageTextContains('Limit User comment body');
// Test edit your comment.
$this->drupalGet('comment/2/edit');
$this->assertText('Limit User comment body');
$this->assertSession()->pageTextContains('Limit User comment body');
// Logout and access as anonymous.
$this->drupalLogin($this->webUser);
$this->drupalGet('comment/2/edit');
// Comment body should be hidden.
$this->assertNoText('Limit User comment body');
$this->assertSession()->pageTextNotContains('Limit User comment body');
$this->drupalLogout();
}
......@@ -260,13 +269,13 @@ protected function checkCustomCommentField() {
// View your comment but not view field body comment post by admin.
$this->drupalGet('node/' . $this->node->id());
// Hide body comment post by Adminuser.
$this->assertNoText($this->fieldText);
$this->assertText($this->commentSubject);
$this->assertText('Limit User comment subject');
$this->assertText('Limit User comment body');
$this->assertSession()->pageTextNotContains($this->fieldText);
$this->assertSession()->pageTextContains($this->commentSubject);
$this->assertSession()->pageTextContains('Limit User comment subject');
$this->assertSession()->pageTextContains('Limit User comment body');
// Edit your comment not accesss to body field.
$this->drupalGet('comment/2/edit');
$this->assertNoText('Limit User comment body');
$this->assertSession()->pageTextNotContains('Limit User comment body');
$this->drupalLogout();
$this->drupalLogin($this->adminUser);
......@@ -279,7 +288,7 @@ protected function checkCustomCommentField() {
$this->drupalLogin($this->limitedUser);
// Test edit your comment edit field body.
$this->drupalGet('comment/2/edit');
$this->assertText('Limit User comment body');
$this->assertSession()->pageTextContains('Limit User comment body');
$this->drupalLogout();
$this->drupalLogin($this->adminUser);
......@@ -289,10 +298,10 @@ protected function checkCustomCommentField() {
$this->setCommentFieldPermissions(FieldPermissionTypeInterface::ACCESS_CUSTOM, $permission, $path);
// view.
$this->drupalGet('node/' . $this->node->id());
$this->assertText('Limit User comment body');
$this->assertSession()->pageTextContains('Limit User comment body');
// edit.
$this->drupalGet('comment/2/edit');
$this->assertText('Limit User comment body');
$this->assertSession()->pageTextContains('Limit User comment body');
$this->drupalLogout();
}
......@@ -310,18 +319,18 @@ protected function checkPrivateFieldPermission() {
// View.
$this->drupalGet('node/' . $this->node->id());
$this->assertNoText('Limit User comment body');
$this->assertSession()->pageTextNotContains('Limit User comment body');
// Edit.
$this->drupalGet('comment/2/edit');
$this->assertNoText('Limit User comment body');
$this->assertSession()->pageTextNotContains('Limit User comment body');
// Add permission access user private field.
$this->webUserRole->grantPermission('access private fields')->save();
// View.
$this->drupalGet('node/' . $this->node->id());
$this->assertText('Limit User comment body');
$this->assertSession()->pageTextContains('Limit User comment body');
// Edit.
$this->drupalGet('comment/2/edit');
$this->assertText('Limit User comment body');
$this->assertSession()->pageTextContains('Limit User comment body');
$this->drupalLogout();
}
......
......@@ -74,7 +74,7 @@ protected function addNode() {
$this->node = $this->drupalCreateNode(['type' => 'article', 'uid' => $this->limitedUser->id()]);
$this->drupalGet('node/' . $this->node->id());
$node_body = $this->node->getFields()['body']->getValue();
$this->assertText($node_body[0]['value']);
$this->assertSession()->responseContains($node_body[0]['value']);
}
/**
......@@ -82,13 +82,13 @@ protected function addNode() {
*/
protected function addNodeUi() {
$this->drupalGet('node/add/article');
$this->assertText('Body');
$this->assertSession()->pageTextContains('Body');
$edit = [];
$node_name = $this->randomMachineName();
$edit['body[0][value]'] = $this->randomString();
$edit['title[0][value]'] = $node_name;
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('Article @name has been created.', ['@name' => $node_name]));
$this->assertSession()->pageTextContains(t('Article @name has been created.', ['@name' => $node_name]));
}
/**
......@@ -97,7 +97,7 @@ protected function addNodeUi() {
protected function assertNodeFieldVisible() {
$field_value = $this->node->getFields()['body']->getValue();
$this->drupalGet('node/' . $this->node->id());
$this->assertText($field_value[0]['value']);
$this->assertSession()->pageTextContains($field_value[0]['value']);
}
/**
......@@ -107,7 +107,7 @@ protected function assertNodeFieldHidden() {
$field_value = $this->node->getFields()['body']->getValue();
$this->drupalGet('node/' . $this->node->id());
$this->assertSession()->statusCodeEquals(200);
$this->assertNoText($field_value[0]['value']);
$this->assertSession()->pageTextNotContains($field_value[0]['value']);
}
/**
......@@ -115,8 +115,8 @@ protected function assertNodeFieldHidden() {
*/
protected function assertNodeFieldEditAccess() {
$this->drupalGet('node/' . $this->node->id() . '/edit');
$this->assertText('Title');
$this->assertText('Body');
$this->assertSession()->pageTextContains('Title');
$this->assertSession()->pageTextContains('Body');
}
/**
......@@ -124,9 +124,9 @@ protected function assertNodeFieldEditAccess() {
*/
protected function assertNodeFieldEditNoAccess() {
$this->drupalGet('node/' . $this->node->id() . '/edit');
$this->assertResponse(200);
$this->assertText('Title');
$this->assertNoText('Body');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Title');
$this->assertSession()->pageTextNotContains('Body');
}
/**
......@@ -136,12 +136,12 @@ protected function checkFieldPermissionConfigurationEdit() {
$this->drupalLogin($this->webUser);
// Test page without admin field permission.
$this->drupalGet('admin/structure/types/manage/article/fields/node.article.body');
$this->assertResponse(200);
$this->assertNoText('Field visibility and permissions');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextNotContains('Field visibility and permissions');
$this->webUserRole->grantPermission('administer field permissions')->save();
// Test page with admin field permission.
$this->drupalGet('admin/structure/types/manage/article/fields/node.article.body');
$this->assertText('Field visibility and permissions');
$this->assertSession()->pageTextContains('Field visibility and permissions');
$this->drupalLogout();
}
......@@ -151,8 +151,8 @@ protected function checkFieldPermissionConfigurationEdit() {
protected function checkPermissionPage() {
$this->drupalLogin($this->adminUser);
$this->drupalGet(Url::fromRoute('user.admin_permissions'));
$this->assertText('Access other users private fields');
$this->assertText('Administer field permissions');
$this->assertSession()->pageTextContains('Access other users private fields');
$this->assertSession()->pageTextContains('Administer field permissions');
$this->drupalLogout();
}
......
......@@ -84,6 +84,11 @@ abstract class FieldPermissionsTestBase extends BrowserTestBase {
'field_permissions',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
......
......@@ -2,7 +2,6 @@
namespace Drupal\Tests\field_permissions\Functional;
use Drupal\Component\Utility\Unicode;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field_permissions\Plugin\FieldPermissionTypeInterface;
......@@ -15,12 +14,19 @@
*/
class FieldPermissionsUserTest extends FieldPermissionsTestBase {
/**
* The entity display repository.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
protected $entityDisplayRepository;
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp();
$this->fieldName = Unicode::strtolower($this->randomMachineName());
$this->fieldName = mb_strtolower($this->randomMachineName());
// Remove the '@' symbol so it isn't converted to an email link.
$this->fieldText = str_replace('@', '', $this->randomString(42));
......@@ -30,6 +36,8 @@ public function setUp() {
->grantPermission('administer users')
->save();
$this->entityDisplayRepository = $this->container->get('entity_display.repository');
$this->addUserField();
}
......@@ -73,15 +81,15 @@ protected function addUserField() {
'bundle' => 'user',
])->save();
entity_get_form_display('user', 'user', 'default')
$this->entityDisplayRepository->getFormDisplay('user', 'user', 'default')
->setComponent($this->fieldName)
->save();
entity_get_form_display('user', 'user', 'register')
$this->entityDisplayRepository->getFormDisplay('user', 'user', 'register')
->setComponent($this->fieldName)
->save();
entity_get_display('user', 'user', 'default')
$this->entityDisplayRepository->getViewDisplay('user', 'user')
->setComponent($this->fieldName)
->save();
}
......@@ -94,12 +102,12 @@ protected function addUserField() {
*/
protected function checkUserFieldEdit(UserInterface $account) {
$this->drupalGet($account->toUrl('edit-form'));
$this->assertText('Textfield');
$this->assertSession()->pageTextContains('Textfield');
$edit = [];
$edit[$this->fieldName . '[0][value]'] = $this->fieldText;
$this->drupalPostForm(NULL, $edit, t('Save'));
$this->drupalGet($account->toUrl());
$this->assertEscaped($this->fieldText);
$this->assertSession()->assertEscaped($this->fieldText);
}
/**
......@@ -110,7 +118,7 @@ protected function checkUserFieldEdit(UserInterface $account) {
*/
protected function assertUserFieldAccess(UserInterface $account) {
$this->drupalGet($account->toUrl());
$this->assertText('Textfield');
$this->assertSession()->pageTextContains('Textfield');
}
/**
......@@ -122,7 +130,7 @@ protected function assertUserFieldAccess(UserInterface $account) {
protected function assertUserFieldNoAccess(UserInterface $account) {
$this->drupalGet($account->toUrl());
$this->assertSession()->statusCodeEquals(200);
$this->assertNoText('Textfield');
$this->assertSession()->pageTextNotContains('Textfield');
}
/**
......@@ -133,7 +141,7 @@ protected function assertUserFieldNoAccess(UserInterface $account) {
*/
protected function assertUserEditFieldAccess(UserInterface $account) {
$this->drupalGet($account->toUrl('edit-form'));
$this->assertText('Textfield');
$this->assertSession()->pageTextContains('Textfield');
}
/**
......@@ -144,8 +152,8 @@ protected function assertUserEditFieldAccess(UserInterface $account) {
*/
protected function assertUserEditFieldNoAccess(UserInterface $account) {
$this->drupalGet($account->toUrl('edit-form'));
$this->assertResponse(200);
$this->assertNoText('Textfield');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextNotContains('Textfield');
}
/**
......
......@@ -26,6 +26,11 @@ class FieldReportTest extends BrowserTestBase {
'text',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Field storage.
*
......
......@@ -5,7 +5,7 @@
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
use Drupal\simpletest\UserCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
/**
* Integration tests for the field permission type plugin manager.
......
......@@ -58,7 +58,7 @@ public function testInvalidOperation() {
// Edit|view access allowed.
$account = $this->prophesize(AccountInterface::class);
$entity = $this->prophesize(EntityInterface::class);
$this->setExpectedException(\AssertionError::class, 'The operation is either "edit" or "view", "bad operation" given instead.');
$this->expectException(\AssertionError::class, 'The operation is either "edit" or "view", "bad operation" given instead.');
$this->plugin->hasFieldAccess('bad operation', $entity->reveal(), $account->reveal());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment