Allow Core to override permission check

HFP-504 HFP-505
pull/38/head
Frode Petterson 2017-02-28 13:05:11 +01:00
parent a83ea9999d
commit 0f08031abf
1 changed files with 26 additions and 3 deletions

View File

@ -783,7 +783,7 @@ class H5PValidator {
} }
// The rest should be library folders // The rest should be library folders
elseif ($this->h5pF->mayUpdateLibraries()) { elseif ($this->h5pC->mayUpdateLibraries()) {
if (!is_dir($filePath)) { if (!is_dir($filePath)) {
// Ignore this. Probably a file that shouldn't have been included. // Ignore this. Probably a file that shouldn't have been included.
continue; continue;
@ -866,7 +866,7 @@ class H5PValidator {
foreach ($missingLibraries as $libString => $library) { foreach ($missingLibraries as $libString => $library) {
$this->h5pF->setErrorMessage($this->h5pF->t('Missing required library @library', array('@library' => $libString))); $this->h5pF->setErrorMessage($this->h5pF->t('Missing required library @library', array('@library' => $libString)));
} }
if (!$this->h5pF->mayUpdateLibraries()) { if (!$this->h5pC->mayUpdateLibraries()) {
$this->h5pF->setInfoMessage($this->h5pF->t("Note that the libraries may exist in the file you uploaded, but you're not allowed to upload new libraries. Contact the site administrator about this.")); $this->h5pF->setInfoMessage($this->h5pF->t("Note that the libraries may exist in the file you uploaded, but you're not allowed to upload new libraries. Contact the site administrator about this."));
} }
} }
@ -1303,7 +1303,7 @@ class H5PStorage {
* FALSE otherwise * FALSE otherwise
*/ */
public function savePackage($content = NULL, $contentMainId = NULL, $skipContent = FALSE, $options = array()) { public function savePackage($content = NULL, $contentMainId = NULL, $skipContent = FALSE, $options = array()) {
if ($this->h5pF->mayUpdateLibraries()) { if ($this->h5pC->mayUpdateLibraries()) {
// Save the libraries we processed during validation // Save the libraries we processed during validation
$this->saveLibraries(); $this->saveLibraries();
} }
@ -2907,6 +2907,29 @@ class H5PCore {
return $val; return $val;
} }
/**
* Check if the current user has permission to update and install new
* libraries.
*
* @param bool [$set] Optional, sets the permission
* @return bool
*/
public function mayUpdateLibraries($set = null) {
static $can;
if ($set !== null) {
// Use value set
$can = $set;
}
if ($can === null) {
// Ask our framework
$can = $this->h5pF->mayUpdateLibraries();
}
return $can;
}
} }
/** /**