Add capabilities. Upgrade plugin to v3.7.4

This commit is contained in:
Jane Adelmann 2021-09-28 19:32:48 +03:00
parent 8a8f3a2763
commit 7f5a888f97
No known key found for this signature in database
GPG Key ID: 4CCF39DF30B8AF72
6 changed files with 110 additions and 5 deletions

View File

@ -0,0 +1,44 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package plagiarism_pchkorg
* @category plagiarism
* @copyright PlagiarismCheck.org, https://plagiarismcheck.org/
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace plagiarism_pchkorg\classes\permissions;
use context_course;
use context_module;
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}
class capability
{
/**
* ENABLE
*/
const ENABLE = 'plagiarism/pchkorg:enable';
/**
* VIEW_SIMILARITY
*/
const VIEW_SIMILARITY = 'plagiarism/pchkorg:viewsimilarity';
}

48
db/access.php Normal file
View File

@ -0,0 +1,48 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package plagiarism_pchkorg
* @category plagiarism
* @copyright PlagiarismCheck.org, https://plagiarismcheck.org/
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.');
}
$capabilities = array(
'plagiarism/pchkorg:enable' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
'coursecreator' => CAP_ALLOW
),
),
'plagiarism/pchkorg:viewsimilarity' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'teacher' => CAP_ALLOW,
'manager' => CAP_ALLOW,
'student' => CAP_ALLOW,
'coursecreator' => CAP_ALLOW
),
),
);

View File

@ -56,4 +56,6 @@ function xmldb_plagiarism_pchkorg_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2021072801, 'plagiarism', 'pchkorg');
}
return true;
}

View File

@ -57,7 +57,6 @@ $string['privacy:metadata:plagiarism_pchkorg_config'] = 'Table with module setti
$string['privacy:metadata:plagiarism_pchkorg_config:cm'] = 'Course module identity';
$string['privacy:metadata:plagiarism_pchkorg_config:name'] = 'Name of option';
$string['privacy:metadata:plagiarism_pchkorg_config:value'] = 'Value of option';
$string['privacy:metadata:plagiarism_pchkorg'] = 'Service for originality check plagiarismcheck.org';
$string['privacy:metadata:plagiarism_pchkorg:file'] =
'Submission attachment for originality checkprivacy:metadata:plagiarism_pchkorg';
@ -69,3 +68,5 @@ $string['pchkorg_label_title'] = 'PlagiarismCheck.org ID: %s; Similarity Score:
$string['pchkorg_label_result'] = 'ID: %s Similarity: %s%%';
$string['pchkorg_label_sent'] = 'ID: %s Sent';
$string['pchkorg_label_queued'] = 'In queue';
$string['pchkorg:enable'] = 'Allow to enable/disable PlagiarismCheck.org inside an activity';
$string['pchkorg:viewsimilarity'] = 'Allow to view similarity value from PlagiarismCheck.org';

14
lib.php
View File

@ -30,6 +30,9 @@ require_once($CFG->libdir . '/filelib.php');
require_once($CFG->libdir . '/accesslib.php');
require_once(__DIR__ . '/classes/plagiarism_pchkorg_config_model.php');
require_once(__DIR__ . '/classes/plagiarism_pchkorg_api_provider.php');
require_once(__DIR__ . '/classes/permissions/capability.class.php');
use plagiarism_pchkorg\classes\permissions\capability;
/**
* Class plagiarism_plugin_pchkorg
@ -74,6 +77,11 @@ class plagiarism_plugin_pchkorg extends plagiarism_plugin {
$context = context_module::instance($cmid);// Get context of course.
}
$canview = has_capability(capability::VIEW_SIMILARITY, $context);
if (!$canview) {
return '';
}
// SQL will be called only once per page. There is static result inside.
if (!$pchkorgconfigmodel->is_enabled_for_module($cmid)) {
return '';
@ -195,9 +203,9 @@ display: inline-block;"
$config = $pchkorgconfigmodel->get_system_config('pchkorg_use');
if ('1' != $config) {
return;
}
if (!isset($data->pchkorg_module_use)) {
return;
}
@ -239,7 +247,9 @@ display: inline-block;"
$pchkorgconfigmodel = new plagiarism_pchkorg_config_model();
$config = $pchkorgconfigmodel->get_system_config('pchkorg_use');
if ('1' == $config) {
$enabled = has_capability(capability::ENABLE, $context);
if ('1' == $config && $enabled) {
$defaultcmid = null;
$cm = optional_param('update', $defaultcmid, PARAM_INT);
if (null !== $cm) {

View File

@ -26,9 +26,9 @@ defined('MOODLE_INTERNAL') || die();
if (!isset($plugin)) {
$plugin = new stdClass();
}
$plugin->version = 2021072801;
$plugin->version = 2021092804;
$plugin->requires = 2017051500; // Requires Moodle 3.3 .
$plugin->release = 'v3.6.2';
$plugin->release = 'v3.7.4';
$plugin->maturity = MATURITY_STABLE;
$plugin->component = 'plagiarism_pchkorg';
$plugin->dependencies = array(