Skip to content

Commit

Permalink
MDL-61444 question: replace all question tag capability checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Feb 19, 2018
1 parent 1451c07 commit e2795e8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion question/amd/build/edit_tags.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions question/amd/src/edit_tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions question/classes/bank/tags_action_column.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ protected function display_content($question, $rowclasses) {
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);
}
}

Expand All @@ -68,15 +68,15 @@ protected function display_content($question, $rowclasses) {
*
* @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
];
Expand Down
6 changes: 3 additions & 3 deletions question/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ public static function submit_tags_form($formdata) {
$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);

Expand Down
4 changes: 2 additions & 2 deletions question/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion question/type/edit_question_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ protected function definition() {
// 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'),
Expand Down

0 comments on commit e2795e8

Please sign in to comment.