mirror of
https://github.com/zulip/zulip.git
synced 2025-11-10 00:46:03 +00:00
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:
@@ -5,6 +5,11 @@ set_global("page_params", {
|
|||||||
{name:"giphy", config: {key: "12345678"}},
|
{name:"giphy", config: {key: "12345678"}},
|
||||||
{name:"foobot", config: {bar: "baz", qux: "quux"}},
|
{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", {});
|
set_global("avatar", {});
|
||||||
@@ -16,14 +21,13 @@ set_global('document', 'document-stub');
|
|||||||
zrequire('bot_data');
|
zrequire('bot_data');
|
||||||
zrequire('settings_bots');
|
zrequire('settings_bots');
|
||||||
zrequire('Handlebars', 'handlebars');
|
zrequire('Handlebars', 'handlebars');
|
||||||
|
zrequire('people');
|
||||||
zrequire('templates');
|
zrequire('templates');
|
||||||
|
|
||||||
|
bot_data.initialize();
|
||||||
|
|
||||||
run_test('generate_zuliprc_uri', () => {
|
run_test('generate_zuliprc_uri', () => {
|
||||||
var bot = {
|
var uri = settings_bots.generate_zuliprc_uri(1);
|
||||||
email: "error-bot@zulip.org",
|
|
||||||
api_key: "QadL788EkiottHmukyhHgePUFHREiu8b",
|
|
||||||
};
|
|
||||||
var uri = settings_bots.generate_zuliprc_uri(bot.email, bot.api_key);
|
|
||||||
var expected = "data:application/octet-stream;charset=utf-8," + encodeURIComponent(
|
var expected = "data:application/octet-stream;charset=utf-8," + encodeURIComponent(
|
||||||
"[api]\nemail=error-bot@zulip.org\n" +
|
"[api]\nemail=error-bot@zulip.org\n" +
|
||||||
"key=QadL788EkiottHmukyhHgePUFHREiu8b\n" +
|
"key=QadL788EkiottHmukyhHgePUFHREiu8b\n" +
|
||||||
|
|||||||
@@ -95,9 +95,9 @@ function render_bots() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.generate_zuliprc_uri = function (email, api_key) {
|
exports.generate_zuliprc_uri = function (bot_id) {
|
||||||
var data = exports.generate_zuliprc_content(email, api_key);
|
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);
|
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 () {
|
$("#active_bots_list").on("click", "a.download_bot_zuliprc", function () {
|
||||||
var bot_info = $(this).closest(".bot-information-box");
|
var bot_info = $(this).closest(".bot-information-box").find(".bot_info");
|
||||||
var email = bot_info.find(".email .value").text();
|
var bot_id = bot_info.attr("data-user-id");
|
||||||
var api_key = bot_info.find(".api_key .api-key-value-and-button .value").text();
|
$(this).attr("href", exports.generate_zuliprc_uri(bot_id));
|
||||||
|
|
||||||
$(this).attr("href", exports.generate_zuliprc_uri(
|
|
||||||
$.trim(email), $.trim(api_key)
|
|
||||||
));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#bots_lists_navbar .add-a-new-bot-tab").click(function (e) {
|
$("#bots_lists_navbar .add-a-new-bot-tab").click(function (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user