Skip to content

Commit

Permalink
Merge branch '2' into 3
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Feb 2, 2023
2 parents 4f7f6cc + 7d8909a commit 903c482
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 10 deletions.
5 changes: 1 addition & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@
}
},
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
},
"expose": [
"client/dist"
]
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
3 changes: 2 additions & 1 deletion lang/eo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ eo:
one: 'Unu subreteja domajno'
other: '{count} subretejaj domajnoj'
PROTOCOL_AUTOMATIC: Aŭtomata
PROTOCOL_DESCRIPTION: 'Marki ĉi tion kiel la aprioran domajnon por ĉi tiu subretejo'
PROTOCOL_DESCRIPTION: 'Kiam generante ligilojn al ĉi tiu subretejo, uzu la elektitan protokolon.'
PROTOCOL_HTTP: 'http://'
PROTOCOL_HTTPS: 'https://'
Protocol: Protokolo
SINGULARNAME: 'Subreteja domajno'
ISPRIMARY_DESCRIPTION: 'Marki ĉi tion kiel la aprioran domajnon por ĉi tiu subretejo'
SilverStripe\Subsites\Pages\SubsitesVirtualPage:
DESCRIPTION: 'Vidigas la enhavon de paĝo en alia subretejo'
OverrideNote: 'Anstataŭigas hereditan valoron el la fonto'
Expand Down
3 changes: 2 additions & 1 deletion lang/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ nl:
one: 'Een subsite domein'
other: '{count} subsite domeinen'
PROTOCOL_AUTOMATIC: Automatisch
PROTOCOL_DESCRIPTION: 'Markeer als standaard domein voor deze subsite'
PROTOCOL_DESCRIPTION: 'Wordt gebruikt bij het genereren van links naar deze subsite. <br />''Automatisch'' houdt in dat het huidige protocol gebruikt zal worden.'
PROTOCOL_HTTP: 'http://'
PROTOCOL_HTTPS: 'https://'
Protocol: Protocol
SINGULARNAME: 'Subsite Domein'
ISPRIMARY_DESCRIPTION: 'Dit is de standaard domeinnaam voor deze subsite'
SilverStripe\Subsites\Pages\SubsitesVirtualPage:
DESCRIPTION: 'Toon de inhoud van een pagina op een andere subsite'
OverrideNote: 'Overschrijft de overgenomen tekst van de gelinkte pagina'
Expand Down
6 changes: 3 additions & 3 deletions src/Extensions/FileSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ public function canEdit($member = null)
}

// Check the CMS_ACCESS_SecurityAdmin privileges on the subsite that owns this group
$subsiteID = SubsiteState::singleton()->getSubsiteId();
if ($subsiteID && $subsiteID == $this->owner->SubsiteID) {
return true;
$currentSubsiteID = SubsiteState::singleton()->getSubsiteId();
if ($currentSubsiteID && $currentSubsiteID !== $this->owner->SubsiteID) {
return false;
}

return SubsiteState::singleton()->withState(function (SubsiteState $newState) use ($member) {
Expand Down
5 changes: 4 additions & 1 deletion src/Extensions/SiteTreeSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use SilverStripe\Subsites\Service\ThemeResolver;
use SilverStripe\Subsites\State\SubsiteState;
use SilverStripe\View\SSViewer;
use SilverStripe\VersionedAdmin\Controllers\HistoryViewerController;

/**
* Extension for the SiteTree object to add subsites support
Expand Down Expand Up @@ -110,10 +111,12 @@ public function updateCMSFields(FieldList $fields)
$subsitesMap = new Map(ArrayList::create());
}

$viewingPageHistory = Controller::has_curr() && Controller::curr() instanceof HistoryViewerController;

// Master page edit field (only allowed from default subsite to avoid inconsistent relationships)
$isDefaultSubsite = $this->owner->SubsiteID == 0 || $this->owner->Subsite()->DefaultSite;

if ($isDefaultSubsite && $subsitesMap->count()) {
if ($isDefaultSubsite && $subsitesMap->count() && !$viewingPageHistory) {
$fields->addFieldToTab(
'Root.Main',
ToggleCompositeField::create(
Expand Down
4 changes: 4 additions & 0 deletions src/State/SubsiteState.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Resettable;
use SilverStripe\Dev\Deprecation;

/**
* SubsiteState provides static access to the current state for subsite related data during a request
Expand Down Expand Up @@ -33,6 +34,9 @@ public function getSubsiteId(): ?int
*/
public function setSubsiteId(?int $id): static
{
if (!ctype_digit((string) $id) && !is_null($id)) {
Deprecation::notice('2.8.0', 'Passing multiple IDs is deprecated, only pass a single ID instead.');
}
if (is_null($this->originalSubsiteId)) {
$this->originalSubsiteId = (int) $id;
}
Expand Down
61 changes: 61 additions & 0 deletions tests/php/FileSubsitesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SilverStripe\Forms\FieldList;
use SilverStripe\Subsites\Extensions\FileSubsites;
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Security\Member;

class FileSubsitesTest extends BaseSubsiteTest
{
Expand Down Expand Up @@ -65,4 +66,64 @@ public function testWritingSubsiteID()
$file->onAfterUpload();
$this->assertEquals($folder->SubsiteID, $file->SubsiteID);
}

/**
* @dataProvider provideTestCanEdit
*/
public function testCanEdit(
string $fileKey,
string $memberKey,
string $currentSubsiteKey,
bool $expected
): void {
$file = $this->objFromFixture(File::class, $fileKey);
$subsiteID = ($currentSubsiteKey === 'mainsite')
? 0 : $this->objFromFixture(Subsite::class, $currentSubsiteKey)->ID;
$member = $this->objFromFixture(Member::class, $memberKey);
Subsite::changeSubsite($subsiteID);
$this->assertSame($expected, $file->canEdit($member));
}

public function provideTestCanEdit(): array
{
$ret = [];
$data = [
// file
'subsite1file' => [
// member - has permissions to edit the file
'filetestyes' => [
// current subite => expected canEdit()
'subsite1' => true,
'subsite2' => false,
'mainsite' => true
],
// member - does not have permissions to edit the file
'filetestno' => [
'subsite1' => false,
'subsite2' => false,
'mainsite' => false
],
],
'mainsitefile' => [
'filetestyes' => [
'subsite1' => true,
'subsite2' => true,
'mainsite' => true
],
'filetestno' => [
'subsite1' => false,
'subsite2' => false,
'mainsite' => false
],
]
];
foreach (array_keys($data) as $fileKey) {
foreach (array_keys($data[$fileKey]) as $memberKey) {
foreach ($data[$fileKey][$memberKey] as $currentSubsiteKey => $expected) {
$ret[] = [$fileKey, $memberKey, $currentSubsiteKey, $expected];
}
}
}
return $ret;
}
}
26 changes: 26 additions & 0 deletions tests/php/SubsiteTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ SilverStripe\Security\Group:
Code: subsite1_group_via_role
AccessAllSubsites: 1
Roles: =>SilverStripe\Security\PermissionRole.role1
filetest:
Title: filetest
Code: filetest
AccessAllSubsites: 1
SilverStripe\Security\Permission:
admin:
Code: ADMIN
Expand Down Expand Up @@ -206,6 +210,9 @@ SilverStripe\Security\Permission:
adminsubsite1:
Code: ADMIN
GroupID: =>SilverStripe\Security\Group.subsite1admins
filetest:
Code: CMS_ACCESS_CMSMain
GroupID: =>SilverStripe\Security\Group.filetest

SilverStripe\Security\Member:
admin:
Expand Down Expand Up @@ -235,7 +242,26 @@ SilverStripe\Security\Member:
subsite1member2:
Email: [email protected]
Groups: =>SilverStripe\Security\Group.subsite1_group_via_role
filetestyes:
Email: [email protected]
Groups: =>SilverStripe\Security\Group.filetest
filetestno:
Email: [email protected]

SilverStripe\SiteConfig\SiteConfig:
config:
CanCreateTopLevelType: LoggedInUsers

SilverStripe\Assets\File:
subsite1file:
Name: subsitefile.pdf
Title: subsitefile
SubsiteID: =>SilverStripe\Subsites\Model\Subsite.subsite1
CanEditType: OnlyTheseUsers
EditorGroups: =>SilverStripe\Security\Group.filetest
mainsitefile:
Name: mainsitefile.pdf
Title: mainsitefile
SubsiteID: 0
CanEditType: OnlyTheseUsers
EditorGroups: =>SilverStripe\Security\Group.filetest

0 comments on commit 903c482

Please sign in to comment.