Skip to content

Commit

Permalink
Add various extension points for security updates
Browse files Browse the repository at this point in the history
In order to display information from
`bringyourownideas/silverstripe-composer-security-updates` we need to be
able to add various information to the summary, and badges which were
previously 'not a thing'. This commit makes badges 'a thing', makes them
extensible, and provides a rudimentary way to alter the summary
information for the on scren report.

Also added were namespaces for the GridFieldComponents, but this should
affect nothing (should not affect anything).
  • Loading branch information
Dylan Wagstaff committed May 29, 2018
1 parent d4cdf17 commit 5760340
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 19 deletions.
36 changes: 24 additions & 12 deletions css/sitesummary.css
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
.package-summary{
.site-summary {
margin-top: 0;
}

.package-summary .message {
.site-summary.message,
.site-summary .message {
margin-left: 0;
margin-right: 0;
margin-top: 0;
}

.package-summary .grid-refresh-button {
.site-summary .grid-refresh-button {
margin-bottom: 0;
}

.package-summary__title {
display:block;
}

/* Due to a rule applied to `.cms .ss-gridfield > div` we have to be specific here */
.cms .ss-gridfield > div.site-summary__clearfix {
margin: 0;
Expand All @@ -26,19 +23,34 @@
margin-bottom: 12px;
}

.package-summary table.ss-gridfield-table tr td.col-Summary {
padding: 0;
}

a.package-summary__anchor {
color: inherit;
text-decoration: inherit;
display: block;
padding: 8px;
padding: 0 8px;
margin: 0 -8px;
}

a.package-summary__anchor:hover,
a.package-summary__anchor:active {
color: inherit;
text-decoration: inherit;
}

.package-summary__badge {
font-size: 0.8em;
padding: 3px 5px;
background: grey;
border-radius: 2px;
color: white;
position: relative;
top: -1px;
}
/* SS4 colours */
.package-summary__badge--good { background: #3fa142; }
.package-summary__badge--warning {background: #ff7f22;}
.package-summary__badge--bad {background: #d40404;}

.package-summary__description {
display:block;
}
5 changes: 4 additions & 1 deletion src/Forms/GridFieldHtmlFragment.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?php

namespace BringYourOwnIdeas\Maintenance\Forms;

use GridField_HTMLProvider;

/**
* Facilitates adding arbitrary HTML to grid fields
*
* @package forms
* @subpackage fields-gridfield
*/

class GridFieldHtmlFragment implements GridField_HTMLProvider
{
/**
Expand Down
8 changes: 6 additions & 2 deletions src/Forms/GridFieldLinkButton.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<?php

namespace BringYourOwnIdeas\Maintenance\Forms;

use ArrayData;
use GridField_HTMLProvider;

/**
* A button that contains a link to an URL.
*
* @package forms
* @subpackage fields-gridfield
*/

class GridFieldLinkButton implements GridField_HTMLProvider
{
/**
Expand Down Expand Up @@ -43,7 +47,7 @@ public function getHTMLFragments($gridField)
$fragment = ArrayData::create([
'Link' => $this->link,
'Caption' => _t('GridFieldLinkButton.LINK_TO_ADDONS', 'Explore Addons')
])->renderWith(__CLASS__);
])->renderWith('GridFieldLinkButton');

return [$this->targetFragment => $fragment];
}
Expand Down
17 changes: 16 additions & 1 deletion src/Forms/GridFieldRefreshButton.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
<?php

namespace BringYourOwnIdeas\Maintenance\Forms;

use ArrayData;
use CheckForUpdatesJob;
use Convert;
use GridField;
use GridField_ActionProvider;
use GridField_FormAction;
use GridField_HTMLProvider;
use GridField_URLHandler;
use Injector;
use QueuedJob;
use QueuedJobService;
use Requirements;

/**
* Adds a "Refresh" button to the bottom or top of a GridField.
*
* @package forms
* @subpackage fields-gridfield
*/

class GridFieldRefreshButton implements GridField_HTMLProvider, GridField_ActionProvider, GridField_URLHandler
{
/**
Expand Down
29 changes: 28 additions & 1 deletion src/Model/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,34 @@ public function getTitle()
*/
public function getSummary()
{
return $this->renderWith('Package_summary');
$summary = $this->renderWith('Package_summary');
$this->extend('updateSummary', $summary);
return $summary;
}

/**
* Gives the summary template {@see getSummary()} a list of badges to show against a package
*
* badgeDefinitions are in the format [$title => $type] where:
* title is the unique string to display
* type is an optional class attribute (applied as a BEM modified, by default)
*
* @return ArrayList
*/
public function getBadges()
{
$badgeDefinitions = [];
$this->extend('updageBadges', $badgeDefinitions);

$badges = ArrayList::create();
foreach ($badgeDefinitions as $title => $type) {
$badges->push(ArrayData::create([
'Title' => $title,
'Type' => $type,
]));
}

return $badges;
}

/**
Expand Down
28 changes: 27 additions & 1 deletion src/Reports/SiteSummary.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

use BringYourOwnIdeas\Maintenance\Forms\GridFieldHtmlFragment;
use BringYourOwnIdeas\Maintenance\Forms\GridFieldLinkButton;
use BringYourOwnIdeas\Maintenance\Forms\GridFieldRefreshButton;

/**
* A report listing all installed modules used in this site (from a cache).
*/
Expand Down Expand Up @@ -59,7 +63,7 @@ public function getReportField()
/** @var GridFieldConfig $config */
$config = $grid->getConfig();

$grid->addExtraClass('package-summary');
$grid->addExtraClass('site-summary');

/** @var GridFieldExportButton $exportButton */
$exportButton = $config->getComponentByType(GridFieldExportButton::class);
Expand All @@ -84,6 +88,28 @@ public function getReportField()
return $grid;
}

public function getCMSFields()
{
$fields = parent::getCMSFields();
$alerts = $this->getAlerts();
if ($alerts) {
$summaryInfo = '<div class="site-summary message warning">' . implode("\n", $alerts) . '</div>';
$fields->unshift(LiteralField::create('AlertSummary', $summaryInfo));
}
return $fields;
}

/**
* Return a list of alerts to display in a message box above the report
* A combination of free text fields - combined alerts as opposed to a message box per alert.
*/
protected function getAlerts()
{
$alerts = [];
$this->extend('updateAlerts', $alerts);
return $alerts;
}

/**
* Extract CMS and Framework version details from the records in the report
*
Expand Down
11 changes: 10 additions & 1 deletion templates/Package_summary.ss
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<a href="https://addons.silverstripe.org/add-ons/$Name.ATT" title="<%t SiteSummary.AddonsLinkTitle "View {package} on addons.silverstripe.org" package=$Title.ATT %>" class="package-summary__anchor" target="_blank" rel="noopener">
<strong class="package-summary__title">$Title.XML</strong>
<% if $Description %><span class="package-summary__description">$Description.XML</span><% end_if %>

<% if $Badges %>
<% loop $Badges %>
<span class="package-summary__badge<% if $Type %> package-summary__badge--$Type.ATT<% end_if %>">$Title</span>
<% end_loop %>
<% end_if %>

<% if $Description %>
<span class="package-summary__description">$Description.XML</span>
<% end_if %>
</a>

0 comments on commit 5760340

Please sign in to comment.