Skip to content

Commit

Permalink
API Remove silverstripe/campaign-admin integration support
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Nov 20, 2024
1 parent 43758ab commit 29730b8
Show file tree
Hide file tree
Showing 11 changed files with 4 additions and 163 deletions.
8 changes: 0 additions & 8 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ SilverStripe\Core\Injector\Injector:
SilverStripe\Forms\FileHandleField:
class: SilverStripe\AssetAdmin\Forms\UploadField
---
Name: assetadmincampaigns
Only:
moduleexists: 'silverstripe/campaign-admin'
---
SilverStripe\AssetAdmin\Forms\FileFormFactory:
extensions:
- 'SilverStripe\AssetAdmin\Extensions\CampaignAdminExtension'
---
Name: assetadminmodals
---
SilverStripe\Admin\ModalController:
Expand Down
2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_sslink-file.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_ssmedia.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion client/src/containers/AssetAdmin/AssetAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,6 @@ class AssetAdmin extends Component {
onClose: this.handleCloseFile,
onSubmit: this.handleSubmitEditor,
onUnpublish: this.handleUnpublish,
addToCampaignSchemaUrl: config.form.addToCampaignForm.schemaUrl
};

return <EditorComponent {...editorProps} />;
Expand Down
3 changes: 0 additions & 3 deletions client/src/containers/AssetAdmin/tests/AssetAdmin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ function makeProps(obj = {}) {
fileSearchForm: {
schemaUrl: '',
},
addToCampaignForm: {
schemaUrl: '',
}
},
},
fileId: null,
Expand Down
76 changes: 0 additions & 76 deletions code/Controller/AssetAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use SilverStripe\Assets\Image;
use SilverStripe\Assets\Storage\AssetNameGenerator;
use SilverStripe\Assets\Upload;
use SilverStripe\CampaignAdmin\AddToCampaignHandler;
use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
Expand Down Expand Up @@ -97,7 +96,6 @@ class AssetAdmin extends AssetAdminOpen implements PermissionProvider
'folderCreateForm',
'fileEditForm',
'fileHistoryForm',
'addToCampaignForm',
'fileInsertForm',
'fileEditorLinkForm',
'schema',
Expand Down Expand Up @@ -292,9 +290,6 @@ public function getClientConfig(): array
'fileSelectForm' => [
'schemaUrl' => $this->Link('schema/fileSelectForm')
],
'addToCampaignForm' => [
'schemaUrl' => $this->Link('schema/addToCampaignForm')
],
'fileHistoryForm' => [
'schemaUrl' => $this->Link('schema/fileHistoryForm')
],
Expand Down Expand Up @@ -1425,77 +1420,6 @@ public function generateThumbnails(File $file, $thumbnailLinks = false)
return $links;
}

/**
* Action handler for adding pages to a campaign
*/
public function addtocampaign(array $data, Form $form): HTTPResponse
{
$id = $data['ID'];
$record = File::get()->byID($id);

$handler = AddToCampaignHandler::create($this, $record, 'addToCampaignForm');
$response = $handler->addToCampaign($record, $data);
$message = $response->getBody();
if (empty($message)) {
return $response;
}

// Send extra "message" data with schema response
$extraData = ['message' => $message];
$schemaId = Controller::join_links($this->Link('schema/addToCampaignForm'), $id);
return $this->getSchemaResponse($schemaId, $form, null, $extraData);
}

/**
* Url handler for add to campaign form
*
* @param HTTPRequest $request
* @return Form
*/
public function addToCampaignForm($request)
{
// Get ID either from posted back value, or url parameter
$id = $request->param('ID') ?: $request->postVar('ID');
return $this->getAddToCampaignForm($id);
}

/**
* @param int $id
* @return Form|HTTPResponse
*/
public function getAddToCampaignForm($id)
{
// Get record-specific fields
$record = File::get()->byID($id);

if (!$record) {
$this->jsonError(404, _t(
__CLASS__.'.ErrorNotFound',
"That {Type} couldn't be found",
['Type' => File::singleton()->i18n_singular_name()]
));
return null;
}
if (!$record->canView()) {
$this->jsonError(403, _t(
__CLASS__.'.ErrorItemPermissionDenied',
"You don't have the necessary permissions to modify {ObjectTitle}",
['ObjectTitle' => $record->i18n_singular_name()]
));
return null;
}

$handler = AddToCampaignHandler::create($this, $record, 'addToCampaignForm');
$form = $handler->Form($record);

$form->setValidationResponseCallback(function (ValidationResult $errors) use ($form, $id) {
$schemaId = Controller::join_links($this->Link('schema/addToCampaignForm'), $id);
return $this->getSchemaResponse($schemaId, $form, $errors);
});

return $form;
}

/**
* @return Upload
*/
Expand Down
39 changes: 0 additions & 39 deletions code/Extensions/CampaignAdminExtension.php

This file was deleted.

1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"silverstripe/frameworktest": "^2",
"squizlabs/php_codesniffer": "^3.7",
"silverstripe/cms": "^6",
"silverstripe/campaign-admin": "^3",
"silverstripe/standards": "^1",
"phpstan/extension-installer": "^1.3"
},
Expand Down
30 changes: 1 addition & 29 deletions tests/php/Forms/FileFormBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace SilverStripe\AssetAdmin\Tests\Forms;

use SilverStripe\AssetAdmin\Controller\AssetAdmin;
use SilverStripe\AssetAdmin\Extensions\CampaignAdminExtension;
use SilverStripe\AssetAdmin\Forms\FileFormFactory;
use SilverStripe\AssetAdmin\Forms\FolderFormFactory;
use SilverStripe\AssetAdmin\Forms\ImageFormFactory;
Expand Down Expand Up @@ -52,9 +51,6 @@ protected function tearDown(): void

public function testEditFileForm()
{
// Ensure campaign-admin extension is not applied!
Config::modify()->remove(FileFormFactory::class, 'extensions');

$this->logInWithPermission('ADMIN');

$file = $this->objFromFixture(File::class, 'file1');
Expand Down Expand Up @@ -95,32 +91,14 @@ public function testEditFileForm()
$this->assertNotNull($form->Actions()->fieldByName('PopoverActions.action_replacefile'));
$this->assertNotNull($form->Actions()->fieldByName('PopoverActions.action_delete'));
$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_unpublish'));

// Add to campaign should not be there by default
$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_addtocampaign'));

// Add extension for campaign-admin
Config::modify()->merge(
FileFormFactory::class,
'extensions',
[CampaignAdminExtension::class]
);

$builder = new FileFormFactory();
$form = $builder->getForm($controller, 'EditForm', ['Record' => $file, 'RequireLinkText' => false]);

// Add to campaign should now be available
$this->assertNotNull($form->Actions()->fieldByName('PopoverActions.action_addtocampaign'));
}

public function testEditFileFormWithPermissions()
{
// Add extension for campaign-admin
FileFormFactory::add_extension(CampaignAdminExtension::class);
// Add extension to simulate different permissions
File::add_extension(FileExtension::class);

$this->logInWithPermission('CMS_ACCESS_CampaignAdmin');
$this->logInWithPermission('CMS_ACCESS_AssetAdmin');

/** @var File $file */
$file = $this->objFromFixture(File::class, 'file1');
Expand All @@ -135,7 +113,6 @@ public function testEditFileFormWithPermissions()
$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_delete'));
$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_replacefile'));

$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_addtocampaign'));
$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_unpublish'));

FileExtension::$canDelete = false;
Expand All @@ -144,7 +121,6 @@ public function testEditFileFormWithPermissions()
$form = $builder->getForm($controller, 'EditForm', ['Record' => $file, 'RequireLinkText' => false]);
$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_delete'));
$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_replacefile'));
$this->assertNotNull($form->Actions()->fieldByName('PopoverActions.action_addtocampaign'));
$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_unpublish'));

FileExtension::$canDelete = true;
Expand All @@ -153,7 +129,6 @@ public function testEditFileFormWithPermissions()
$form = $builder->getForm($controller, 'EditForm', ['Record' => $file]);
$this->assertNotNull($form->Actions()->fieldByName('PopoverActions.action_delete'));
$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_replacefile'));
$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_addtocampaign'));
$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_unpublish'));

FileExtension::$canDelete = false;
Expand All @@ -162,7 +137,6 @@ public function testEditFileFormWithPermissions()
$form = $builder->getForm($controller, 'EditForm', ['Record' => $file]);
$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_delete'));
$this->assertNotNull($form->Actions()->fieldByName('PopoverActions.action_replacefile'));
$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_addtocampaign'));
$this->assertNull($form->Actions()->fieldByName('PopoverActions.action_unpublish'));

FileExtension::$canDelete = true;
Expand All @@ -173,10 +147,8 @@ public function testEditFileFormWithPermissions()
$form = $builder->getForm($controller, 'EditForm', ['Record' => $file, 'RequireLinkText' => false]);
$this->assertNotNull($form->Actions()->fieldByName('PopoverActions.action_delete'));
$this->assertNotNull($form->Actions()->fieldByName('PopoverActions.action_replacefile'));
$this->assertNotNull($form->Actions()->fieldByName('PopoverActions.action_addtocampaign'));
$this->assertNotNull($form->Actions()->fieldByName('PopoverActions.action_unpublish'));

FileFormFactory::remove_extension(CampaignAdminExtension::class);
File::remove_extension(FileExtension::class);
}

Expand Down
3 changes: 0 additions & 3 deletions tests/php/Forms/FolderCreateFormFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ class FolderCreateFormFactoryTest extends SapphireTest
{
public function testEditFileForm()
{
// Ensure campaign-admin extension is not applied!
Config::modify()->remove(FileFormFactory::class, 'extensions');

$this->logInWithPermission('ADMIN');

$controller = new AssetAdmin();
Expand Down

0 comments on commit 29730b8

Please sign in to comment.