Skip to content

Commit

Permalink
Merge branch '3.1' into 3
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 13, 2023
2 parents 551fec2 + 018618d commit 4bec304
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 13 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/BrokenExternalLinksReport.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 3 additions & 10 deletions client/src/js/BrokenExternalLinksReport.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@
self.setReloadContent(true);
self.poll();
},
error(e) {
if (typeof console !== 'undefined') {
// eslint-disable-next-line no-console
console.error(e);
}
error() {
self.buttonReset();
}
});
},
Expand Down Expand Up @@ -141,11 +138,7 @@
$('.external-links-report__create-report').poll();
}, 1000));
},
error(e) {
if (typeof console !== 'undefined') {
// eslint-disable-next-line no-console
console.error(e);
}
error() {
self.buttonReset();
}
});
Expand Down
7 changes: 7 additions & 0 deletions src/Controllers/CMSExternalLinksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SilverStripe\Control\Controller;
use Symbiote\QueuedJobs\Services\QueuedJobService;
use SilverStripe\Control\Middleware\HTTPCacheControlMiddleware;
use SilverStripe\Security\Permission;

class CMSExternalLinksController extends Controller
{
Expand All @@ -24,6 +25,9 @@ class CMSExternalLinksController extends Controller
*/
public function getJobStatus()
{
if (!Permission::check('CMS_ACCESS_CMSMain')) {
return $this->httpError(403, 'You do not have permission to access this resource');
}
// Set headers
HTTPCacheControlMiddleware::singleton()->setMaxAge(0);
$this->response
Expand All @@ -49,6 +53,9 @@ public function getJobStatus()
*/
public function start()
{
if (!Permission::check('CMS_ACCESS_CMSMain')) {
return $this->httpError(403, 'You do not have permission to access this resource');
}
// return if the a job is already running
$status = BrokenExternalPageTrackStatus::get_latest();
if ($status && $status->Status == 'Running') {
Expand Down
29 changes: 27 additions & 2 deletions tests/php/ExternalLinksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace SilverStripe\ExternalLinks\Tests;

use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\Dev\FunctionalTest;
use SilverStripe\ExternalLinks\Model\BrokenExternalPageTrackStatus;
use SilverStripe\ExternalLinks\Reports\BrokenExternalLinksReport;
use SilverStripe\ExternalLinks\Tasks\CheckExternalLinksTask;
Expand All @@ -13,7 +13,7 @@
use SilverStripe\i18n\i18n;
use SilverStripe\Reports\Report;

class ExternalLinksTest extends SapphireTest
class ExternalLinksTest extends FunctionalTest
{

protected static $fixture_file = 'ExternalLinksTest.yml';
Expand Down Expand Up @@ -125,4 +125,29 @@ public function testArchivedPagesAreHiddenFromReport()
// Ensure report does not list the link associated with an archived page
$this->assertEquals(3, BrokenExternalLinksReport::create()->sourceRecords()->count());
}

public function provideGetJobStatus(): array
{
return [
'ADMIN - valid permission' => ['ADMIN', 200],
'CMS_ACCESS_CMSMain - valid permission' => ['CMS_ACCESS_CMSMain', 200],
'VIEW_SITE - not enough permission' => ['VIEW_SITE', 403],
];
}

/**
* @dataProvider provideGetJobStatus
*/
public function testGetJobStatus(
string $permission,
int $expectedResponseCode
): void {
$this->logInWithPermission($permission);

$response = $this->get('admin/externallinks/start', null, ['Accept' => 'application/json']);
$this->assertEquals($expectedResponseCode, $response->getStatusCode());

$response = $this->get('admin/externallinks/getJobStatus', null, ['Accept' => 'application/json']);
$this->assertEquals($expectedResponseCode, $response->getStatusCode());
}
}

0 comments on commit 4bec304

Please sign in to comment.