Skip to content

Commit

Permalink
ENH More Actions button is hidden if Campaign is published (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabina-talipova authored Nov 7, 2023
1 parent c3142e4 commit 1c20dbf
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 12 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions client/src/containers/CampaignAdmin/CampaignAdminList.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class CampaignAdminList extends Component {
}

renderPreview(itemLinks, itemId) {
const { PreviewComponent, previewState } = this.props;
const { PreviewComponent, previewState, record: { State } } = this.props;
const { loading, error, errorCode } = this.state;

let previewClasses = [
Expand Down Expand Up @@ -384,16 +384,16 @@ class CampaignAdminList extends Component {
</div>
);
}

return (
<PreviewComponent
itemLinks={itemLinks}
itemId={itemId}
onBack={this.handleCloseItem}
moreActions={this.getMoreActions()}
className={previewClasses}
/>
);
const props = {
itemLinks,
itemId,
onBack: this.handleCloseItem,
className: previewClasses,
};
if (State === 'open') {
props.moreActions = this.getMoreActions();
}
return <PreviewComponent {...props}/>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function makeProps(obj = {}) {
itemListViewEndpoint: { url: '', method: 'POST' },
record: {
ID: 3,
State: 'open',
placeholderGroups: [
{
baseClass: 'SilverStripe\\CMS\\Model\\SiteTree',
Expand Down
3 changes: 3 additions & 0 deletions src/CampaignAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ public function removeCampaignItem(HTTPRequest $request)
return (new HTTPResponse(null, 404));
}

if ($campaign->State !== ChangeSet::STATE_OPEN) {
return (new HTTPResponse(null, 400));
}

$campaign->removeObject($item->Object());

Expand Down
2 changes: 2 additions & 0 deletions tests/behat/features/manage-campaigns.feature
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Feature: Manage campaigns
And I click on the ".grid-field__cell--drillable" element
And I press the "Publish campaign" button
And I confirm the dialog
And I should not see the "Publish campaign" button
And I should not see an "#tab-ActionMenus_MoreOptions" element

When I go to "/admin/pages"
Then the rendered HTML should not contain "badge status-addedtodraft"
Expand Down
36 changes: 36 additions & 0 deletions tests/php/CampaignAdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ReflectionClass;
use SilverStripe\CampaignAdmin\CampaignAdmin;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Dev\FunctionalTest;
Expand All @@ -13,6 +14,7 @@
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Versioned\ChangeSet;
use SilverStripe\Versioned\ChangeSetItem;

class CampaignAdminTest extends FunctionalTest
{
Expand Down Expand Up @@ -159,4 +161,38 @@ public function testReadCampaign(
$response = $this->get("/admin/campaigns/set/$changeSetID/show", null, ['Accept' => 'application/json']);
$this->assertEquals($expectedResponseCode, $response->getStatusCode());
}

public function provideRemoveCampaignItem(): array
{
return [
'open campaign' => [false, false, 204],
'published campaign' => [true, false, 400],
'incorrect campaign ID' => [true, true, 404],
];
}

/**
* @dataProvider provideRemoveCampaignItem
*/
public function testRemoveCampaignItem(
bool $isPublished,
bool $isWrongID,
int $expectedResponseCode,
): void {
$item = new SiteTree();
$item->write();
$changeset = new ChangeSet();
$changeset->write();
$changeset->addObject($item);

if ($isPublished) {
$changeset->publish();
}

$changesetitemID = ChangeSetItem::get()->where(['"ChangeSetID" = ?' => $changeset->ID])->first()->ID;
$changesetID = $isWrongID ? 12345 : $changeset->ID;

$response = $this->post("/admin/campaigns/removeCampaignItem/$changesetID/$changesetitemID", null);
$this->assertEquals($expectedResponseCode, $response->getStatusCode());
}
}

0 comments on commit 1c20dbf

Please sign in to comment.