Commit Graph

156 Commits

Author SHA1 Message Date
Anders Kaseorg e3b3df328d eslint: Replace sort-imports with import/order.
import/order sorts require() calls as well as import statements.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-24 09:42:56 -07:00
Anders Kaseorg 96dcc0ce6e js: Use ES6 object literal shorthand syntax.
Generated by ESLint.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-21 12:42:22 -07:00
Anders Kaseorg b65d2e063d js: Reformat with Prettier.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg 8046b6477a js: Remove extra consecutive spaces.
Prettier would do this anyway, but it’s separated out for a more
reviewable diff.  Generated by ESLint.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg 6924d501bc js: Indent case clauses in switch statements.
Prettier would do this anyway, but it’s separated out for a more
reviewable diff.  Generated by ESLint.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:25 -07:00
Anders Kaseorg f3726db89a js: Normalize strings to double quotes.
Prettier would do this anyway, but it’s separated out for a more
reviewable diff.  Generated by ESLint.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-17 14:31:24 -07:00
Aman Agrawal 19b7ef3888 list_render: Use simplebar container to track scroll event.
We have changed our all instances of list_render to use
simplebar and thus, we will now use simplebar container
to track scroll event for all the lists created by
list_render.

This fixes the bug of new subscribers not rendering on
scrolling at the end of subscriber list in stream settings
and similar bug in some other lists also.

This commit also removes scroll_util.get_list_scrolling_container
function as this is no longer used.

Fixes #15637.
2020-07-15 10:16:56 -07:00
Anders Kaseorg e014ea966a eslint: Enable comma-dangle for functions.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:55:51 -07:00
Anders Kaseorg a79322bc94 eslint: Enable prefer-arrow-callback.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:55:50 -07:00
Anders Kaseorg b0253c5a2e eslint: Enable arrow-parens.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-03 16:53:39 -07:00
Pragati Agrawal d453520022 settings_user: Fix event propagation for bot and user edit form modal.
When the user clicks a button that opens a modal, and if we don't break off
the corresponding click event. This condition in the global click handler
will become true and enables all mouse events outside modal.

```js
    $(document).on('click', function (e) {
        ...
        // If user clicks outside an active modal
        if ($('.modal.in').has(e.target).length === 0) {
            // Enable mouse events for the background as the modal closes
            $('.overlay.show').attr("style", null);
        }
```

Related to #12369.
2020-06-19 12:53:13 -07:00
sahil839 dbd64c4362 settings_users: Only owner can deactivate other owners.
This commit adds the restriction of deactivating owners for admins
by disabling the deactivating button in the UI. Only owners are
allowed to deactivate other owners. The backend part of this is
already implemented in 86b52ef.
2020-06-14 21:20:30 -07:00
sahil839 c7a68d60f3 realm owner: Add frontend implementation of owner role.
This commit adds the option of owner role in user role dropdown
and also takes care of the restrictions while adding/removing
owner status of the user.
This commit also handles the places where we dispaly role of
the user in UI.
2020-06-14 21:20:30 -07:00
Clara Dantas 451ea753a2 settings_users: Simplify get_item function. 2020-06-10 12:14:58 -07:00
Clara Dantas db197d0abd settings_users: Use user_ids for the users list_render.
This is part of a refactor that aimed to remove /json/users calls,
as we can get all the information needed on people API.

Now, the list render for $users_table and $deactivated_users_table
uses user_ids instead of user objects, as the people API give us
a filtered list of active_user_ids and non_active_user_ids.
2020-06-09 20:11:23 -07:00
Clara Dantas 6449366d64 settings_users: Remove unnecessary sort.
The populate_users function doesn't need to sort the list of
active and non-active users, because the list_render is called
specifying to sort users by their full_name.

Author: Clara Moraes Dantas <clara.moraesd@gmail.com>
2020-06-09 20:11:23 -07:00
Clara Dantas e95718f741 settings_users: Remove /json/users calls.
As part of a refactoring, we are now able to remove the
/json/users calls and get all the information needed on people.js.

To do this, now the populate_users uses the people api to get
all the active and non active human users.
2020-06-09 20:11:23 -07:00
Clara Dantas 23ca3381f6 settings_users.js: Calculate is_active in human_info.
This is part of a refactoring aimed to eliminate /json/users calls,
as we can have all the information needed on people.js.

Now, human_info() will call is_person_active() because the person
object it will receive won't have is_active field anymore, as
we'll use the people api to get a set of filtered active/non active
users.

Author: Clara Moraes Dantas <clara.moraesd@gmail.com>
2020-06-09 20:11:23 -07:00
Clara Dantas e1e755c887 people.js: Change functions to return a list of ids instead of objects.
The get_active_humans and get_non_active_humans functions used
to return a list of user objects. The get_active_humans is used
on settings_users.js and settings_bots.js, and in both places the
only attributes needed of the person object are the user_id and
full_name.

To make the function return smaller, instead of a list of active
humans, we are returning a list of active human ids, saving memory.
With the ids we can call the people API to get the full_name attribute.
2020-06-04 14:23:52 -04:00
Sahil Silare c4d0bd6445
settings: Fix last_active sorting in user settings.
We were incorrectly accessing .id, not .user_id, on the people objects.

Fixes #15165.
2020-06-02 12:07:09 -07:00
sahil839 2ab6767b73 events: Update person dict in event for do_change_user_role to send role.
This commit changes the person dict in event sent by do_change_user_role
to send role instead of is_admin or is_guest.

This makes things much more straightforward for our upcoming primary
owners feature.
2020-05-31 17:22:50 -07:00
Clara Dantas 080014abcc settings_users: Fix bot_list_widget not defined.
Fix error thrown when creating a bot if the bot_list_widget
is not defined.
2020-05-30 12:23:49 -07:00
sahil839 9fa60672e6 users: Modify update user API endpoint to accept role as parameter.
This commit changes the update user API endpoint to accept role
as parameter instead of the bool parameters is_guest and is_admin.

User role dropdown in user info modal is also modified to use
"dropdown_options_widget".

Modified by tabbott to document the API change.
2020-05-29 14:29:17 -07:00
Rohitt Vashishtha 58b612a4f0 settings-users: Rerender bot rows on data change.
Previously, we fiddled with the existing HTML to update the
state. Now, we can use list_render.render_item() to render
the complete item properly.
2020-05-28 17:10:51 -04:00
Rohitt Vashishtha 1091615b17 edit-bot: Show dropdown list widget for selecting owner.
This commit removes user_dropdown in favor of the common
dropdown_list_widget for our bot edit forms.
2020-05-20 09:51:38 -07:00
Rohitt Vashishtha c70eb8b772 settings_bots: Do not destroy section when switching to users section.
We were destroying the bots table in start_data_load() which is now
only called for the users section since the refactoring done in
5c16bb9c99.
2020-05-18 17:02:00 -04:00
Steve Howell 9f137c3a05 bots: Extract user_dropdown widget.
We use this new widget in bot settings panels
(personal and org).  It lets you re-assign a
bot to a new human user.

Ideally we can improve this code to use
our existing list widgets to make it more
performant for realms with lots of users.
2020-05-11 16:16:58 -07:00
Steve Howell 5c16bb9c99 bot settings: Load bots independently.
We no longer use `/json/users` in the codepath
for bot settings (admin side).

We also specifically don't load human users when
we load bots, so you no longer have to pay for
the server round trip as a side effect of loading
bots.  Instead, there is a dedicated `set_up_bots`
entry point.

We also get the bot ids directly from `bot_data` now.

This commit, to some degree, builds on the prior commit
that had us hydrate data from `people.js` instead
of the payload from `/json/users`.
2020-05-11 16:16:58 -07:00
Steve Howell f6b1176045 bot settings: Use `get_item` in the list widget.
Our `list_render` list widget gives us the
option to use ids as our "list" and then
hydrate that list on-demand with an
`opts.get_item` function.

We now use that for the bots list, passing
in `bot_info` as that option.

And, importantly, we are now actually
hydrating the bot data from `bot_data.js`
data structures, and not `/json/bots`.

Using the `get_item` scheme has a couple
benefits:

    - Our sort functions are based on the
      actual items that we use to build the
      template, so there's a bit less
      code duplication.  (Generally, the
      data that we pass in to the template
      is "finalized" in some sense, such
      as the bot owner name.)

    - We are less likely to display stale
      data.

    - We are less likely to wire up filters
      to intermediate data elements that are
      not actually displayed to users (think
      of email vs. delivery_email).

We do rely on `get_item` (i.e. `bot_info`)
to be inexpensive, which it should be.

Note that we haven't completely decoupled
ourselves from `/json/bots`, which we still
use as our source for bot user_ids.  We will
fix that in the next commit.
2020-05-11 16:16:58 -07:00
Steve Howell cea6214ce8 user settings: Remove reset/meta.loaded logic.
We don't really need to know whether we've loaded
the user-related panels, since we only used `meta.loaded`
for a tiny optimization to avoid a jQuery lookup.

We rely mostly on the list widgets from `list_render`,
and they are smart enough to repopulate themselves
when they're called subsequent times.
2020-05-11 16:16:58 -07:00
Steve Howell 393551bf81 bot settings: Live-update w/owner name (not email).
This fixes the fact that we update the bot table
with the owner's email instead of a name, but as
the TODO indicates, this is not a full fix, since
I don't linkify the owner name.

To do the full fix properly, I want to make it
so that the `list_render` widgets can just be given
an id of a row to update, and that's coming soon,
hopefully.  If I get sidetracked, the ugly ways to
do this are one of the following:

    - just duplicate what the template does in
      jQuery

    - extract a partial to draw the bot owner link

The full solution here should fix ALL the live
update code in `update_user_data`, which is why
I'm hesitant to add any interim complexity.
2020-05-11 16:14:04 -07:00
Steve Howell 47f07eeb2e minor: Move update_user_data() down in file.
This is just a lexical change.  We are going
to use some shared code soon that we don't want
to export, and if `update_user_data()` is
declared too early in the file, then the function
we extract will either need to be exported (to
satisy the linter) or placed far away from its
most natural siblings.
2020-05-11 16:14:04 -07:00
Steve Howell 91fa64e8e6 refactor: Extract `bot_owner_full_name`.
We will use this for a patch to the live-update
code, and it also de-clutters `bot_info`.

This function could plausibly live in `people.js`,
but it's not worth the indirection at this time,
and, also, one of the upcoming callers to the
function will only temporarily need it.

There's a little bit of a chicken/egg problem
going on:

    - It's hard to have nice system-wide
      APIs related to bots while bot settings
      are still in flux.

    - It's hard to clean up the bot settings
      code while the system-wide API is still
      kinda messy.

But I'm making slow progress on that front.
2020-05-11 16:14:04 -07:00
Steve Howell c8fd4e01e1 minor: Remove obsolete `is_active_human`. 2020-05-11 16:14:04 -07:00
Steve Howell 2df183142c user settings: Flatten template data.
We now no longer have to remember that
`is_guest` is on `user` but `is_current_user`
is in `..`.

And we no longer have to remember that
`full_name` is on `user` but `display_email`
is in `..`.
2020-05-09 10:41:14 -07:00
Steve Howell 71c2bde665 user settings: Extract human_info(). 2020-05-09 10:41:14 -07:00
Steve Howell e9298dab5b bot settings: Extract bot_info().
We now gather all the bot info in one place, rather
than grabbing some of it during the triage phase and
then some of it later.

We also explicitly copy over the fields that we
need for the template, in preparation for two
efforts:

    - We want to get data from `people.js` and
      avoid the round trip to `<server>/json/users`.

    - We want to simplify the template by
      flattening our data.  (It's really somewhat
      arbitrary whether `is_admin` is a calculated
      value, for example, but we currently leak
      that implementation detail to the template.)

We can't flatten this data quite yet, since we
share the same template for bot users as human users,
so we'll fix the human data in a bit.
2020-05-09 10:41:14 -07:00
Steve Howell d45f0171cb user settings: Avoid status_field confusion.
We now close on status_field in our event handlers,
so that there's no chance of writing to the wrong
status field if somebody switches panels before
we have a status to report.

We can't eliminate `get_status_field` yet, but that
will go away in a future commit.
2020-05-09 10:41:14 -07:00
Steve Howell 8508cb6058 user settings: Clean up event handler code.
We now create the event handlers directly in
`set_up()`, and we explicitly tie them to
each of the three tables.

The goal here is to allow us to set up
the three tables individually, and this gets
us closer to that goal.
2020-05-09 10:41:14 -07:00
Steve Howell 772d7fa705 user settings: Improve deactivation-confirm code.
We are now more rigorous about only showing one
modal, only having one handler active, and not
needing to pull info out of the DOM.
2020-05-09 10:41:14 -07:00
Steve Howell fd3d7fa9f2 user settings: Move get_human_profile_data().
This is a purely lexical move (apart from changing
a closure variable to an argument), which is
simply designed to make less indentation for the
reader and to de-clutter `handle_human_form`.
2020-05-09 10:41:13 -07:00
Steve Howell f3e425c071 user settings: Build profile fields in open_human_form. 2020-05-09 10:22:37 -07:00
Steve Howell 79c25f40ce minor: Use person.full_name directly.
The get_full_name() helper is overkill when
we already have the `person` object, and the
surrounding code is already referencing fields
directly.
2020-05-09 10:22:37 -07:00
Steve Howell d5cadbcec2 user settings: Separate code for bot form.
When editing a bot, there are only two fields
that are similar to humans--full name and
email--which are trivial.

Before this commit we used a single codepath
to build the human form and the bot form.

Now we have two simple codepaths.

The tricky nature of the code had already led
to ugly things for the bot codepath that
fortunately weren't user facing, but which
were distracting:

    - For bots we would needlessly set things
      like is_admin, is_guest in the template
      data.

    - For bots we would needlessly try to update
      custom profile fields.

The code that differs between bots and humans
is nontrivial, and the code was both hard to read
and hard to improve:

    - Humans don't have bot owners.

    - Bots don't have custom profile fields.

The bot-owner code is nontrivial for performance
reasons.  In a big realm there are tens of thousands
of potential bot owners.  We avoid the most egregious
performance problems (i.e we don't have multiple
copies of the dropdown), but we may still want
to refine that (at least adding a spinner).

The custom-profile-fields code is nontrivial due
to the dynamic nature of custom profile fields,
which can bring in specialized widgets like
pill fields.

Now each form corresponds to a single endpoint:

    * human -> /json/users
    * bot -> /json/bots

Before we had a lot of conditional logic in
the template, the code to build to views, and
the code to submit the data.  Now everything is
much flatter.

The human code is still a bit messy (more work
coming on that), but the bot code is fairly
pristine.  All three components of the bot code
fit on a page, and there are no conditionals:

    - admin_bot_form.hbs
    - open_bot_form
    - handle_bot_form

We may want to grow out the bot code a bit
to allow admins to do more things, such as
adding services, and this will be easier now.
It would also be easier for us now to share
widgets with the per-user bot settings.

Note that the form for editing human data will
continue to be invoked from two panels:

    - Users
    - Deactivated users

There are some minor differences between
users and deactivated users, but the shape of
the data is the same for both, so that's still
all one codepath.

We eliminate `reset_edit_user` here, since
it was never used.

One nice thing about these forms was that they
had very little custom CSS attached to them
(at form-level specificity), and it turned out
all the custom CSS was for the human-specific
form.
2020-05-09 10:22:37 -07:00
Steve Howell f2ee1a1a65 user settings: Extract handle_* helpers.
This is purely refactoring.

The new call tree is:

    on_load_success
        populate_users
        handle_deactivation
        handle_reactivation
        handle_user_form
        handle_bot_owner_profile
        handle_bot_deactivation

The actual sequence of operations should be
identical to before.
2020-05-09 10:22:37 -07:00
Steve Howell 56517788fb user settings: Extract section.*.create_table(). 2020-05-09 10:22:37 -07:00
Steve Howell 2272c5e6eb modals: Use selectors for open_modal/close_modal.
When reading the calling code, it's helpful to know
that we're really just passing in a selector.  The
calls to open_modal/close_modal are nicer now to
reconcile with surrounding code, and you don't have
to guess whether the parameter is some kind of
"key" value--it really just refers directly to a DOM
element.

There is nothing user-visible about this change, but
the blueslip info messages now include the hash:

    open modal: open #change_email_modal
2020-05-09 10:22:37 -07:00
Jagan c69dc720ff admin user list: Replace the buttons with icons.
1. Replaced the deactivate and reactivate buttons with icons.
2. Added (you) near the current user name to denote his/her account in
the entire user list.

Tweaked by tabbott to reuse the (you) formatting from the right
sidebar here for readability and consistency.

Fixes #6313.
2020-04-23 16:49:57 -07:00
Steve Howell aa5ffcbd2e admin user: Sort bot owners by name.
The original commit here was sorting bot owners by
id, which is of course meaningless to users:

    444ce74a8e

It was also returning 1/-1 in cases where the bot
owner on both sides of a comparison were missing,
which is a big no-no for sorting algorithms.
2020-04-15 15:13:26 -07:00
Steve Howell 0b71b092b3 admin users: Fix email sort.
The email sort now works correctly for admins in
realms with hidden emails.  (We want to sort on
delivery email.)
2020-04-15 15:13:26 -07:00