Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Commit

Permalink
[bug 1061581] As a Helper, I can sign into a SUMO account so that I g…
Browse files Browse the repository at this point in the history
…et authenticated as a BuddyUp helper.
  • Loading branch information
rik committed Feb 10, 2015
1 parent 4525254 commit 26e13ef
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 100 deletions.
2 changes: 1 addition & 1 deletion app/css/utils.css
Expand Up @@ -13,7 +13,7 @@
border: 0;
}
.hide {
display: none;
display: none !important;
}
.spinner:before {
display: inline-block;
Expand Down
1 change: 0 additions & 1 deletion app/home.html
Expand Up @@ -25,7 +25,6 @@
<section role="region" class="vbox fit">
<header>
<h1>Support</h1>
<a href="authentication.html">Login</a>
<a href="profile.html" id="settings" class="settings-icon" data-icon="settings">
<span class="visuallyhidden">Settings</span>
</a>
Expand Down
19 changes: 12 additions & 7 deletions app/js/profile_controller.js
Expand Up @@ -38,6 +38,9 @@
for (var i = 0, l = profile_elements.length; i < l; i++) {
var elem_name = profile_elements[i];
var elem = form.elements[profile_elements[i]];
if (!elem) {
break;
}

switch(elem_name) {
case 'handset_type':
Expand Down Expand Up @@ -83,14 +86,16 @@
var ProfileController = {
init: function() {

User.get_user().then(function(user) {
var promises = [];
promises.push(User.is_helper());
promises.push(User.get_user());
Promise.all(promises).then(function([is_helper, user]) {
var html = nunjucks.render('my-profile.html', {
results: {
user: user,
locales: LOCALES,
handsets: HANDSETS,
operators: OPERATORS
}
user: user,
locales: LOCALES,
handsets: HANDSETS,
operators: OPERATORS,
is_helper: is_helper
});

document.querySelector('#my-profile').innerHTML = html;
Expand Down
26 changes: 23 additions & 3 deletions app/js/question_controller.js
Expand Up @@ -4,6 +4,7 @@

(function(exports) {
var question_thread;
var question_form;
var suggestions;
var thread_introduction;
var question_id;
Expand Down Expand Up @@ -66,7 +67,7 @@
}

function close_question() {
document.getElementById('question_form').classList.add('hide');
question_form.parentElement.classList.add('hide');
}

/**
Expand Down Expand Up @@ -233,6 +234,8 @@
close_question();
}

display_sign_in_if_needed(question);

question.content = question.title;
answers.push(question);
answers.reverse();
Expand Down Expand Up @@ -318,15 +321,32 @@
});
}

// Needed when the user is not a helper nor the question creator
function display_sign_in_if_needed(question) {
User.get_user().then(function(user) {
if (user.username == question.creator.username) {
return;
}
User.is_helper().then(function(is_helper) {
if (is_helper) {
return;
}
// FIXME Careful with the presence of those elements
document.getElementById('sign-in-link').classList.remove('hide');
question_form.classList.add('hide');
});
});
}

var QuestionController = {
init: function() {
question_field = document.getElementById('question_field');
question_field.addEventListener('input', take_question);
question_field.addEventListener('input',
_.throttle(give_suggestions, 500, {leading: false}));

var form = document.getElementById('question_form');
form.addEventListener('submit', submit_comment);
question_form = document.getElementById('question_form');
question_form.addEventListener('submit', submit_comment);

question_thread = document.getElementById('question-thread');
question_thread.addEventListener('click', handle_event);
Expand Down
19 changes: 18 additions & 1 deletion app/js/questions_controller.js
Expand Up @@ -151,6 +151,23 @@
Utils.toggle_spinner();
}

function display_sign_in_if_needed() {
User.is_helper().then(function(is_helper) {
if (is_helper) {
return;
}

var sign_in = document.getElementById('sign-in-link');
if (sign_in) {
sign_in.classList.remove('hide');
}
var new_active_tabs = document.getElementById('new-active-tabs');
if (new_active_tabs) {
new_active_tabs.classList.add('hide');
}
});
}

var QuestionsController = {
init: function() {
load_more_my_questions_button = document.getElementById(
Expand All @@ -170,7 +187,7 @@
nunjucks.configure({ autoescape: true });

add_tab_widget_handler();

display_sign_in_if_needed();
Utils.toggle_spinner();

my_questions_list_container = document.getElementById('myquestions');
Expand Down
2 changes: 1 addition & 1 deletion app/js/sumo_db.js
Expand Up @@ -191,7 +191,7 @@

register_user: function(username, password, email) {
var endpoint = API_V2_BASE + 'user/';
endpoint += '?format=json' // TODO bug 1088014
endpoint += '?format=json'; // TODO bug 1088014
var data = {
username: username,
password: password,
Expand Down
81 changes: 50 additions & 31 deletions app/js/templates.js
Expand Up @@ -81,24 +81,36 @@ var colno = null;
var output = "";
try {
output += "<form name=\"profile\" id=\"profile\" class=\"profile\" method=\"get\">\n <fieldset class=\"user\">\n <p>\n <label for=\"display_name\" class=\"visuallyhidden\">Your Display Name</label>\n <input type=\"text\" name=\"display_name\" id=\"display_name\" value=\"";
output += runtime.suppressValue(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "results")),"user", env.autoesc)),"display_name", env.autoesc), env.autoesc);
output += "\" required />\n <button type=\"reset\">Clear</button>\n </p>\n <ul class=\"achievements\">\n <li>\n <span class=\"count\" data-icon=\"tick\">";
output += runtime.suppressValue(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "results")),"user", env.autoesc)),"solution_count", env.autoesc), env.autoesc);
output += "</span> Questions Answered\n </li>\n <li>\n <span class=\"count\" data-icon=\"feedback\">";
output += runtime.suppressValue(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "results")),"user", env.autoesc)),"helpfulness", env.autoesc), env.autoesc);
output += "</span> Helpful Upvotes\n </li>\n </ul>\n </fieldset>\n\n <fieldset class=\"notifications\">\n <h2>Notifications</h2>\n <ul>\n <li>\n <label for=\"new_comment_notify\" class=\"pack-switch\">\n <input type=\"checkbox\" id=\"new_comment_notify\" name=\"new_comment_notify\"\n ";
if(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "results")),"user", env.autoesc)),"new_comment_notify", env.autoesc)) {
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "user")),"display_name", env.autoesc), env.autoesc);
output += "\" required />\n <button type=\"reset\">Clear</button>\n </p>\n ";
if(runtime.contextOrFrameLookup(context, frame, "is_helper")) {
output += "\n <ul class=\"achievements\">\n <li>\n <span class=\"count\" data-icon=\"tick\">";
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "user")),"solution_count", env.autoesc), env.autoesc);
output += "</span> Questions Answered\n </li>\n <li>\n <span class=\"count\" data-icon=\"feedback\">";
output += runtime.suppressValue(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "user")),"helpfulness", env.autoesc), env.autoesc);
output += "</span> Helpful Upvotes\n </li>\n </ul>\n ";
;
}
output += "\n </fieldset>\n\n <fieldset class=\"notifications\">\n <h2>Notifications</h2>\n <ul>\n <li>\n <label for=\"new_comment_notify\" class=\"pack-switch\">\n <input type=\"checkbox\" id=\"new_comment_notify\" name=\"new_comment_notify\"\n ";
if(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "user")),"new_comment_notify", env.autoesc)) {
output += "checked=\"checked\"";
;
}
output += " />\n <span>New Comments</span>\n </label>\n </li>\n <li>\n <label for=\"buddyup_reminder\" class=\"pack-switch\">\n <input type=\"checkbox\" id=\"buddyup_reminder\" name=\"buddyup_reminder\"\n ";
if(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "results")),"user", env.autoesc)),"buddyup_reminder", env.autoesc)) {
output += " />\n <span>New Comments</span>\n </label>\n </li>\n ";
if(runtime.contextOrFrameLookup(context, frame, "is_helper")) {
output += "\n <li>\n <label for=\"buddyup_reminder\" class=\"pack-switch\">\n <input type=\"checkbox\" id=\"buddyup_reminder\" name=\"buddyup_reminder\"\n ";
if(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "user")),"buddyup_reminder", env.autoesc)) {
output += "checked=\"checked\"";
;
}
output += " />\n <span>BuddyUp Reminder</span>\n </label>\n </li>\n </ul>\n </fieldset>\n\n <fieldset class=\"question-filters\">\n <h2>Answer A Question Filter</h2>\n <section>\n <p>The unanswered questions list will be filtered based on the setting below.</p>\n\n <label for=\"locale\">Language</label>\n <span class=\"button icon icon-dialog\">\n <select id=\"locale\">\n ";
output += " />\n <span>BuddyUp Reminder</span>\n </label>\n </li>\n ";
;
}
output += "\n\n </ul>\n </fieldset>\n\n ";
if(runtime.contextOrFrameLookup(context, frame, "is_helper")) {
output += "\n\n <fieldset class=\"question-filters\">\n <h2>Answer A Question Filter</h2>\n <section>\n <p>The unanswered questions list will be filtered based on the setting below.</p>\n\n <label for=\"locale\">Language</label>\n <span class=\"button icon icon-dialog\">\n <select id=\"locale\">\n ";
frame = frame.push();
var t_3 = runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "results")),"locales", env.autoesc);
var t_3 = runtime.contextOrFrameLookup(context, frame, "locales");
if(t_3) {var t_2 = t_3.length;
for(var t_1=0; t_1 < t_3.length; t_1++) {
var t_4 = t_3[t_1];
Expand All @@ -110,26 +122,26 @@ frame.set("loop.revindex0", t_2 - t_1 - 1);
frame.set("loop.first", t_1 === 0);
frame.set("loop.last", t_1 === t_2 - 1);
frame.set("loop.length", t_2);
output += "\n <option ";
if(t_4 == runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "results")),"user", env.autoesc)),"locale", env.autoesc)) {
output += "\n <option ";
if(t_4 == runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "user")),"locale", env.autoesc)) {
output += "selected=\"selected\"";
;
}
output += ">";
output += runtime.suppressValue(t_4, env.autoesc);
output += "</option>\n ";
output += "</option>\n ";
;
}
}
frame = frame.pop();
output += "\n </select>\n </span>\n\n <label for=\"handset_type\">Handset Type</label>\n <select id=\"handset_type\" multiple=\"true\">\n ";
if(runtime.memberLookup((runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "results")),"user", env.autoesc)),"handset_type", env.autoesc)),0, env.autoesc) == "All") {
output += "\n <option selected=\"selected\">All</option>\n ";
output += "\n </select>\n </span>\n\n <label for=\"handset_type\">Handset Type</label>\n <select id=\"handset_type\" multiple=\"true\">\n ";
if(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "user")),"handset_type", env.autoesc)),0, env.autoesc) == "All") {
output += "\n <option selected=\"selected\">All</option>\n ";
;
}
output += "\n ";
output += "\n ";
frame = frame.push();
var t_7 = runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "results")),"handsets", env.autoesc);
var t_7 = runtime.contextOrFrameLookup(context, frame, "handsets");
if(t_7) {var t_6 = t_7.length;
for(var t_5=0; t_5 < t_7.length; t_5++) {
var t_8 = t_7[t_5];
Expand All @@ -141,26 +153,26 @@ frame.set("loop.revindex0", t_6 - t_5 - 1);
frame.set("loop.first", t_5 === 0);
frame.set("loop.last", t_5 === t_6 - 1);
frame.set("loop.length", t_6);
output += "\n <option ";
if((runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "results")),"user", env.autoesc)),"handset_type", env.autoesc).indexOf(t_8) !== -1)) {
output += "\n <option ";
if((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "user")),"handset_type", env.autoesc).indexOf(t_8) !== -1)) {
output += "selected=\"selected\"";
;
}
output += ">";
output += runtime.suppressValue(t_8, env.autoesc);
output += "</option>\n ";
output += "</option>\n ";
;
}
}
frame = frame.pop();
output += "\n </select>\n\n <label for=\"operator\">Operator</label>\n <select id=\"operator\">\n ";
if(runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "results")),"user", env.autoesc)),"operator", env.autoesc) == "All") {
output += "\n <option selected=\"selected\">All</option>\n ";
output += "\n </select>\n\n <label for=\"operator\">Operator</label>\n <select id=\"operator\">\n ";
if(runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "user")),"operator", env.autoesc) == "All") {
output += "\n <option selected=\"selected\">All</option>\n ";
;
}
output += "\n ";
output += "\n ";
frame = frame.push();
var t_11 = runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "results")),"operators", env.autoesc);
var t_11 = runtime.contextOrFrameLookup(context, frame, "operators");
if(t_11) {var t_10 = t_11.length;
for(var t_9=0; t_9 < t_11.length; t_9++) {
var t_12 = t_11[t_9];
Expand All @@ -172,19 +184,26 @@ frame.set("loop.revindex0", t_10 - t_9 - 1);
frame.set("loop.first", t_9 === 0);
frame.set("loop.last", t_9 === t_10 - 1);
frame.set("loop.length", t_10);
output += "\n <option ";
if(t_12 == runtime.memberLookup((runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "results")),"user", env.autoesc)),"operator", env.autoesc)) {
output += "\n <option ";
if(t_12 == runtime.memberLookup((runtime.contextOrFrameLookup(context, frame, "user")),"operator", env.autoesc)) {
output += "selected=\"selected\"";
;
}
output += ">";
output += runtime.suppressValue(t_12, env.autoesc);
output += "</option>\n ";
output += "</option>\n ";
;
}
}
frame = frame.pop();
output += "\n </select>\n </section>\n </fieldset>\n</form>\n";
output += "\n </select>\n </section>\n </fieldset>\n ";
;
}
else {
output += "\n <section>\n <h2>Answer questions</h2>\n <p>Sign in to answer support questions from the Mozilla community.</p>\n <a href=\"authentication.html\" class=\"button-blue\">Create account or sign in</a>\n </section>\n ";
;
}
output += "\n\n</form>\n";
cb(null, output);
;
} catch (e) {
Expand Down
29 changes: 22 additions & 7 deletions app/js/user.js
Expand Up @@ -40,8 +40,9 @@
return user;
}

function set_user(username, password, token) {
return set_credentials(username, password, token).then(function() {
function set_user(username, password, token, is_helper) {
return set_credentials(username, password, token, is_helper)
.then(function() {
return SumoDB.get_user(username).then(sync_user);
});
}
Expand All @@ -53,8 +54,9 @@
return SumoDB.create_user().then(function(response) {
var promises = [];

var is_helper = false;
promises.push(set_credentials(response.user.username, response.password,
response.token));
response.token, is_helper));

var normalized_user = normalize_user(response.user);
normalized_user.last_sync = Date.now();
Expand All @@ -66,11 +68,16 @@
});
}

function set_credentials(username, password, token) {
function set_credentials(username, password, token, is_helper) {
if (typeof is_helper == 'undefined') {
console.error('foo');
return;
}
return asyncStorage.setItem(USER_CREDENTIALS_KEY, {
username: username,
password: password,
token: token
token: token,
is_helper: is_helper
});
}

Expand Down Expand Up @@ -124,6 +131,12 @@
});
},

is_helper: function() {
return User.get_credentials().then(function(credentials) {
return credentials.is_helper;
});
},

/**
* Updates the local user data as well as last sync time.
* @param {object} user_data - The ammended user data and settings i.e.
Expand All @@ -139,7 +152,8 @@

authenticate_user: function(username, password) {
return SumoDB.get_token(username, password).then(function(token) {
return set_user(username, password, token);
var is_helper = true;
return set_user(username, password, token, is_helper);
});
},

Expand All @@ -149,7 +163,8 @@
return promise.then(function() {
return User.authenticate_user(username, password);
}).then(function(token) {
return User.set_user(username, password, token);
var is_helper = true;
return User.set_user(username, password, token, is_helper);
});
}
};
Expand Down
1 change: 1 addition & 0 deletions app/question.html
Expand Up @@ -52,6 +52,7 @@ <h1>My Question</h1>
<input type="text" id="question_field" class="fit" placeholder="Type your question" />
<button type="submit" data-icon-after="send"></button>
</form>
<a id="sign-in-link" href="authentication.html" class="button-blue hide">Sign in to reply</a>
</footer>
</section>

Expand Down
6 changes: 5 additions & 1 deletion app/question_list_helper.html
Expand Up @@ -34,7 +34,11 @@ <h1 id="main_heading">My Questions</h1>
</header>
<main class="fit scroll">
<section class="tabbed-section" role="region">
<ul role="tablist" class="bb-tablist" data-type="filter">
<div id="sign-in-link" class="hide">
<p>Sign in to answer support questions from the Mozilla community.</p>
<a href="authentication.html" class="button-blue">Create account or sign in</a>
</div>
<ul id="new-active-tabs" role="tablist" class="bb-tablist" data-type="filter">
<li id="new" role="presentation">
<a id="tab1" href="#panel_new" role="tab" aria-controls="panel_new" aria-selected="true">New</a>
</li>
Expand Down

0 comments on commit 26e13ef

Please sign in to comment.