mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 13:03:29 +00:00
settings: Send bot types from the backend instead of hardcoding them.
This commit is contained in:
committed by
Tim Abbott
parent
2310794451
commit
3be8e95d13
@@ -17,17 +17,11 @@ function is_local_part(value, element) {
|
||||
return this.optional(element) || /^[\-!#$%&'*+\/=?\^_`{}|~0-9A-Z]+(\.[\-!#$%&'*+\/=?\^_`{}|~0-9A-Z]+)*$/i.test(value);
|
||||
}
|
||||
|
||||
// Note: These strings are mostly duplicates with a similar data set
|
||||
// in the bot-settings.handlebars. We'll probably want to move this
|
||||
// map to be sent from the backend and shared.
|
||||
exports.type_id_to_string = function (type_id) {
|
||||
if (type_id === 1) {
|
||||
return i18n.t("Generic bot");
|
||||
} else if (type_id === 2) {
|
||||
return i18n.t("Incoming webhook");
|
||||
} else if (type_id === 3) {
|
||||
return i18n.t("Outgoing webhook");
|
||||
}
|
||||
var name = _.find(page_params.bot_types, function (bot_type) {
|
||||
return bot_type.type_id === type_id;
|
||||
}).name;
|
||||
return i18n.t(name);
|
||||
};
|
||||
|
||||
function render_bots() {
|
||||
|
||||
@@ -35,9 +35,11 @@
|
||||
title='{{t "Incoming webhooks can only send messages." }}'></i>
|
||||
</label>
|
||||
<select name="bot_type" id="create_bot_type">
|
||||
<option value="1">{{t "Generic bot" }}</option>
|
||||
<option value="2">{{t "Incoming webhook" }}</option>
|
||||
<option value="3">{{t "Outgoing webhook" }}</option>
|
||||
{{#each page_params.bot_types}}
|
||||
{{#if this.allowed}}
|
||||
<option value="{{this.type_id}}">{{this.name}}</option>
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="input-group">
|
||||
|
||||
@@ -489,6 +489,13 @@ class UserProfile(AbstractBaseUser, PermissionsMixin):
|
||||
"""
|
||||
EMBEDDED_BOT = 4
|
||||
|
||||
BOT_TYPES = {
|
||||
DEFAULT_BOT: 'Generic bot',
|
||||
INCOMING_WEBHOOK_BOT: 'Incoming webhook',
|
||||
OUTGOING_WEBHOOK_BOT: 'Outgoing webhook',
|
||||
EMBEDDED_BOT: 'Embedded bot',
|
||||
}
|
||||
|
||||
# For now, don't allow creating other bot types via the UI
|
||||
ALLOWED_BOT_TYPES = [
|
||||
DEFAULT_BOT,
|
||||
|
||||
@@ -48,6 +48,7 @@ class HomeTest(ZulipTestCase):
|
||||
"avatar_source",
|
||||
"avatar_url",
|
||||
"avatar_url_medium",
|
||||
"bot_types",
|
||||
"can_create_streams",
|
||||
"cross_realm_bots",
|
||||
"custom_profile_fields",
|
||||
|
||||
@@ -64,6 +64,17 @@ def sent_time_in_epoch_seconds(user_message: Optional[UserMessage]) -> Optional[
|
||||
# Return the epoch seconds in UTC.
|
||||
return calendar.timegm(user_message.message.pub_date.utctimetuple())
|
||||
|
||||
def get_bot_types():
|
||||
# type: () -> List[Dict[Text, object]]
|
||||
bot_types = []
|
||||
for type_id, name in UserProfile.BOT_TYPES.items():
|
||||
bot_types.append({
|
||||
'type_id': type_id,
|
||||
'name': name,
|
||||
'allowed': type_id in UserProfile.ALLOWED_BOT_TYPES
|
||||
})
|
||||
return bot_types
|
||||
|
||||
def home(request: HttpRequest) -> HttpResponse:
|
||||
if settings.DEVELOPMENT and os.path.exists('var/handlebars-templates/compile.error'):
|
||||
response = render(request, 'zerver/handlebars_compilation_failed.html')
|
||||
@@ -189,6 +200,7 @@ def home_real(request: HttpRequest) -> HttpResponse:
|
||||
prompt_for_invites = prompt_for_invites,
|
||||
furthest_read_time = sent_time_in_epoch_seconds(latest_read),
|
||||
has_mobile_devices = num_push_devices_for_user(user_profile) > 0,
|
||||
bot_types = get_bot_types(),
|
||||
)
|
||||
|
||||
undesired_register_ret_fields = [
|
||||
|
||||
Reference in New Issue
Block a user