MDL-61444 question: replace all question tag capability checks

This commit is contained in:
Simey Lameze
2018-02-19 14:21:59 +08:00
parent 1451c07e05
commit e2795e8632
6 changed files with 15 additions and 14 deletions
+1 -1
View File
@@ -1 +1 @@
define(["jquery","core/fragment","core/str","core/modal_events","core/modal_factory","core/notification","core/custom_interaction_events","core_question/repository","core_question/selectors"],function(a,b,c,d,e,f,g,h,i){var j=function(a){a.find(i.actions.save).prop("disabled",!1)},k=function(a){a.find(i.actions.save).prop("disabled",!0)},l=function(a){return a.getBody().find("form").serialize()},m=function(a){var b=a.find(i.containers.loadingIcon);b.removeClass("hidden")},n=function(a){var b=a.find(i.containers.loadingIcon);b.addClass("hidden")},o=function(h){var l=e.create({type:e.types.SAVE_CANCEL,large:!1},[h,i.actions.edittags]).then(function(a){return c.get_string("questiontags","question").then(function(b){return a.setTitle(b),b}).fail(f.exception),a.getRoot().on(d.save,function(b){var c=a.getBody().find("form");c.submit(),b.preventDefault()}),a.getRoot().on("submit","form",function(b){p(a,h).then(function(){a.hide()}).fail(f.exception),b.preventDefault(),b.stopPropagation()}),a});h.on(g.events.activate,i.actions.edittags,function(c){var d=a(c.currentTarget),e=d.data("questionid"),g=!!d.data("canedit"),o=d.data("contextid");l.then(function(a){k(h),m(h);var c={id:e},d=b.loadFragment("question","tags_form",o,c);return a.setBody(d),d.then(function(){j(h)}).always(function(){n(h)}).fail(f.exception),g?a.getRoot().find(i.actions.save).show():a.getRoot().find(i.actions.save).hide(),a}).fail(f.exception),c.preventDefault()})},p=function(a,b){k(b),m(b);var c=l(a);return h.submitTagCreateUpdateForm(c).always(function(){n(b),j(b)}).fail(f.exception)};return{init:function(b){b=a(b),o(b)}}});
define(["jquery","core/fragment","core/str","core/modal_events","core/modal_factory","core/notification","core/custom_interaction_events","core_question/repository","core_question/selectors"],function(a,b,c,d,e,f,g,h,i){var j=function(a){a.find(i.actions.save).prop("disabled",!1)},k=function(a){a.find(i.actions.save).prop("disabled",!0)},l=function(a){return a.getBody().find("form").serialize()},m=function(a){var b=a.find(i.containers.loadingIcon);b.removeClass("hidden")},n=function(a){var b=a.find(i.containers.loadingIcon);b.addClass("hidden")},o=function(h){var l=e.create({type:e.types.SAVE_CANCEL,large:!1},[h,i.actions.edittags]).then(function(a){return c.get_string("questiontags","question").then(function(b){return a.setTitle(b),b}).fail(f.exception),a.getRoot().on(d.save,function(b){var c=a.getBody().find("form");c.submit(),b.preventDefault()}),a.getRoot().on("submit","form",function(b){p(a,h).then(function(){a.hide()}).fail(f.exception),b.preventDefault(),b.stopPropagation()}),a});h.on(g.events.activate,i.actions.edittags,function(c){var d=a(c.currentTarget),e=d.data("questionid"),g=!!d.data("cantag"),o=d.data("contextid");l.then(function(a){k(h),m(h);var c={id:e},d=b.loadFragment("question","tags_form",o,c);return a.setBody(d),d.then(function(){j(h)}).always(function(){n(h)}).fail(f.exception),g?a.getRoot().find(i.actions.save).show():a.getRoot().find(i.actions.save).hide(),a}).fail(f.exception),c.preventDefault()})},p=function(a,b){k(b),m(b);var c=l(a);return h.submitTagCreateUpdateForm(c).always(function(){n(b),j(b)}).fail(f.exception)};return{init:function(b){b=a(b),o(b)}}});
+2 -2
View File
@@ -149,7 +149,7 @@ define([
var currentTarget = $(e.currentTarget);
var questionId = currentTarget.data('questionid'),
canEdit = !!currentTarget.data('canedit'),
canTag = !!currentTarget.data('cantag'),
contextId = currentTarget.data('contextid');
// This code gets called each time the user clicks the tag link
@@ -180,7 +180,7 @@ define([
// Show or hide the save button depending on whether the user
// has the capability to edit the tags.
if (canEdit) {
if (canTag) {
modal.getRoot().find(QuestionSelectors.actions.save).show();
} else {
modal.getRoot().find(QuestionSelectors.actions.save).hide();
+5 -5
View File
@@ -55,11 +55,11 @@ class tags_action_column extends action_column_base {
if (\core_tag_tag::is_enabled('core_question', 'question') &&
question_has_capability_on($question, 'view')) {
$canedit = question_has_capability_on($question, 'edit');
$cantag = question_has_capability_on($question, 'tag');
$category = $DB->get_record('question_categories', ['id' => $question->category], 'contextid');
$url = $this->qbank->edit_question_url($question->id);
$this->print_tag_icon($question->id, $url, $canedit, $category->contextid);
$this->print_tag_icon($question->id, $url, $cantag, $category->contextid);
}
}
@@ -68,15 +68,15 @@ class tags_action_column extends action_column_base {
*
* @param int $id The question ID.
* @param string $url Editing question url.
* @param bool $canedit Whether the user can edit questions or not.
* @param bool $cantag Whether the user can tag questions or not.
* @param int $contextid Question category context ID.
*/
protected function print_tag_icon($id, $url, $canedit, $contextid) {
protected function print_tag_icon($id, $url, $cantag, $contextid) {
global $OUTPUT;
$params = [
'data-action' => 'edittags',
'data-canedit' => $canedit,
'data-cantag' => $cantag,
'data-contextid' => $contextid,
'data-questionid' => $id
];
+3 -3
View File
@@ -151,15 +151,15 @@ class core_question_external extends external_api {
$question = $DB->get_record('question', array('id' => $questionid));
require_once($CFG->libdir . '/questionlib.php');
$canedit = question_has_capability_on($question, 'edit');
$cantag = question_has_capability_on($question, 'tag');
require_once($CFG->dirroot . '/question/type/tags_form.php');
$mform = new \core_question\form\tags(null, null, 'post', '', null, $canedit, $data);
$mform = new \core_question\form\tags(null, null, 'post', '', null, $cantag, $data);
if ($validateddata = $mform->get_data()) {
// Due to a mform bug, if there's no tags set on the tag element, it submits the name as the value.
// The only way to discover is checking if the tag element is an array.
if ($canedit) {
if ($cantag) {
if (is_array($validateddata->tags)) {
$categorycontext = context::instance_by_id($validateddata->contextid);
+2 -2
View File
@@ -58,8 +58,8 @@ function core_question_output_fragment_tags_form($args) {
$toform->tags = core_tag_tag::get_item_tags_array('core_question', 'question', $question->id);
}
$canedit = question_has_capability_on($question, 'edit');
$mform = new \core_question\form\tags(null, null, 'post', '', null, $canedit, $toform);
$cantag = question_has_capability_on($question, 'tag');
$mform = new \core_question\form\tags(null, null, 'post', '', null, $cantag, $toform);
$mform->set_data($toform);
return $mform->render();
+2 -1
View File
@@ -201,7 +201,8 @@ abstract class question_edit_form extends question_wizard_form {
// Any questiontype specific fields.
$this->definition_inner($mform);
if (core_tag_tag::is_enabled('core_question', 'question')) {
if (core_tag_tag::is_enabled('core_question', 'question')
&& question_has_capability_on($this->question, 'tag')) {
$mform->addElement('header', 'tagsheader', get_string('tags'));
}
$mform->addElement('tags', 'tags', get_string('tags'),