Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support security (and other) alerts #72

Conversation

NightJar
Copy link
Contributor

@NightJar NightJar commented May 29, 2018

Required for #39 - but does not close it. Dependency of bringyourownideas/silverstripe-composer-security-checker#34


Needs a rebase yet, as includes a pre-rebase of #65

@NightJar NightJar force-pushed the pulls/1.0/support-security-alerts branch 5 times, most recently from 5760340 to 04f2849 Compare May 29, 2018 03:31
/* SS4 colours */
.package-summary__badge--good { background: #3fa142; }
.package-summary__badge--warning {background: #ff7f22;}
.package-summary__badge--bad {background: #d40404;}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please format this a little bit - two spaces for indentation would be ideal

public function getBadges()
{
$badgeDefinitions = [];
$this->extend('updageBadges', $badgeDefinitions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo* also might be good to put the extension point after the logic below that assembles the list

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, somewhere between 'update' and 'upgrade', ahaha


/**
* 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz add a return phpdoc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't auto-resolve because the line it's on hasn't changed.
But there is now a return php doc 2 lines down (after an empty one) in this file.

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

<% if $Badges %>
<% loop $Badges %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just loop Badges right? At worst it'll be empty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, yes. There are issues in v3 with looping empty lists resulting in at least one pass of the internal HTML (with no variables filled in).
In at least... there were. Call it habit if has changed at some point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you reference a framework issue please if this is a valid issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, tested. Guess it was fixed at some point in the past. Call it habit, now no longer needed (thank goodness!)


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May as well add $Title.XML, unless it's already escaped

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

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

a.package-summary__anchor {
Copy link
Contributor

@ScopeyNZ ScopeyNZ May 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering package-summary has been changed to site-summary above you should remain consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is a separate selector. It summarises a package (as the block*), not the site (as the gridfield does) - the site level summary being the one I updated.

*Block as the B in BEM.

@NightJar NightJar force-pushed the pulls/1.0/support-security-alerts branch 4 times, most recently from bfbca70 to 8ce9ca0 Compare May 29, 2018 05:04
@NightJar NightJar force-pushed the pulls/1.0/support-security-alerts branch from 8ce9ca0 to 31861fc Compare May 29, 2018 21:00
Copy link
Contributor

@robbieaverill robbieaverill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Couple of minor comments

*/
public function getBadges($badgeDefinitions = [])
{
$this->extend('updateBadges', $badgeDefinitions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment - I think this should go after the foreach.

if ($alerts) {
$summaryInfo = '<div class="site-summary message warning">' . implode("\n", $alerts) . '</div>';
$fields->unshift(LiteralField::create('AlertSummary', $summaryInfo));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you were to put this into a beforeUpdateCMSFields callback then extensions could remove or adjust it if they wanted to. They won't be able to at the moment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a thing in 3?
There's a rather rudimentary extension hook in getAlerts that allows modification (that's how the security module adds its one).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a thing in 3?

Yep:

public function getCMSFields()
{
    $this->beforeUpdateCMSFields(function (FieldList $fields) {
        // ...  modify field list here
    });
    return parent::getCMSFields();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah nah, this is a SS_Report though, not a DataObject (the only place the function is defined) :>

Me test give us an error:

Exception: Object->__call(): the method 'beforeupdatecmsfields' does not exist on 'SiteSummary', or the method is not public.

Hooray for tests! :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yep, you can still use beforeExtending callbacks if you want here but it’s ok :-D

@robbieaverill robbieaverill changed the base branch from master to 1 May 30, 2018 04:57
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).
@NightJar NightJar force-pushed the pulls/1.0/support-security-alerts branch from 31861fc to 3e724b2 Compare May 30, 2018 05:48
@robbieaverill robbieaverill merged commit 9d066b8 into bringyourownideas:1 May 30, 2018
@robbieaverill robbieaverill deleted the pulls/1.0/support-security-alerts branch May 30, 2018 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants