Bug 1154257 - Helpees should not see "Choose a category" when viewing questions

This commit is contained in:
Anthony Ricaud 2015-04-20 18:55:41 +02:00
Родитель fdc2fe1425
Коммит 5edba372d7
5 изменённых файлов: 54 добавлений и 40 удалений

Просмотреть файл

@ -140,27 +140,31 @@
*/ */
function add_thread_header(question) { function add_thread_header(question) {
var date_posted = Utils.time_since(new Date(question.updated)); var date_posted = Utils.time_since(new Date(question.updated));
var author = question.creator.display_name || question.creator.username;
var displayable_metadata = var displayable_metadata =
Utils.convert_metadata_for_display(question.metadata); Utils.convert_metadata_for_display(question.metadata);
var html = nunjucks.render('thread_header.html', { User.is_helper().then(function(is_helper) {
date_posted: date_posted, var html = nunjucks.render('thread_header.html', {
displayable_metadata: displayable_metadata, date_posted: date_posted,
author: author, displayable_metadata: displayable_metadata,
categories: CATEGORIES, viewer_is_helper: is_helper,
selected_category: question.category categories: CATEGORIES,
}); selected_category: question.category
question_thread.insertAdjacentHTML('afterbegin', html); });
question_thread.insertAdjacentHTML('afterbegin', html);
var category_chooser = document.getElementById('category_chooser'); var category_chooser = document.getElementById('category_chooser');
category_chooser.addEventListener('change', function(evt) { if (!category_chooser) {
var category = evt.target.value;
if (category == question.category) {
return; return;
} }
SumoDB.set_category_for_question(category, question.id); category_chooser.addEventListener('change', function(evt) {
var category = evt.target.value;
if (category == question.category) {
return;
}
SumoDB.set_category_for_question(category, question.id);
});
}); });
} }

Просмотреть файл

@ -497,7 +497,9 @@ output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLook
output += "</span>\n</div>\n<h3 class=\"QuestionThread-date text-blue\">\n "; output += "</span>\n</div>\n<h3 class=\"QuestionThread-date text-blue\">\n ";
output += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "date_posted"), env.autoesc); output += runtime.suppressValue(runtime.contextOrFrameLookup(context, frame, "date_posted"), env.autoesc);
output += "\n</h3>\n\n"; output += "\n</h3>\n\n";
output += "\n<ul>\n <li>\n <div class=\"button\" data-icon=\"forward\">\n <select id=\"category_chooser\">\n "; if(runtime.contextOrFrameLookup(context, frame, "viewer_is_helper")) {
output += "\n ";
output += "\n <ul>\n <li>\n <div class=\"button\" data-icon=\"forward\">\n <select id=\"category_chooser\">\n ";
frame = frame.push(); frame = frame.push();
var t_3 = runtime.contextOrFrameLookup(context, frame, "categories"); var t_3 = runtime.contextOrFrameLookup(context, frame, "categories");
if(t_3) {var t_1; if(t_3) {var t_1;
@ -515,16 +517,16 @@ frame.set("loop.revindex0", t_2 - t_1 - 1);
frame.set("loop.first", t_1 === 0); frame.set("loop.first", t_1 === 0);
frame.set("loop.last", t_1 === t_2 - 1); frame.set("loop.last", t_1 === t_2 - 1);
frame.set("loop.length", t_2); frame.set("loop.length", t_2);
output += "\n <option value=\""; output += "\n <option value=\"";
output += runtime.suppressValue(t_4, env.autoesc); output += runtime.suppressValue(t_4, env.autoesc);
output += "\"\n "; output += "\"\n ";
if(runtime.contextOrFrameLookup(context, frame, "selected_category") == t_4) { if(runtime.contextOrFrameLookup(context, frame, "selected_category") == t_4) {
output += "selected"; output += "selected";
; ;
} }
output += ">\n "; output += ">\n ";
output += runtime.suppressValue(t_5, env.autoesc); output += runtime.suppressValue(t_5, env.autoesc);
output += "\n </option>\n "; output += "\n </option>\n ";
; ;
} }
} else { } else {
@ -542,22 +544,25 @@ frame.set("loop.revindex0", t_2 - t_1 - 1);
frame.set("loop.first", t_1 === 0); frame.set("loop.first", t_1 === 0);
frame.set("loop.last", t_1 === t_2 - 1); frame.set("loop.last", t_1 === t_2 - 1);
frame.set("loop.length", t_2); frame.set("loop.length", t_2);
output += "\n <option value=\""; output += "\n <option value=\"";
output += runtime.suppressValue(t_6, env.autoesc); output += runtime.suppressValue(t_6, env.autoesc);
output += "\"\n "; output += "\"\n ";
if(runtime.contextOrFrameLookup(context, frame, "selected_category") == t_6) { if(runtime.contextOrFrameLookup(context, frame, "selected_category") == t_6) {
output += "selected"; output += "selected";
; ;
} }
output += ">\n "; output += ">\n ";
output += runtime.suppressValue(t_7, env.autoesc); output += runtime.suppressValue(t_7, env.autoesc);
output += "\n </option>\n "; output += "\n </option>\n ";
; ;
} }
} }
} }
frame = frame.pop(); frame = frame.pop();
output += "\n </select>\n </div>\n </li>\n</ul>\n"; output += "\n </select>\n </div>\n </li>\n </ul>\n";
;
}
output += "\n";
cb(null, output); cb(null, output);
; ;
} catch (e) { } catch (e) {

Просмотреть файл

@ -4,6 +4,7 @@
var MockUser = { var MockUser = {
get_user: function() {}, get_user: function() {},
is_helper: function() {},
get_credentials: function() {}, get_credentials: function() {},
reauthenticate_user: function() {} reauthenticate_user: function() {}
}; };

Просмотреть файл

@ -86,6 +86,8 @@ suite('QuestionController', function() {
window.parent.Notif = MockNotif; window.parent.Notif = MockNotif;
this.sinon.stub(User, 'get_user').returns(Promise.resolve(FAKE_USER)); this.sinon.stub(User, 'get_user').returns(Promise.resolve(FAKE_USER));
this.sinon.stub(User, 'is_helper').returns(Promise.resolve(true));
this.sinon.stub(Utils, 'get_url_parameters') this.sinon.stub(Utils, 'get_url_parameters')
.returns({id: DISPLAYED_QUESTION_ID}); .returns({id: DISPLAYED_QUESTION_ID});
this.sinon.stub(Utils, 'time_since'); this.sinon.stub(Utils, 'time_since');
@ -125,6 +127,6 @@ suite('QuestionController', function() {
}); });
test('only display new answers since last time', function() { test('only display new answers since last time', function() {
sinon.assert.calledOnce(nunjucks.render); sinon.assert.calledOnce(nunjucks.render.withArgs('thread.html'));
}); });
}); });

Просмотреть файл

@ -11,18 +11,20 @@
{{ date_posted }} {{ date_posted }}
</h3> </h3>
{# This <ul><li> is needed to get the right Building block styling for that button #} {% if viewer_is_helper %}
<ul> {# This <ul><li> is needed to get the right Building block styling for that button #}
<li> <ul>
<div class="button" data-icon="forward"> <li>
<select id="category_chooser"> <div class="button" data-icon="forward">
{% for key, value in categories %} <select id="category_chooser">
<option value="{{ key }}" {% for key, value in categories %}
{% if selected_category == key %}selected{% endif %}> <option value="{{ key }}"
{{ value }} {% if selected_category == key %}selected{% endif %}>
</option> {{ value }}
{% endfor %} </option>
</select> {% endfor %}
</div> </select>
</li> </div>
</ul> </li>
</ul>
{% endif %}