frontend: Use bot_data instead of HTML data to generate zuliprc.

It is better to retrieve all information about a bot from
the central bot data store, rather than relying on the
bot card's HTML attributes.
This commit is contained in:
Robert Hönig
2018-06-01 11:27:02 +02:00
committed by Tim Abbott
parent 7e7583e9cd
commit d08c701bb4
2 changed files with 15 additions and 15 deletions

View File

@@ -5,6 +5,11 @@ set_global("page_params", {
{name:"giphy", config: {key: "12345678"}},
{name:"foobot", config: {bar: "baz", qux: "quux"}},
],
realm_bots: [{api_key: 'QadL788EkiottHmukyhHgePUFHREiu8b',
email: 'error-bot@zulip.org',
full_name: 'Error bot',
user_id: 1},
],
});
set_global("avatar", {});
@@ -16,14 +21,13 @@ set_global('document', 'document-stub');
zrequire('bot_data');
zrequire('settings_bots');
zrequire('Handlebars', 'handlebars');
zrequire('people');
zrequire('templates');
bot_data.initialize();
run_test('generate_zuliprc_uri', () => {
var bot = {
email: "error-bot@zulip.org",
api_key: "QadL788EkiottHmukyhHgePUFHREiu8b",
};
var uri = settings_bots.generate_zuliprc_uri(bot.email, bot.api_key);
var uri = settings_bots.generate_zuliprc_uri(1);
var expected = "data:application/octet-stream;charset=utf-8," + encodeURIComponent(
"[api]\nemail=error-bot@zulip.org\n" +
"key=QadL788EkiottHmukyhHgePUFHREiu8b\n" +

View File

@@ -95,9 +95,9 @@ function render_bots() {
}
}
exports.generate_zuliprc_uri = function (email, api_key) {
var data = exports.generate_zuliprc_content(email, api_key);
exports.generate_zuliprc_uri = function (bot_id) {
var bot = bot_data.get(bot_id);
var data = exports.generate_zuliprc_content(bot.email, bot.api_key);
return exports.encode_zuliprc_as_uri(data);
};
@@ -448,13 +448,9 @@ exports.set_up = function () {
});
$("#active_bots_list").on("click", "a.download_bot_zuliprc", function () {
var bot_info = $(this).closest(".bot-information-box");
var email = bot_info.find(".email .value").text();
var api_key = bot_info.find(".api_key .api-key-value-and-button .value").text();
$(this).attr("href", exports.generate_zuliprc_uri(
$.trim(email), $.trim(api_key)
));
var bot_info = $(this).closest(".bot-information-box").find(".bot_info");
var bot_id = bot_info.attr("data-user-id");
$(this).attr("href", exports.generate_zuliprc_uri(bot_id));
});
$("#bots_lists_navbar .add-a-new-bot-tab").click(function (e) {