/**
  * Build item resource from a changeset
  *
  * @param ChangeSet $changeSet
  * @return array
  */
 protected function getChangeSetResource(ChangeSet $changeSet)
 {
     $hal = ['_links' => ['self' => ['href' => $this->SetLink($changeSet->ID)]], 'ID' => $changeSet->ID, 'Name' => $changeSet->Name, 'Created' => $changeSet->Created, 'LastEdited' => $changeSet->LastEdited, 'State' => $changeSet->State, 'IsInferred' => $changeSet->IsInferred, 'canEdit' => $changeSet->canEdit(), 'canPublish' => false, '_embedded' => ['items' => []]];
     // Before presenting the changeset to the client,
     // synchronise it with new changes.
     try {
         $changeSet->sync();
         $hal['Description'] = $changeSet->getDescription();
         $hal['canPublish'] = $changeSet->canPublish();
         foreach ($changeSet->Changes() as $changeSetItem) {
             if (!$changeSetItem) {
                 continue;
             }
             /** @var ChangesetItem $changeSetItem */
             $resource = $this->getChangeSetItemResource($changeSetItem);
             $hal['_embedded']['items'][] = $resource;
         }
         $hal['ChangesCount'] = count($hal['_embedded']['items']);
         // An unexpected data exception means that the database is corrupt
     } catch (UnexpectedDataException $e) {
         $hal['Description'] = 'Corrupt database! ' . $e->getMessage();
         $hal['ChangesCount'] = '-';
     }
     return $hal;
 }
 public function testCanEdit()
 {
     // Create changeset containing all items (unpublished)
     $this->logInWithPermission('ADMIN');
     $changeSet = new ChangeSet();
     $changeSet->write();
     $base = $this->objFromFixture(ChangeSetTest_Base::class, 'base');
     $changeSet->addObject($base);
     $changeSet->sync();
     $this->assertEquals(5, $changeSet->Changes()->count());
     // Check canEdit
     Session::clear("loggedInAs");
     $this->assertFalse($changeSet->canEdit());
     $this->logInWithPermission('SomeWrongPermission');
     $this->assertFalse($changeSet->canEdit());
     $this->logInWithPermission('CMS_ACCESS_CampaignAdmin');
     $this->assertTrue($changeSet->canEdit());
 }
 /**
  * Build item resource from a changeset
  *
  * @param ChangeSet $changeSet
  * @return array
  */
 protected function getChangeSetResource(ChangeSet $changeSet)
 {
     // Before presenting the changeset to the client,
     // synchronise it with new changes.
     $changeSet->sync();
     $hal = ['_links' => ['self' => ['href' => $this->SetLink($changeSet->ID)]], 'ID' => $changeSet->ID, 'Name' => $changeSet->Name, 'Description' => $changeSet->getDescription(), 'Created' => $changeSet->Created, 'LastEdited' => $changeSet->LastEdited, 'State' => $changeSet->State, 'canEdit' => $changeSet->canEdit(), 'canPublish' => $changeSet->canPublish(), '_embedded' => ['items' => []]];
     foreach ($changeSet->Changes() as $changeSetItem) {
         if (!$changeSetItem) {
             continue;
         }
         /** @var ChangesetItem $changeSetItem */
         $resource = $this->getChangeSetItemResource($changeSetItem);
         $hal['_embedded']['items'][] = $resource;
     }
     $hal['ChangesCount'] = count($hal['_embedded']['items']);
     return $hal;
 }