diff --git a/classes/permissions/capability.class.php b/classes/permissions/capability.class.php new file mode 100644 index 0000000..7fb3ec9 --- /dev/null +++ b/classes/permissions/capability.class.php @@ -0,0 +1,44 @@ +. + +/** + * @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'; +} diff --git a/db/access.php b/db/access.php new file mode 100644 index 0000000..9152089 --- /dev/null +++ b/db/access.php @@ -0,0 +1,48 @@ +. +/** + * @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 + ), + ), +); diff --git a/db/upgrade.php b/db/upgrade.php index 6167b57..3d1890e 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -56,4 +56,6 @@ function xmldb_plagiarism_pchkorg_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2021072801, 'plagiarism', 'pchkorg'); } + + return true; } diff --git a/lang/en/plagiarism_pchkorg.php b/lang/en/plagiarism_pchkorg.php index 973ea5d..e7adfbf 100644 --- a/lang/en/plagiarism_pchkorg.php +++ b/lang/en/plagiarism_pchkorg.php @@ -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'; diff --git a/lib.php b/lib.php index e1f7fff..dc3f2e8 100644 --- a/lib.php +++ b/lib.php @@ -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) { diff --git a/version.php b/version.php index 8d6fb29..86f3fde 100644 --- a/version.php +++ b/version.php @@ -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(