Commit Graph

208 Commits

Author SHA1 Message Date
Sahil Batra b4eddad9a5 people: Use names in PM urls instead of emails.
We change the "pm-with" and "sender" narrow urls
to be of "{user-id}-{encoded_name}" form instead
of using email. This change improves performance
of changing between PM views since parseOneAddress
function was slow and we remove its usage now by
using name instead of email.

The name is encoded such that the characters that
would be encoded by the browsers are replaced by
"-".
2022-10-25 10:42:00 -07:00
yogesh sirsat d3b4b1cefd stream_bots: Display unsubscribe button on bots full profile modal.
Displaying unsubscribe button on bots full profile modal, allowing bot
owners to ubsubscribe their bots from streams.

Admins can also unsubscribe any bot from any subscribed streams from
bots full profile modal.

Fixes part of: #21402
2022-09-16 17:51:34 -07:00
evykassirer bc2149d1ef people: Extract emails_to_full_names_string helper.
This code that previously lived in a larger function is needed by
another function in PR #22127.
2022-08-25 17:48:50 -07:00
Anders Kaseorg 485fe8556e zjsunit: Defer run_test execution to the end of the test module.
This is consistent with Jest and other standard test runners, and is
necessary to support asynchronous tests.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-08-18 08:55:31 -07:00
Anders Kaseorg c520890f54 node_tests: Remove low-hanging uses of __Rewire__.
When we were preparing the conversion to ES modules in 2019, the
primary obstacle was that the Node tests extensively relied on the
ability to reach into modules and mutate their CommonJS exports in
order to mock things.  ES module bindings are not mutable, so in
commit 173c9cee42 we added
babel-plugin-rewire-ts as a kludgy transpilation-based workaround for
this to unblock the conversion.

However, babel-plugin-rewire-ts is slow, buggy, nonstandard,
confusing, and unmaintained.  It’s incompatible with running our ES
modules as native ES modules, and prevents us from taking advantage of
modern tools for ES modules.  So we want to excise all use of
__Rewire__ (and the disallow_rewire, override_rewire helper functions
that rely on it) from the tests and remove babel-plugin-rewire-ts.

Commits 64abdc199e and
e17ba5260a (#20730) prepared for this by
letting us see where __Rewire__ is being used.  Now we go through and
remove most of the uses that are easy to remove without modifying the
production code at all.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-07-13 16:27:30 -07:00
somesh202 b1cafb1280 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.
2022-05-10 14:09:57 -07:00
Anders Kaseorg a682530fd4 node_tests: Enforce 100% coverage for test files.
This makes it easier to find obsolete parts of the tests that should
be cleaned up.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-04-10 19:31:56 -04:00
Steve Howell c43d48b22f stream create: Overhaul create-stream add-subscribers UI.
The most notable change here is that when you are adding
subscribers to a stream as part of creating the stream,
you can now use the same essential pill-based UI for
adding users as we do when you edit subscribers for an
existing stream.

We don't try to exactly mimic the edit-stream UI or
implementation, since when you are adding subscribers
during create-stream, we are just updating a list in
memory, whereas in the edit-stream UI, we immediately
send info to the server.

Fixes #20499
2022-03-07 16:58:58 -08:00
Steve Howell d994dcbfb2 node tests: Test people.get_users_from_ids. 2022-02-22 16:29:36 -08:00
Anders Kaseorg 64abdc199e zjsunit: Split deprecated __Rewire__ functionality out of override.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-01-08 10:01:27 -05:00
Steve Howell 6c9427340a refactor: Move user-sorting code to people.js.
We also remove the blueslip check, since it is
pretty easy to audit the callers here.
2021-12-16 15:28:11 -08:00
somesh202 219ecea659 people: Extract helper functions for medium avatar urls.
The new is obviously parallel with the small avatar URL construction,
and allows us to deduplicate this construction between the popovers
and full user profile logic for getting a medium avatar URL.

Fixes #20140.
2021-12-02 14:56:34 -08:00
Sahil Batra 16d35f5b4e streams: Hide fake emails in stream creation form.
We hide fake emails in "People to add" section of
stream creation form and instead show user id
along with specifying that email is hidden.
2021-11-18 12:49:10 -08:00
Anders Kaseorg cab0f9c219 people: Fix small avatar URL generation.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-10-14 12:47:43 -07:00
Sahil Batra 998d710275 frontend: Add new user_settings module for user's settings.
We add a new user_settings module similar to page_params
module in frontend and use it to access user's personal
settings instead of page_params.
2021-08-01 15:30:17 -07:00
Priyank Patel 968a8c4e50 js: Split out muted_users module from muting. 2021-06-30 16:32:55 -07:00
Hashir Sarwar 7b9ed4ff2e people: Allow deactivated users pills in compose box.
This commit treats deactivated users as valid users
for compose box which prevents the PM list to collapse
when a deactivated user in the PM list is clicked.

Part of #13766

Co-authored-by: Signior-X <b19188@students.iitmandi.ac.in>
2021-06-25 18:01:15 -07:00
Steve Howell 9e657dd795 node tests: Use {override} in run_test. 2021-06-16 12:55:53 -04:00
Riken Shah f95c539122 custom_check: Avoid use of assert to avoid confusion with assert.equal.
This commit bans the use of `assert` and replaces it
with `assert.ok` to avoid confusion with `assert.equal`.

Fixes #18687.
2021-06-10 09:15:57 -07:00
Vishnu KS 5db53029a5 api: Include is_billing_admin as an attribute in user response.
This is sufficiently useful that it should be made available to clients.
2021-06-03 10:27:07 -07:00
akshatdalton 78b59fa756 people: Fix `get_mention_syntax` when `full_name` matches wildcard.
When quoting a reply or mentioning a person having full name matching
wildcard mention, in such case, `get_mention_syntax` doesn't return
mention syntax of format: **full_name|user_id**.
As a result, a normal user can't mention such users and users who
can mention them may unwillingly trigger wildcard mention.
This commit fixes such issue.
2021-05-20 11:41:56 -07:00
Abhijeet Prasad Bodas a377a2df8b pm_list: Use "Muted user" placeholder for muted usernames.
This also handles a few other places missed earlier like
narrow headings, beacuse they use the same function.

We already rerender the PM list for events, so there's no
need to do anything special when someone is muted/unmuted.

`people.get_full_names` is now only used in the settings pages
while creating ListWidgets etc, so we add a new test for
it to ensure coverage.
2021-05-13 07:51:21 -07:00
Abhijeet Prasad Bodas e5a339df25 recent topics: Handle muted user avatars in participants.
We use styling same as that of the number shown for overflow
(e.g "+3") which has a gray background.
To keep these avatars up-to-date, we need to rerender the
recent topics view after receiving a `muted_users` event.

Also update the user documentation to mention this detail.
We deliberately avoid mentioning "recent topics" because
this applies to mobile too.
2021-05-12 09:30:24 -07:00
Abhijeet Prasad Bodas e4cbfcaf1d recent senders: Rename sender_info getter function for brevity.
We will also later use this function for attaching other
information to it like whether the sender has been muted
or not.
2021-05-12 09:30:24 -07:00
Abhijeet Prasad Bodas 421cf05176 people: Deduplicate get_full_names logic.
Share code between `safe_full_names` and `get_display_full_names`
functions, and rename `safe_full_names` to `get_full_names_for_poll`,
because that was the only place where this was used earlier.

This also has the nice side effect of showing "Muted user" instead
of the muted username in poll results.
2021-05-11 13:21:38 -07:00
Abhijeet Prasad Bodas 22053d8399 people: User "Muted user" placeholder for muted usernames. 2021-05-10 12:36:39 -07:00
Abhijeet Prasad Bodas 5bcc96508d refactor: Extract people.get_display_full_names.
This deduplicates code used to generate message group headers
and the reactions tooltip.
2021-05-10 12:36:39 -07:00
sahil839 730c0493b3 users: Show user role as 'moderator' in frontend for realm moderators.
This commit modifies the code to show "Moderator" correctly for
realm moderators.

As, we show role using settings_config.user_role_values object and
the same is used for showing options in changing role dropdown, this
commit also adds the moderator option in that dropdown and thus allows
the user to change role to moderator and from moderator to any other
role from frontend.
But the code for live updating page_params.is_moderator and
person.is_moderator will be in further commit.
2021-04-29 15:18:49 -07:00
sahil839 77499589f9 users: Use role value directly to display user role text in frontend.
Since, we now get role value in person objects sent from server, we
can simply user user_role_map to display role in different places
instead of having multiple if-else conditions to check flags like
is_admin, is_guest, etc.
2021-04-29 15:18:49 -07:00
Aman Agrawal 384156c307 stream_create: Use ListWidget to render list of all users.
This improves the UX of creating a stream for atleast 1000+ users
realm by showing the the stream creation form much faster than
before.

Search, user addition, scrolling worked smoothly on 15k+
users realm as tested on dev setup.

Also, simplebar is used to replace the default scrollbar.

Fixes #16805
2021-04-25 08:54:08 -07:00
m-e-l-u-h-a-n ce4cf66f3f setting(streams): Add pill support to subscribe all members of group.
We update the pills typeahead logic to also include user group
results and pass the "user_group" key in `opts` to enable this
option for Add subscriber form.

The changes includes:
* Exporting the `query_matches_name_description` function, to
  deduplicate the typeahead `matcher` logic.
* Creating a `people.is_known_user` function, to deduplicate
  the typeahead `sorter` logic.
* Add a new `user_group_pill.js`, to allow adding user group
  pills in input widgets that support pills.

This has been tested manually as well as by adding some new
node tests.
2021-04-19 17:41:50 -07:00
Anders Kaseorg 2004a85fb1 i18n: Automatically convert remaining JavaScript messages to FormatJS.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-04-13 17:41:10 -07:00
Steve Howell 45d806d9aa refactor: Extract message_helper.process_new_message.
We move the message_store.add_message_metadata function
(and all its dependencies) into a new module called
message_helper and rename the function to process_new_message.
(It does a bit more than adding message metadata, such
as updating our message store.)

We also have a "protected" interface now in message_store,
so that message_helper can access the message store:

    update_message_cache
    get_cached_message

Because update_message_cache is identical to
the former create_mock_message, we just renamed it
in the tests.

Most callers should use these functions:

    message_helper.process_new_message (setting)
    message_store.get (getting)

It's slightly annoying that the setter interface
is in a different module than the getter interface,
but that's how you break a bunch of dependencies.

We also extract the tiny message_user_ids class:

    user_ids()
    add_user_ids()

All the code moves here are pretty trivial, and
the code that was moved maintains 100% line
coverage.

The module name `message_helper` is not ideal, but it's a single
function and it'll save time to just do the topology change now and
leave thinking through the right name to later.
2021-03-29 14:53:57 -07:00
Anders Kaseorg 38ffd47b90 js: Convert static/js/page_params.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-26 10:17:56 -07:00
Anders Kaseorg bb1b2048bd js: Convert static/js/i18n.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-26 10:17:56 -07:00
Steve Howell 8f9126cd91 node tests: Add huddle_string test. 2021-03-19 13:24:55 -04:00
Anders Kaseorg 3ef6f6e2e2 js: Convert static/js/blueslip.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-17 08:47:15 -04:00
Anders Kaseorg 876806eb4d zjsunit: Lift restriction against mocking third party modules.
Use fully resolvable request paths because we need to be able to refer
to third party modules, and to increase uniformity and explicitness.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-03-12 10:06:30 -08:00
Steve Howell 0e4bf2cf53 node tests: Avoid test leaks for people. 2021-03-08 13:06:52 -05:00
Steve Howell f54f7cfc33 node tests: Introduce mock_module helper. 2021-03-06 13:15:04 -05:00
Steve Howell 167fda142c node tests: Remove __esModule cruft.
We just set __esModule in our rewiremock helper.
2021-03-06 12:36:07 -05:00
Steve Howell 30c7108955 zjsunit: Remove rewiremock dependency.
We now just use a module._load hook to inject
stubs into our code.

For conversion purposes I temporarily maintain
the API of rewiremock, apart from the enable/disable
pieces, but I will make a better wrapper in an
upcoming commit.

We can detect when rewiremock is called after
zrequire now, and I fix all the violations in
this commit, mostly by using override.

We can also detect when a mock is needlessly
created, and I fix all the violations in this
commit.

The one minor nuisance that this commit introduces
is that you can only stub out modules in the Zulip
source tree, which is now static/js.  This should
not really be a problem--there are usually better
techniques to deal with third party depenencies.
In the prior commit I show a typical workaround,
which is to create a one-line wrapper in your
test code.  It's often the case that you can simply
use override(), as well.

In passing I kill off `reset_modules`, and I
eliminated the second argument to zrequire,
which dates back to pre-es6 days.
2021-03-06 11:10:57 -05:00
Anders Kaseorg 7145cb4a0d js: Convert static/js/message_store.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-28 14:23:00 -08:00
Steve Howell da1cd57d5f node tests: Use override in more places. 2021-02-24 11:56:40 -05:00
Anders Kaseorg 7e3735b9ba node_tests: Don’t read page_params from deprecated global variable.
Follow up to commit 89aa3155a9 (#17262).

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-22 19:46:42 -08:00
Anders Kaseorg c292342d0e node_tests: Remove irrelevant set_global calls for ES6 modules.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-10 10:27:14 -08:00
Anders Kaseorg 89aa3155a9 node_tests: Don’t read from most deprecated global variables.
We still need to write to these globals with set_global because the
code being tested reads from them, but the tests themselves should
never need to read from them.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-10 07:40:22 -08:00
Anders Kaseorg 9896782fd1 dependencies: Remove XDate.
It’s even more unmaintained than Moment and doesn’t add any
functionality we don’t already have.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-02-07 06:41:33 -05:00
aryanshridhar f92f99d92d dependencies: Replace moment.js with date-fns.
Replaced methods/functions of moment.js with date-fns library.
The motive was to replace it with a smaller frontend timezone library.

Date-fns ~ 11.51 kb
moment.js ~ 217.87 kb

Some of the format strings change because date-fns encodes them
differently from how moment did.

Fixes #16373.
2021-02-05 11:04:32 -08:00
Anders Kaseorg ce42d1194d node_tests: Skip unnecessary explicit uses of global.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-12-01 07:14:00 -05:00