org_settings: Add "Role" column in bot-list table.

This commit adds a new "Role" column for the bot-list table in the
org-settings, and removes the user_id column from the same.
The role of a bot is fetched using the `get_user_type` function inside
bot_info().
This also adds the `sort_role` in the sort_fields which sorts the role
column in the bot-list table.
This commit is contained in:
somesh202
2022-03-31 12:01:45 +05:30
committed by Tim Abbott
parent 94457732c1
commit b1cafb1280
5 changed files with 8 additions and 8 deletions

View File

@@ -127,6 +127,7 @@ const bot_botson = {
full_name: "Bot Botson", full_name: "Bot Botson",
is_bot: true, is_bot: true,
bot_owner_id: isaac.user_id, bot_owner_id: isaac.user_id,
role: 300,
}; };
const moderator = { const moderator = {
@@ -525,7 +526,7 @@ test_people("user_type", () => {
assert.equal(people.get_user_type(guest.user_id), $t({defaultMessage: "Guest"})); assert.equal(people.get_user_type(guest.user_id), $t({defaultMessage: "Guest"}));
assert.equal(people.get_user_type(realm_owner.user_id), $t({defaultMessage: "Owner"})); assert.equal(people.get_user_type(realm_owner.user_id), $t({defaultMessage: "Owner"}));
assert.equal(people.get_user_type(moderator.user_id), $t({defaultMessage: "Moderator"})); assert.equal(people.get_user_type(moderator.user_id), $t({defaultMessage: "Moderator"}));
assert.equal(people.get_user_type(bot_botson.user_id), $t({defaultMessage: "Bot"})); assert.equal(people.get_user_type(bot_botson.user_id), $t({defaultMessage: "Moderator"}));
}); });
test_people("updates", () => { test_people("updates", () => {

View File

@@ -274,9 +274,6 @@ export function get_user_time(user_id) {
export function get_user_type(user_id) { export function get_user_type(user_id) {
const user_profile = get_by_user_id(user_id); const user_profile = get_by_user_id(user_id);
if (user_profile.is_bot) {
return $t({defaultMessage: "Bot"});
}
return settings_config.user_role_map.get(user_profile.role); return settings_config.user_role_map.get(user_profile.role);
} }

View File

@@ -190,10 +190,12 @@ function bot_info(bot_user_id) {
const info = {}; const info = {};
info.is_bot = true; info.is_bot = true;
info.role = people.get_by_user_id(bot_user_id).role;
info.is_active = bot_user.is_active; info.is_active = bot_user.is_active;
info.user_id = bot_user.user_id; info.user_id = bot_user.user_id;
info.full_name = bot_user.full_name; info.full_name = bot_user.full_name;
info.bot_owner_id = owner_id; info.bot_owner_id = owner_id;
info.user_role_text = people.get_user_type(bot_user_id);
// Convert bot type id to string for viewing to the users. // Convert bot type id to string for viewing to the users.
info.bot_type = settings_bots.type_id_to_string(bot_user.bot_type); info.bot_type = settings_bots.type_id_to_string(bot_user.bot_type);
@@ -279,7 +281,7 @@ section.bots.create_table = () => {
sort_fields: { sort_fields: {
email: sort_bot_email, email: sort_bot_email,
bot_owner: sort_bot_owner, bot_owner: sort_bot_owner,
id: sort_user_id, role: sort_role,
}, },
$simplebar_container: $("#admin-bot-list .progressive-table-wrapper"), $simplebar_container: $("#admin-bot-list .progressive-table-wrapper"),
}); });

View File

@@ -12,14 +12,14 @@
<span class="hidden-email">{{t "(hidden)"}}</span> <span class="hidden-email">{{t "(hidden)"}}</span>
</td> </td>
{{/if}} {{/if}}
{{#unless is_bot}}
<td> <td>
<span class="user_id">{{user_id}}</span> <span class="user_id">{{user_id}}</span>
</td> </td>
{{#unless is_bot}} {{/unless}}
<td> <td>
<span class="user_role">{{user_role_text}}</span> <span class="user_role">{{user_role_text}}</span>
</td> </td>
{{/unless}}
{{#if is_bot}} {{#if is_bot}}
<td> <td>
<span class="owner"> <span class="owner">

View File

@@ -13,7 +13,7 @@
<thead class="table-sticky-headers"> <thead class="table-sticky-headers">
<th class="active" data-sort="alphabetic" data-sort-prop="full_name">{{t "Name" }}</th> <th class="active" data-sort="alphabetic" data-sort-prop="full_name">{{t "Name" }}</th>
<th data-sort="email">{{t "Email" }}</th> <th data-sort="email">{{t "Email" }}</th>
<th data-sort="id">{{t "User ID"}}</th> <th class="user_role" data-sort="role">{{t "Role" }}</th>
<th data-sort="bot_owner">{{t "Owner" }}</th> <th data-sort="bot_owner">{{t "Owner" }}</th>
<th data-sort="alphabetic" data-sort-prop="bot_type">{{t "Bot type" }}</th> <th data-sort="alphabetic" data-sort-prop="bot_type">{{t "Bot type" }}</th>
{{#if is_admin}} {{#if is_admin}}