forked from aces/Loris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dashboard] Load project description from ajax and run through DOMPurify
This makes sure the Project Description on the dashboard runs through DOMPurify. In order to do that, it was also necessary to move the description from being loaded in a smarty template to being loaded from an AJAX call (so that we can import the DOMPurify module.) Fixes aces#8750
- Loading branch information
Showing
8 changed files
with
55 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,3 +64,5 @@ login: | |
mri_violations: | ||
target=mri_violations npm run compile | ||
|
||
dashboard: | ||
target=dashboard npm run compile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
js/welcome.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import DOMPurify from 'dompurify'; | ||
|
||
window.addEventListener('load', () => { | ||
fetch(loris.BaseURL + "/dashboard/projectdescription").then ( (resp) => { | ||
if (!resp.ok) { | ||
throw new Error('Could not get project description'); | ||
} | ||
return resp.json(); | ||
}).then ( (json) => { | ||
const el = document.getElementById("project-description"); | ||
el.innerHTML = DOMPurify.sanitize(json.Description); | ||
}).catch( (e) => console.error(e)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
namespace LORIS\dashboard; | ||
use \Psr\Http\Server\RequestHandlerInterface; | ||
use \Psr\Http\Message\ServerRequestInterface; | ||
use \Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* Get the project description to display in the welcome widget. | ||
* | ||
* @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 | ||
*/ | ||
|
||
class ProjectDescription extends \LORIS\Http\Endpoint | ||
{ | ||
public function handle(ServerRequestInterface $request) : ResponseInterface { | ||
$desc = $this->loris->getConfiguration()->getSetting('projectDescription'); | ||
return new \LORIS\Http\Response\JSON\OK(['Description' => $desc]); | ||
} | ||
public function _hasAccess(\User $user) { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
<h3 class="welcome">Welcome, {$username}.</h3> | ||
<p class="pull-right small login-time">Last login: {$last_login}</p> | ||
{if !is_null($project_description)} | ||
<p class="project-description">{$project_description}</p> | ||
{/if} | ||
<p id="project-description" class="project-description"></p> | ||
<script src="/dashboard/js/welcome.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters