Skip to content

Commit

Permalink
Merge pull request #76 from openjournalteam/prepare-publish-to-pkp
Browse files Browse the repository at this point in the history
Prepare publish to pkp
  • Loading branch information
rahmanramsi authored Sep 2, 2024
2 parents 04eca8e + 2f756ed commit 328a1c7
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 2.0.9.0 : 02 September 2024
- Add protection to access the control panel
- only allow admin to enable/disable plugin
- First version to release to pkp plugin gallery

### 2.0.8.2 : 02 May 2024
- Fix error handler when there's no error triggered

Expand Down
25 changes: 22 additions & 3 deletions OjtPageHandler.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,35 @@ class OjtPageHandler extends Handler

public function __construct($request)
{
if (!$request->getUser()) {
$request->redirect(null, 'login', null, null);
}
parent::__construct();

$this->addRoleAssignment(
[ROLE_ID_SITE_ADMIN, ROLE_ID_MANAGER],
['index', 'getInstalledPlugin', 'updatePanel', 'settings', 'saveSettings', 'downloadLog', 'reportBug', 'submitBug', 'checkUpdate', 'getPluginGalleryList', 'save', 'installPlugin', 'uninstallPlugin', 'checkPluginInstalled', 'toggleInstalledPlugin', 'resetSetting', 'support'],
);

$this->ojtPlugin = OjtPlugin::get();

$this->contextId = $this->ojtPlugin->getCurrentContextId();
$this->baseUrl = $this->ojtPlugin->getJournalURL();
}

/**
* @copydoc PKPHandler::authorize
*/
public function authorize($request, &$args, $roleAssignments) {
import('lib.pkp.classes.security.authorization.PolicySet');
$rolePolicy = new PolicySet(COMBINING_PERMIT_OVERRIDES);

import('lib.pkp.classes.security.authorization.RoleBasedHandlerOperationPolicy');
foreach ($roleAssignments as $role => $operations) {
$rolePolicy->addPolicy(new RoleBasedHandlerOperationPolicy($request, $role, $operations));
}
$this->addPolicy($rolePolicy);

return parent::authorize($request, $args, $roleAssignments);
}

public function updatePanel($args, $request)
{
$plugin = $this->ojtPlugin;
Expand Down
41 changes: 21 additions & 20 deletions OjtPlugin.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ public function init()
$paramHandler->handle();
}

/**
* Determine whether the plugin can be enabled.
* @return boolean
*/
function getCanEnable() {
return $this->getCanDisable();
}

/**
* @copydoc Plugin::getCanDisable()
*/
function getCanDisable() {
return $this->getRequest()->getUser()->hasRole([ROLE_ID_SITE_ADMIN], $this->getCurrentContextId());
}

public function apiUrl()
{
return static::API;
Expand Down Expand Up @@ -111,11 +126,11 @@ function fatalHandler()
$error = error_get_last();

// Sometimes fatalHandler called without error
if(!is_array($error)) return;
if (!is_array($error)) return;

// Fatal error, E_ERROR === 1
if (array_key_exists('type', $error) && !in_array($error['type'], [E_COMPILE_ERROR, E_ERROR])) return;

// Sometime there's no file in error so we need to check it first
if (!array_key_exists('file', $error)) return;

Expand Down Expand Up @@ -274,8 +289,8 @@ public function setupBackendPage($hookName, $args)
"isCurrent" => false
];

if($this->getSetting($this->getCurrentContextId(), 'show_support_link_ojs') ?? true){

if ($this->getSetting($this->getCurrentContextId(), 'show_support_link_ojs') ?? true) {
$menu['ojtSupportTicketing'] = [
'name' => 'Get OJT support',
'url' => $request->getDispatcher()->url($request, ROUTE_PAGE, $request->getContext()->getPath(), 'ojt', 'support'),
Expand Down Expand Up @@ -404,7 +419,7 @@ public function updatePanel($url)
$resource = \GuzzleHttp\Psr7\Utils::tryFopen($file_name, 'w');
$stream = \GuzzleHttp\Psr7\Utils::streamFor($resource);
$this->getHttpClient()->request('GET', $url, ['sink' => $stream]);

$zip = new ZipArchive;
if (!$zip->open($file_name)) {
unlink($file_name);
Expand Down Expand Up @@ -549,19 +564,6 @@ public function getActions($request, $actionArgs)
return $actions;
}

/**
* Check the folder this $folder is.
* @return bool - true if folder exist
*/
public function isPluginExist($folder)
{
if (!$folder) {
return false;
}

return is_dir(getcwd() . DIRECTORY_SEPARATOR . $this->getModulesPath() . $folder);
}

/**
* Removing plugin folder
* @return bool - true if success.
Expand Down Expand Up @@ -655,7 +657,6 @@ public function getPluginDownloadLink($pluginToken, $license = false, $journalUr
* throw error if there is something wrong
* @return bool - true if success.
*/

public function installPlugin($url)
{
$url = str_replace('https', 'http', $url);
Expand Down Expand Up @@ -742,7 +743,7 @@ public function isDiagnosticEnabled()

function str_contains($haystack, $needle)
{
if(!$haystack){
if (!$haystack) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<version>
<application>ojtPlugin</application>
<type>plugins.generic</type>
<release>2.0.8.2</release>
<date>2024-05-02</date>
<release>2.0.9.0</release>
<date>2024-09-02</date>
<lazy-load>0</lazy-load>
<class>OjtPlugin</class>
</version>

0 comments on commit 328a1c7

Please sign in to comment.