mirror of
https://github.com/zulip/zulip.git
synced 2026-06-21 21:32:29 +08:00
settings_bots: Extract logic for ability to create bots.
This is a minor refactor/deduplication and renaming of 'admin_only_bot_creation' to 'can_create_new_bots'
This commit is contained in:
parent
b0bfb6b153
commit
603139500a
@ -195,3 +195,15 @@ run_test('test tab clicks', () => {
|
||||
assert(forms.inactive.visible());
|
||||
}());
|
||||
});
|
||||
|
||||
run_test('can_create_new_bots', () => {
|
||||
page_params.is_admin = true;
|
||||
assert(settings_bots.can_create_new_bots());
|
||||
|
||||
page_params.is_admin = false;
|
||||
page_params.realm_bot_creation_policy = 1;
|
||||
assert(settings_bots.can_create_new_bots());
|
||||
|
||||
page_params.realm_bot_creation_policy = 3;
|
||||
assert(!settings_bots.can_create_new_bots());
|
||||
});
|
||||
|
||||
@ -136,9 +136,7 @@ exports.setup_page = function () {
|
||||
zuliprc: 'zuliprc',
|
||||
botserverrc: 'botserverrc',
|
||||
timezones: moment.tz.names(),
|
||||
admin_only_bot_creation: page_params.is_admin ||
|
||||
page_params.realm_bot_creation_policy !==
|
||||
settings_bots.bot_creation_policy_values.admins_only.code,
|
||||
can_create_new_bots: settings_bots.can_create_new_bots(),
|
||||
settings_label: settings.settings_label,
|
||||
});
|
||||
|
||||
|
||||
@ -72,8 +72,7 @@ function render_bots() {
|
||||
user_owns_an_active_bot = user_owns_an_active_bot || elem.is_active;
|
||||
});
|
||||
|
||||
if (page_params.is_admin || page_params.realm_bot_creation_policy !==
|
||||
exports.bot_creation_policy_values.admins_only.code) {
|
||||
if (settings_bots.can_create_new_bots()) {
|
||||
if (!user_owns_an_active_bot) {
|
||||
focus_tab.add_a_new_bot_tab();
|
||||
return;
|
||||
@ -146,6 +145,15 @@ exports.bot_creation_policy_values = {
|
||||
},
|
||||
};
|
||||
|
||||
exports.can_create_new_bots = function () {
|
||||
if (page_params.is_admin) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return page_params.realm_bot_creation_policy !==
|
||||
exports.bot_creation_policy_values.admins_only.code;
|
||||
};
|
||||
|
||||
exports.update_bot_settings_tip = function () {
|
||||
var permission_type = exports.bot_creation_policy_values;
|
||||
var current_permission = page_params.realm_bot_creation_policy;
|
||||
@ -164,9 +172,7 @@ exports.update_bot_permissions_ui = function () {
|
||||
exports.update_bot_settings_tip();
|
||||
$('#bot_table_error').hide();
|
||||
$("#id_realm_bot_creation_policy").val(page_params.realm_bot_creation_policy);
|
||||
if (page_params.realm_bot_creation_policy ===
|
||||
exports.bot_creation_policy_values.admins_only.code &&
|
||||
!page_params.is_admin) {
|
||||
if (!exports.can_create_new_bots()) {
|
||||
$('#create_bot_form').hide();
|
||||
$('.add-a-new-bot-tab').hide();
|
||||
focus_tab.active_bots_tab();
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
<ul class="nav nav-tabs nav-justified" id="bots_lists_navbar">
|
||||
<li class="active active-bots-tab"><a>{{t "Active bots" }}</a></li>
|
||||
<li class="inactive-bots-tab"><a>{{t "Inactive bots" }}</a></li>
|
||||
<li class="add-a-new-bot-tab {{#unless admin_only_bot_creation}}hide{{/unless}}"><a>{{t "Add a new bot" }}</a></li>
|
||||
<li class="add-a-new-bot-tab {{#unless can_create_new_bots}}hide{{/unless}}"><a>{{t "Add a new bot" }}</a></li>
|
||||
</ul>
|
||||
|
||||
<ol class="bots_list required-text" id="active_bots_list" data-empty="{{t 'You have no active bots.' }}">
|
||||
@ -28,7 +28,7 @@
|
||||
|
||||
<div id="add-a-new-bot-form">
|
||||
<form id="create_bot_form"
|
||||
class="form-horizontal no-padding {{#unless admin_only_bot_creation}}hide{{/unless}}">
|
||||
class="form-horizontal no-padding {{#unless can_create_new_bots}}hide{{/unless}}">
|
||||
<div class="new-bot-form">
|
||||
<div class="input-group">
|
||||
<label for="bot_type">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user