MDL-9469 mod_forum: add exportforum capability and checks
Part of MDL-66075
This commit is contained in:
@@ -633,4 +633,14 @@ class capability {
|
||||
|
||||
return $canstart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the user can export the whole forum (discussions and posts).
|
||||
*
|
||||
* @param stdClass $user The user object.
|
||||
* @return bool True if the user can export the forum or false otherwise.
|
||||
*/
|
||||
public function can_export_forum(stdClass $user) : bool {
|
||||
return has_capability('mod/forum:exportforum', $this->get_context(), $user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,6 +328,17 @@ $capabilities = array(
|
||||
'manager' => CAP_ALLOW
|
||||
)
|
||||
),
|
||||
'mod/forum:exportforum' => array(
|
||||
'riskbitmask' => RISK_PERSONAL,
|
||||
|
||||
'captype' => 'read',
|
||||
'contextlevel' => CONTEXT_MODULE,
|
||||
'archetypes' => array(
|
||||
'teacher' => CAP_ALLOW,
|
||||
'editingteacher' => CAP_ALLOW,
|
||||
'manager' => CAP_ALLOW,
|
||||
)
|
||||
),
|
||||
'mod/forum:exportpost' => array(
|
||||
|
||||
'riskbitmask' => RISK_PERSONAL,
|
||||
|
||||
@@ -42,6 +42,9 @@ if (empty($forum)) {
|
||||
}
|
||||
|
||||
$capabilitymanager = $managerfactory->get_capability_manager($forum);
|
||||
if (!$capabilitymanager->can_export_forum($USER)) {
|
||||
throw new moodle_exception('cannotexportforum', 'forum');
|
||||
}
|
||||
|
||||
$course = $forum->get_course_record();
|
||||
$coursemodule = $forum->get_course_module_record();
|
||||
|
||||
@@ -66,6 +66,7 @@ $string['cannotcreateinstanceforteacher'] = 'Could not create new course module
|
||||
$string['cannotdeletepost'] = 'You can\'t delete this post!';
|
||||
$string['cannotdeletediscussioninsinglediscussion'] = 'You cannot delete the first post in a single discussion';
|
||||
$string['cannoteditposts'] = 'You can\'t edit other people\'s posts!';
|
||||
$string['cannotexportforum'] = 'You cannot export this forum';
|
||||
$string['cannotfinddiscussion'] = 'Could not find the discussion in this forum';
|
||||
$string['cannotfindfirstpost'] = 'Could not find the first post in this forum';
|
||||
$string['cannotfindorcreateforum'] = 'Could not find or create a main announcements forum for the site';
|
||||
|
||||
+10
-2
@@ -5245,6 +5245,11 @@ function forum_extend_settings_navigation(settings_navigation $settingsnav, navi
|
||||
$PAGE->cm->context = context_module::instance($PAGE->cm->instance);
|
||||
}
|
||||
|
||||
$vaultfactory = mod_forum\local\container::get_vault_factory();
|
||||
$managerfactory = mod_forum\local\container::get_manager_factory();
|
||||
$forumvault = $vaultfactory->get_forum_vault();
|
||||
$forumentity = $forumvault->get_from_id($forumobject->id);
|
||||
|
||||
$params = $PAGE->url->params();
|
||||
if (!empty($params['d'])) {
|
||||
$discussionid = $params['d'];
|
||||
@@ -5380,8 +5385,11 @@ function forum_extend_settings_navigation(settings_navigation $settingsnav, navi
|
||||
$forumnode->add($string, $url, settings_navigation::TYPE_SETTING, null, null, new pix_icon('i/rss', ''));
|
||||
}
|
||||
|
||||
$url = new moodle_url('/mod/forum/export.php', ['id' => $forumobject->id]);
|
||||
$forumnode->add(get_string('export', 'mod_forum'), $url, navigation_node::TYPE_SETTING);
|
||||
$capabilitymanager = $managerfactory->get_capability_manager($forumentity);
|
||||
if ($capabilitymanager->can_export_forum($USER)) {
|
||||
$url = new moodle_url('/mod/forum/export.php', ['id' => $forumobject->id]);
|
||||
$forumnode->add(get_string('export', 'mod_forum'), $url, navigation_node::TYPE_SETTING);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2019052000; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2019052001; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2019051100; // Requires this Moodle version
|
||||
$plugin->component = 'mod_forum'; // Full name of the plugin (used for diagnostics)
|
||||
|
||||
Reference in New Issue
Block a user