Commit Graph

156 Commits

Author SHA1 Message Date
Anders Kaseorg 21d432e12c zjsunit: Deglobalize run_test.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-12-01 07:14:00 -05:00
Anders Kaseorg 425f1789e2 zjsunit: Deglobalize namespace.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-12-01 07:14:00 -05:00
Anders Kaseorg 7b03d48798 zjsunit: Deglobalize assert.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-12-01 07:14:00 -05:00
sahil839 1477416515 stream_data: Exclude private streams from get_non_default_stream_names.
We do not show private streams in default streams typeahead as we do
not allow to set private stream as default.
2020-10-29 15:47:34 -07:00
Anders Kaseorg b178fc6069 eslint: Fix unicorn/prefer-set-has.
https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/prefer-set-has.md

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-10-07 16:00:33 -07:00
sahil839 ab90abfa4c stream_data: Rename sub.is_admin to sub.is_realm_admin.
This commit renames sub.is_admin to sub.is_realm_admin such that
we can clearly differentiate between realm and stream admins.
2020-09-14 22:05:31 -07:00
Priyank Patel b7998d3160 js: Purge people module from window. 2020-09-01 19:55:58 -07:00
Ryan Rehman b4888c1251 subscriptions: Refactor template rendering of `stream_privacy_policy`.
This makes it similar to `stream_post_policy`.
2020-08-04 15:48:35 -07:00
Anders Kaseorg 6ec808b8df js: Add "use strict" directive to CommonJS files.
ES and TypeScript modules are strict by default and don’t need this
directive.  ESLint will remind us to add it to new CommonJS files and
remove it from ES and TypeScript modules.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-31 22:09:46 -07:00
sahil839 ed96758614 stream_data: Add subscribed_stream_ids function.
We add a function subscribed_stream_ids which returns an array
of stream ids of all subscribed streams.

This is a prep commit for changing the logic for sorting streams
to store stream ids instead of names.
2020-07-28 16:57:50 -07:00
Anders Kaseorg 1d59fc272c js: Use Marked.js as a module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-28 10:54:35 -07:00
Anders Kaseorg d2520cd7e0 js: Replace underscore with lodash and remove it from globals.
Tweaked by tabbott to bump PROVISION_VERSION.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2020-07-26 16:12:06 -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 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
sahil839 a0d2c7db16 stream_data: Modify is_user_subscribed to use stream id.
This commit changes stream_data.is_user_subscribed to use stream id
instead of stream name.
We are using stream ids so that we can avoid bugs related to live
update after stream rename.
2020-07-13 13:09:17 -07:00
sahil839 66dc712830 compose: Modify validate_stream_message to check invalid stream name early.
We change validate_stream_message to check the existence of stream from
the stream name in compose box early and we then pass stream_id or the
obtained sub objects accordingly to other validate functions.

Passing stream_id or sub objects to these functions, enables us to use
stream_id instead of stream name in stream_data.get_subscriber_count.

stream_data.get_stream_post_policy is also removed as we only used it in
validate_stream_message_policy, but we do not need it now as we can get
stream_post_policy directly from sub object obtained by early check of
valid stream name.
2020-07-06 15:30:01 -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 615b7fcc2c eslint: Enable arrow-body-style.
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
Steve Howell 2574efde3d urls: Support simple integer stream slugs.
Fixes #15402
2020-07-03 16:50:18 -07:00
sahil839 28b6af5c4b stream_data: Modify create_sub_from_server_data to use stream id.
This commit changes stream_data.create_sub_from_server_data to use
stream id, instead of stream name, for checking whether subscription
already exists or not. We are using stream ids so that we can avoid
bugs related to live update after stream rename.
2020-06-22 13:39:47 -07:00
sahil839 235601d3b6 stream_data: Modify remove_subscriber to use stream id.
This commit changes stream_data.remove_subscriber to use stream id
instead of stream name. We are using stream ids so that we can
avoid bugs related to live update after stream rename.
2020-06-22 13:39:47 -07:00
sahil839 ddbfbdc386 stream: Modify stream_data.add_subscriber to use stream_id.
Thsi commit changes stream_data.add_subscriber to use stream_id
instead of stream name. We are using stream ids so that we can
avoid bugs related to live update after stream rename.
2020-06-22 13:39:47 -07:00
sahil839 f3604fbb1e stream_edit: Refactor receives_notifications to use stream ids.
This commit changes receives_notifications function to use
stream_ids instead of stream names. We are using stream ids so
that we can avoid bugs related to live update after stream rename.
2020-06-22 13:39:47 -07:00
sahil839 d9b7228444 streams: Add frontend to set/update message_retention_days of a stream.
This commit adds frontend support for setting and updating message
retention days of a stream from stream settings.

Message retention days can be changed from stream privacy modal of the
stream and can be set from stream_creation_form while creating streams.

Only admins can create streams with message_retention_days value other
than realm_default.

This commit also contains relevant changes to docs.
2020-06-18 17:00:34 -07:00
Ryan Rehman cfc87e3925 message list: Move the `FetchStatus` object to MessageListData class.
The reason for this change is that, this is where `Filter` and
actual tracking of what messages are contiguous lives. This
will be beneficial when we will to move to a model where we
cache `MessageListData` objects for a large number of views.
2020-06-02 15:45:39 -07:00
clarammdantas aae7c79c00 people.js: Rename add() to add_active_user(). 2020-05-26 21:41:54 -07:00
Rohitt Vashishtha 8bf407878d stream_data: Create realm_has_notifications_stream().
We use this as part of our effort to wrap the use of -1 for null/None
from the rest of the code.
2020-04-22 17:57:16 -07:00
Rohitt Vashishtha e79935dbf7 stream_data: Remove page_params.notifications_stream.
We shouldn't add redundant data to page_params. Since we already have
page_params.realm_notifications_stream_id, we can use that value instead
of creating page_params.notifications_stream.

We, however, still need the name of the notifications stream to render
it in templates. Thus we create stream_data.get_notifications_stream().
2020-04-22 17:57:16 -07:00
Rohitt Vashishtha c8b0627ffe zblueslip: Run blueslip.reset after each test.
This simplifies the blueslip interface to just declaring expected
errors and calling the code to test.
2020-04-20 08:17:20 -04:00
Rohitt Vashishtha 9fd645f9ee zblueslip: Remove redundant get_test_logs calls. 2020-04-20 08:17:20 -04:00
Rohitt Vashishtha 0def4a97ae zblueslip: Implement tracking extra/lesser blueslip calls.
We change the user facing interface to allow specifying expected
number of error messages (default=1). Now an average test can look
like:

```
    // We expect 3 error messages;
    blueslip.expect('error', 'an error message', 3);
    throwError();
    throwError();
    throwError();
    blueslip.reset();
```
2020-04-20 08:17:20 -04:00
Hashir Sarwar ee0d4541b4 topic_data: Rename `topic_data` module to `stream_topic_history`.
`stream_topic_history` is a more appropriate name as this
module will contain information about last message of a
stream in upcoming commits. Function and variable names
are changed accordingly like:

* topic_history() -> per_stream_history()
* get_recent_names() -> get_recent_topic_names()
* name -> topic_name
2020-04-16 20:11:04 -07:00
Steve Howell e64059de79 node tests: Remove most test_log length assertions.
For all the places where we just make zero or one
blueslip call, asserting for length is either
unnecessary or overkill.
2020-04-08 11:37:27 -04:00
Steve Howell 9943a07e8c node tests: Improve handling of blueslip.fatal().
We now use `assert.throws()` to test that we're
properly calling `blueslip.fatal`.

In order to not break line coverage here, we have
to remove an unreachable `return` in `stream_data.js`.

Usually we test `fatal` for line coverage reasons.
Most places where we use `blueslip.fatal` fall in
these categories:

    * the code is theoretically unreachable, but
      we have `blueslip.fatal` for defensive reasons

    * we have some upstream bug that we should just
      fix

    * the code should recover gracefully and just
      use blueslip.errors()

It's possible that we should eliminate `blueslip.fatal`
from our API and just throw errors when really important
invariants get broken.  This will make it more obvious
to somebody reading the code that we're not going to
continue after the call, and `blueslip` already knows
how to catch exceptions and report them.
2020-04-08 11:37:27 -04:00
Steve Howell f7b432afec node tests: Auto-include zblueslip for node tests.
We already use blueslip stubs in ~45 tests, so we
may as well just auto-include it.
2020-04-03 12:56:49 -04:00
Steve Howell df84c52a7f zblueslip: Change API to expect/reset.
The `set_test_data` never made complete sense to
me, since it wasn't really data that we were
setting.
2020-04-03 12:56:49 -04:00
Ryan Rehman c759083cb8 notification settings: Add helper function for stream notifications.
This function returns a list of objects to create a
list_render object, and each item contains the streams
whose atleast one notification setting differs from the
default set by the user.

This is done by comparing the global settings in the
`#settings/notifications` page with those settings
present in the subscribed streams.

Work towards #9228.
2020-03-31 15:36:59 -07:00
Steve Howell 2cd9c77979 refactor: Stop using page_params.realm_default_streams.
We now only use `page_params.realm_default_streams` during
initialization, and then after that we use `stream_data`
APIs to get default stream ids and related info.  (And
for the event that replace the data, we just update our
internal data structures as well.)

Long term we should have the server just send us ids here,
since we are now hydrating info from stream data in all places.
2020-03-25 17:11:25 -07:00
Steve Howell 6313917143 stream_data: Remove invite_streams().
This function was made obsolete in
b4e2313cbc.

It was replaced by get_invite_stream_data(),
which has plenty of coverage.
2020-03-25 17:11:25 -07:00
Steve Howell 4610ef3169 refactor: Remove stream_data.get_default_status().
There was no reason to have this when it's more
robust to look up streams by id than name.
2020-03-25 17:11:25 -07:00
Steve Howell 8d8226117c refactor: Extract get_default_stream_ids().
We only used get_default_stream_names() in a
test, so now it's being replaced with a function
that just gets ids.

We'll have use for get_default_streams_ids()
in an upcoming commit.
2020-03-25 17:11:25 -07:00
Steve Howell c86ccd8c6e tests: Remove obsolete page_params test setup.
This test code has basically been dead since
we started passing in `params` to
`stream_data.initialize()`, and now it's
more confusing than helpful.
2020-03-25 17:11:25 -07:00
Steve Howell f0c99b42ec Rename people.add_in_realm to people.add().
We had this API:

    people.add_in_realm = full-fledged user
    people.add = not necessarily in realm

Now the API is this:

    people.add = full-fledged user
    people._add_user = internal API for cross-realm bots
        and deactivated users

I think in most of our tests the distinction between
people.add() and people.add_in_realm() was just an
accident of history and didn't reflect any real intention.

And if I had to guess the intention in 99% of the cases,
folks probably thought they were just creating ordinary,
active users in the current realm.

In places where the distinction was obviously important
(because a test failed), I deactivated the user via
`people.deactivate`.

For the 'basics' test in the people test suite, I clean
up the test setup for Isaac.  Before this commit I was
adding him first as a non-realm user then as a full-fledged
user, but this was contrived and confusing, and we
didn't really need it for test coverage purposes.
2020-03-22 10:55:11 -07:00
Steve Howell 156ff33d22 stream edit: Extract stream_data.potential_subscribers().
We want to move more logic to stream_data to facilitate
testing.

Both before and after this commit, we essentially build a
new list of users for typeahead, but now the new list
excludes subscribed users.  We can do even better than
this in a follow-up commit.
2020-03-22 10:55:11 -07:00
Steve Howell b994889315 node tests: Just set i18n every time.
Explicitly stubbing i18n in 48 different files
is mostly busy work at this point, and it doesn't
provide much signal, since often it's invoked
only to satisfy transitive dependencies.
2020-02-28 17:11:24 -08:00
Steve Howell da79fd206a ui_init: Handle page_params more cleanly.
This cleans up the handoff of page_params
data between ui_init and modules that
take over ownership of page_params-derived
data.

Read the long comment in ui_init for a bit
more context.

Most of this diff is actually test cleanup.
And a lot of the diff to "real" code is
just glorified `s/page_params/params/`
in the `initialize` functions.

One little oddity is that we don't actually
surrender ownership of `page_params.user_id`
to `people.js`.  We could plausibly sweep
the rest of the codebase to just use
`people.my_user_id()` consistently, but it's
not a super high priority thing to fix,
since the value never changes.

The stream_data situation is a bit messy,
since we consume `page_params` data in the
initialize() function in addition to the
`params` data we "own".  I added a comment
there and intend to follow up.  I tried
to mostly avoid the "word soup" by extracting
three locals at the top.

Finally, I don't touch `alert_words` yet,
despite it also doing the delete-page-params-data
dance.  The problem is that `alert_words`
doesn't have a proper `initialize()`.  We
should clean that up and have it use a
`Map` internally, too.
2020-02-26 13:14:09 -08:00
Steve Howell 5e8279c2fb refactor: Extract settings_config.
This moves some code from settings_display.js
into the new module settings_config.js.

Extracting this module breaks some dependencies
on settings_display.js (which has some annoying
transitive dependencies, including jQuery).

In particular this isolates stream_data from
from settings_display.js.

Two of the three structures that we moved here
weren't even directly used by settings_display.js,
since we do a lot of rendering in the modules
admin.js and setting.js.

We make get_all_display_settings() a function
to avoid a require-time dependency on page_params.

Breaking the dependencies simplifies a few
node tests.

Most of the node test complexity came from the
following commit in March 2019:

5a130097bf

The commit itself seems harmless enough, but
dependencies can have a somewhat "viral" nature,
where making stream_data depend on settings_display
caused us to modify four different node tests.
2020-02-21 12:06:31 -08:00