Commit e98b794e authored by Rudy Gnodde's avatar Rudy Gnodde Committed by Oliver Bartsch
Browse files

[FEATURE] Option to copy page access settings from parent page

Add option to copy page access settings from the parent page.
Set by setting Page TSconfig TCEMAIN.permissions.* to "copyFromParent".
Can be set for groupid, userid, user, group and everybody.
For example: TCEMAIN.permissions.groupid = copyFromParent

Resolves: #89917
Releases: master
Change-Id: I4dd11177f533fd752f3b75287db2d8cb60c67005
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62750

Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Jochen's avatarJochen <rothjochen@gmail.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Jochen's avatarJochen <rothjochen@gmail.com>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent 8f69889f
......@@ -91,20 +91,39 @@ class PagePermissionAssembler
*/
protected function setTSconfigPermissions(array $fieldArray, array $tsconfig): array
{
if ((string)($tsconfig['userid'] ?? '') !== '') {
$fieldArray['perms_userid'] = (int)$tsconfig['userid'];
}
if ((string)($tsconfig['groupid'] ?? '') !== '') {
$fieldArray['perms_groupid'] = (int)$tsconfig['groupid'];
}
if ((string)($tsconfig['user'] ?? '') !== '') {
$fieldArray['perms_user'] = $this->assemblePermissions($tsconfig['user']);
}
if ((string)($tsconfig['group'] ?? '') !== '') {
$fieldArray['perms_group'] = $this->assemblePermissions($tsconfig['group']);
}
if ((string)($tsconfig['everybody'] ?? '') !== '') {
$fieldArray['perms_everybody'] = $this->assemblePermissions($tsconfig['everybody']);
$parentPermissions = [];
if (in_array('copyFromParent', $tsconfig, true)) {
$parentPermissions = BackendUtility::getRecordWSOL('pages', $fieldArray['pid'], 'uid,perms_userid,perms_groupid,perms_user,perms_group,perms_everybody') ?? [];
}
if (
(string)($tsconfig['userid'] ?? '') !== ''
&& ($tsconfig['userid'] !== 'copyFromParent' || isset($parentPermissions['perms_userid']))
) {
$fieldArray['perms_userid'] = $tsconfig['userid'] === 'copyFromParent' ? (int)$parentPermissions['perms_userid'] : (int)$tsconfig['userid'];
}
if (
(string)($tsconfig['groupid'] ?? '') !== ''
&& ($tsconfig['groupid'] !== 'copyFromParent' || isset($parentPermissions['perms_groupid']))
) {
$fieldArray['perms_groupid'] = $tsconfig['groupid'] === 'copyFromParent' ? (int)$parentPermissions['perms_groupid'] : (int)$tsconfig['groupid'];
}
if (
(string)($tsconfig['user'] ?? '') !== ''
&& ($tsconfig['user'] !== 'copyFromParent' || isset($parentPermissions['perms_user']))
) {
$fieldArray['perms_user'] = $tsconfig['user'] === 'copyFromParent' ? (int)$parentPermissions['perms_user'] : $this->assemblePermissions($tsconfig['user']);
}
if (
(string)($tsconfig['group'] ?? '') !== ''
&& ($tsconfig['group'] !== 'copyFromParent' || isset($parentPermissions['perms_group']))
) {
$fieldArray['perms_group'] = $tsconfig['group'] === 'copyFromParent' ? (int)$parentPermissions['perms_group'] : $this->assemblePermissions($tsconfig['group']);
}
if (
(string)($tsconfig['everybody'] ?? '') !== ''
&& ($tsconfig['everybody'] !== 'copyFromParent' || isset($parentPermissions['perms_everybody']))
) {
$fieldArray['perms_everybody'] = $tsconfig['everybody'] === 'copyFromParent' ? (int)$parentPermissions['perms_everybody'] : $this->assemblePermissions($tsconfig['everybody']);
}
return $fieldArray;
}
......
.. include:: ../../Includes.txt
=======================================================
Feature: #89738 - Copy page access settings from parent
=======================================================
See :issue:`89738`
Description
===========
It is now possible to copy page access permissions from the parent page,
while creating new pages. This is possible, using :typoscript:`copyFromParent`
as value for one of the page TSconfig :typoscript:`TCEMAIN.permissions.*`
subkeys.
Example
=======
.. code-block:: typoscript
TCEMAIN.permissions.userid = copyFromParent
TCEMAIN.permissions.groupid = copyFromParent
TCEMAIN.permissions.user = copyFromParent
TCEMAIN.permissions.group = copyFromParent
TCEMAIN.permissions.everybody = copyFromParent
.. index:: Backend, ext:core
......@@ -89,14 +89,50 @@ TCEMAIN.permissions.everybody = show,delete
}
/**
* @return array
* @test
*/
protected function insertPage(): array
public function newPageReceivesOverriddenPageTsPermissionSetFromParent()
{
// pid 88 comes from ImportDefault
$result = $this->actionService->createNewRecord('pages', 88, [
$this->backendUser->user['uid'] = 13;
$this->backendUser->firstMainGroup = 14;
$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPermissions'] = [
'user' => 'show,editcontent,edit,delete',
'group' => 'show,editcontent,new',
'everybody' => 'show',
];
$GLOBALS['TYPO3_CONF_VARS']['BE']['defaultPageTSconfig'] = '
TCEMAIN.permissions.userid = 12
TCEMAIN.permissions.groupid = 42
TCEMAIN.permissions.user = show,edit
TCEMAIN.permissions.group = show,delete
TCEMAIN.permissions.everybody = show,delete
';
$parent = $this->insertPage(88, [
'title' => 'Test page',
'TSconfig' => '
TCEMAIN.permissions.userid = copyFromParent
TCEMAIN.permissions.groupid = copyFromParent
TCEMAIN.permissions.user = copyFromParent
TCEMAIN.permissions.group = copyFromParent
TCEMAIN.permissions.everybody = copyFromParent
',
]);
$record = $this->insertPage((int)$parent['uid']);
self::assertEquals(12, $record['perms_userid']);
self::assertEquals(42, $record['perms_groupid']);
self::assertEquals(Permission::PAGE_SHOW + Permission::PAGE_EDIT, $record['perms_user']);
self::assertEquals(Permission::PAGE_SHOW + Permission::PAGE_DELETE, $record['perms_group']);
self::assertEquals(Permission::PAGE_SHOW + Permission::PAGE_DELETE, $record['perms_everybody']);
}
/**
* @return array
*/
protected function insertPage(int $pageId = 88, array $fields = ['title' => 'Test page'])
{
// pid 88 comes from ImportDefault
$result = $this->actionService->createNewRecord('pages', $pageId, $fields);
$recordUid = $result['pages'][0];
return BackendUtility::getRecord('pages', $recordUid);
}
......
Supports Markdown
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