Commit Graph

244 Commits

Author SHA1 Message Date
Lauryn Menard 782cc80d99 account-settings: Refactor change email button and modal class names.
Prep commit for updating tooltip from info icon to disabled button.
2022-12-30 17:54:00 -08:00
Sahil Batra ee04677d4b settings: Remove ID from discard button in save-discard widget.
This commit removes ID from discard button in save-discard widget.

Generating IDs using variables results in difficulty to grep
the code and we can anyway access the discard button by using
ID of the settings-subsection-parent div. Also, we do not use
ID to access this button, so we can change this safely.
2022-12-07 10:23:47 -08:00
Sahil Batra 4b46f08b5f settings: Use subection-parent div to get subsction.
We used id of save-button to get subsection parameter
which is passed to get_complete_data_for_subsection.

This commit now changes it to instead get subsection
from settings-subsection-parent div. We also change
the id of settings-subsection-parent div of organization
joining settings in this commit to be a more reasonable
name as per this change.
2022-12-07 10:23:47 -08:00
Sahil Batra 8241e2d353 settings: Refactor code for realm message retention setting.
This commit refactors the code for realm message retention
setting which will help us in reusing some code when adding
save-discard widget for stream settings in further commits.

Following changes have been done in this commit -

- Renamed the "retain_for_period" option to "custom_period"
and "retain_forever" option to "unlimited" to match with
the stream settings options such that we can reuse the code.

- Updated set_message_retention_setting_dropdown such that
it can be used for stream message retention setting as well.
2022-11-22 17:14:35 -08:00
Sahil Batra 30f4e67aaa settings: Rename "org-subsection-parent" class to "settings-subsection-parent".
This commit renames the "org-subsection-parent" class used for
organization settings subsections to "settings-subsection-parent"
such that we can use same for the stream settings and avoid
duplicating code for handling save-discard widget which will be
added in future.
2022-11-22 17:14:35 -08:00
Sahil Batra e9316499cb settings_org: Pass subsection elem to get_subsection_property_elements.
We passed subsection elem to get_subsection_property_elements function
in all cases except the one when calling from discard button click
handler and we passed the input elem instead in that case.

This commit changes the code to pass subsection element directly
in the discard button click handler as well such that we can use
get_subsection_property_elements function for the stream settings
code and do not find the subsection element inside the function.
2022-11-22 17:14:35 -08:00
Sahil Batra 6ad8e276de settings: Refactor code for realm message retention setting.
This commit refactors the code for realm message retention
setting to make it more similar to code for other time-limit
realm settings. There are still separate functions for the
message retention setting but they are similar to that of
other time-limit settings and can probably help us to
deduplicate the code in future. This refactor also helps
us in reusing some code for stream message retention
setting for changes in #23013.

This commit also fixes a bug where save-discard widget
not being hidden when resetting the setting to original
value. This can only be reproduced when the original
setting value is "retain_forever".

Following changes have been done in this commit -

- Added data-setting-widget-type attribute which is set to
"message-retention-setting" similar to "time-limit" value for
message edit and delete limit settings.

- Added get_message_retention_setting_value function similar
to get_time_limit_setting_value function which is used by
get_input_element_value.

- Removed "message-retention" block from
get_complete_data_for_subsection and the message retention
setting is now added to request data in populate_data_for_request
itself using data-setting-widget-type attribute.

- Updated id and class of elements to support the above changes.
2022-11-10 16:13:49 -08:00
Tim Abbott a1aba2869b settings_org: Fix exception processing stream type events.
The previous check looked at whether the settings overlay as a whole
was open, not whether the specific panel we're going to update was
rendered.

The other code paths calling from server_events_dispatch into this
module already correctly check meta.loaded.
2022-11-02 11:43:07 -07:00
Anders Kaseorg 748ad53f83 dependencies: Remove formdata-node, node-fetch.
Node.js 18 has these built in.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-10-11 10:50:57 -07:00
Sahil Batra 009e06d868 settings: Extract a function to set msg edit and delete limit setting.
Since set_msg_edit_limit_dropdown and set_msg_delete_limit_dropdown
have almost same code except the ID of elements, we extract a common
function set_time_limit_setting and both the above functions call
this new function only.

We can use this function for topic edit limit setting which will be
added in further commits.
2022-09-23 16:24:16 -07:00
Sahil Batra 55cf61eaf3 settings: Do not show save-discard widget till custom input is not changed.
We now show save-discard widget on changing the message edit and delete
limit setting dropdown from any value to "Custom" only after value inside
the custom input is changed. This makes sense as the setting value is
not actually changed unless the custom input is not changed and also
makes the behavior consistent with realm-level default of notification
batching period setting.

After this change, the dropdown element and custom input element are not
considered as different setting elements for code purposes and are
treated as single setting like the realm-level default of notification
batching period setting. And thus we remove the prop-element class
from the custom input elements of these settings.
2022-09-23 16:24:16 -07:00
Sahil Batra 3fa7e68058 settings_config: Change time_limit_dropdown_values to a list.
This commit changes time_limit_dropdown_values from map to
list like we have email_notifications_batching_period_values.

This change will help us in further commits for refactoring
the message edit and delete settings related code.
2022-09-23 16:24:16 -07:00
Sahil Batra 17aba277c5 settings: Change id and name of message delete limit dropdown.
We change the id and name of message delete limit dropdown to
"id_realm_message_content_delete_limit_seconds" and
"realm_message_content_delete_limit_seconds" respectively.

This is a prep commit for sending only changed settings in
message editing section to the API.
2022-09-23 16:24:16 -07:00
Sahil Batra 1e9c65b759 settings: Change id and name of message edit limit dropdown.
We change the id and name of message edit limit dropdown to
"id_realm_message_content_edit_limit_seconds" and
"realm_message_content_edit_limit_seconds" respectively.

This is a prep commit for sending only changed settings in
message editing section to the API.
2022-09-23 16:24:16 -07:00
Sahil Batra b3b6449034 settings: Enable and disable the save button in change_save_button_state.
We now enable and disable save button when changing inputs for custom time
limit settings in change_save_button_state function only which shows or hide
the save-discard widget instead of handling them in "change" event handlers.

This fixes the bug of save button flashing to its enabled state from
disabled state before hiding after clicking on "Discard" as now button
is re-enabled only after save-discard widget is hidden and it is disabled
if required before being shown.

Note that there is still a bug for message edit and delete limit settings
where the save button flashes to enabled state when setting is changed to
the original value instead of clicking on "Discard". This bug is not present
for email notification batching setting in a follow-up PR.

This commit also renames update_save_button_state function to
enable_or_disable_save_button to avoid confusion with
change_save_button_state function.
2022-09-19 20:20:53 -07:00
Sahil Batra fa63045b49 settings: Rename dropdown value for custom option for msg limit settings.
This commit renames dropdown value for custom option for message edit
and delete limit settings to "custom_period" to make it consistent
with the value for email notification batching setting and thus
we can avoid code duplication in further commits.
2022-09-19 20:20:53 -07:00
Anders Kaseorg d4923a12e1 node_tests: Use a spec-compliant FormData implementation.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-08-18 08:53:55 -07:00
Sahil Batra 577abbd434 node_tests: Remove duplicated code in settings_org tests. 2022-08-12 18:09:53 -07:00
Sahil Batra 0c67c7d269 settings: Add checkbox for whether message editing is allowed or not.
This commit adds a checkbox for allow_message_editing setting and
thus we also remove the "Never" option from the time limit dropdown
as unchecking the newly added checkbox will mean the same.

We also disable the time limit input if message editing is not
allowed.

This commit also changes the label for time limit dropdown.

Fixes part of #21739.
2022-08-12 18:09:53 -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
Ganesh Pawar c6d636ef48 realm_domains_modal: Migrate modal to dialog_widget. 2022-07-07 14:56:45 -07:00
Anders Kaseorg 175dd999ac dropdown_list_widget: Separate setup method from constructor.
This refactoring is required so the next commit can reorder the
constructor.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-04-27 22:09:10 -07:00
Anders Kaseorg 7e94e3b370 node_tests: Mock classes with classes.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-04-27 14:36:00 -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
Anders Kaseorg 6aec27e646 js: Fix no-jquery/no-parse-html-literal.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-03-17 13:16:34 -07:00
Anders Kaseorg f84a2c08d5 js: Prefix jQuery object variable names with $.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2022-03-16 12:52:07 -07:00
NerdyLucifer c355feea0e dropdown_list_widget: Hide 'disable' button when nothing is selected.
Hides 'disable' button of any kind when nothing is selected
in dropdown list widgets  by removing ':enabled' selector from
the button, the button is not actually a button, it's an <a> tag which
doesn't support "disabled" attribute.

Fixes part of #20831.
2022-03-02 17:18:50 -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
Sahil Batra 25ba96488d settings: Add frontend part for create_web_public_stream_policy.
This commit has the following changes -

- Adds dropdown for changing create_web_public_stream_policy and this
dropdown is visible only if settings.WEB_PUBLIC_STREAMS_ENABLED and
enable_spectator_access is set to True. This dropdown is live-udpated
on changing enable_spectator_access setting.

- The web-public stream option in stream creation form and stream privacy
modal is hidden if one of settings.WEB_PUBLIC_STREAMS_ENABLED or
enable_spectator_access is set to False except in stream privacy modal
when the stream is already web-public so that the user is not confused by
none of the options being selected.

- We disable the web-public stream option in stream creation form and
in stream-privacy modals of stream which are not already web-public
when the user is not allowed to create web-public streams as per
create_web_public_stream_policy setting.

- We use on_show parameter to hide or disable the options in stream-privacy
modal because we use the visible property of element to remove the bottom
border from last element in the stream-privacy choices and thus we have
to wait for the modal to be visible.

Fixes #20287.  Fixes #20296.
2021-11-23 13:48:43 -08:00
Sahil Batra a7b14756ec settings_org: Use admin-realm-form class in save-discard click handlers.
We use 'admin-realm-form' class as selector in save-discard click
handlers instead of 'organization' which includes all the organization
settings sections, but save/discard widget is used only for some
sections and all of them are inside the form with class 'admin-realm-form'.

This will also help us to avoid code duplication when changing the realm
level defaults section to use save-discard widget.
2021-10-07 10:12:10 -07:00
Ganesh Pawar fa928d5cd1 streams: Split setting for stream creation policy.
Users wanted a feature where they could specify
which users can create public streams and which users can
create private streams.

This splits stream creation code into two parts,
public and private stream creation.

Fixes #17009.
2021-10-01 10:26:42 -07:00
sahil839 1e1f08fa4e settings: Add moderators and members option to msg-delete dropdown.
This commit adds moderators, full members and members options to
the delete_own_message_policy dropdown.
2021-09-30 14:59:31 -07:00
sahil839 909a3cde76 realm: Replace allow_message_deleting with delete_own_message_policy.
This commit replaces 'allow_message_deleting' boolean setting
with an integer setting 'delete_own_message_policy'. We have a
separate dropdown now for deciding which user-roles can delete
messages sent by themselves and the time-limit setting droddown
is different.

This new setting has two options - everyone and admins only. Other
options including moderators will be added further.

We also remove the "Never" option from the original time-limit
dropdown, as admins are always allowed to delete message. This
never option resembled the case of only admins being allowed to
delete but this state is now resembled by setting the dropdown
to "admins only" and we also disable the time-limit dropdown in
this case as admins are allowed to delete irrespective of limit.

Note, this setting is only for deleting messages sent by the
deleting user themselves, and only admins are allowed to delete
messages sent by others as before.
2021-09-30 14:59:31 -07:00
Sahil Batra c233ee9935 settings: Migrate twenty_four_hour_time setting to RealmUserDefault.
This commit removes the existing default_twenty_four_hour_time field in
Realm table which was used to set the twenty_four_hour_time setting of
new user on joining and instead we now use the twenty_four_hour_time
field of RealmUserDefault table for the same.

With some tweaks by tabbott to clarify the documentation.
2021-09-23 10:44:42 -07:00
Sahil Batra 1b5b7b8c2b settings: Specify moderators in dropdown options.
We change the label of various organization settings
to specify moderators.

Labels for 'admins only', 'admins and moderators'
and 'nobody' are still same.

The updated labels are -
- 'Admins, moderators and full members'
- 'Admins, moderators and members'
- 'Admins, moderators, members and guests'

These options will be replaced by user groups in
future but this is an intermediate fix.

Fixes #19562.
2021-09-10 14:29:32 -07:00
sahil839 b8854a9d92 settings: Add full members and moderators options in custom emoji setting. 2021-07-27 16:41:23 -07:00
sahil839 4b1313a92b models: Replace add_emoji_by_admins_only with add_custom_emoji_policy.
This commit replaces boolean field add_emoji_by_admins_only with an
integer field add_custom_emoji_policy as we would also add full members
and moderators option for this setting in further commits.
2021-07-27 16:41:22 -07:00
Anders Kaseorg ee8724e436 docs: Correct Big Blue Button to BigBlueButton.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-07-05 16:59:00 -07:00
sahil839 a537ecc587 settings: Fix live update of user-avatar upload widget.
We add disabled prop on buttons only and we add the css for
buttons (and some specific class elements) when disabled as
'cursor: not-allowed' or 'pointer-events: none' which means
the user cannot use these buttons when disabled.

This is not the case for the avatar widget as we use a div
element there and not button and neither those specific
classes which has appropriate styles defined.

We use the avatar image block in two ways - for showing image
and as a clickable target (which is actually a div element)
for uploading, so instead of adding 'disabled' prop we are
hiding (adding display: none) the div such that it is not
visible on hover and also cannot be clicked.
2021-06-30 15:00:51 +05:30
sahil839 e0fc6df2b4 settings: Fix live update of email change button.
This commit fixes a bug of not enabling/disabling
the email-change button when email_changes_disabled
setting is changed. Bug was because of using wrong
selector.
2021-06-28 22:14:55 -07:00
Steve Howell 5e824a6d6d node tests: Only expose mock_template via run_test.
We now only expose mock_template as a helper in run_test.

This has the following advantages:

    * less boilerplate at the top of the file
    * more surgical control with setting exercise_templates
    * no more "f" hack (or render_foo consts)
    * we force devs to explicitly mock the template

See frontend_tests/zjsunit for the substantive changes.

All the changes to the tests are very mechanical in nature.
2021-06-27 23:00:34 -04:00
sahil839 828759d2ba models: Replace allow_community_topic_editing with edit_topic_policy.
This commit replaces the allow_community_topic_editing boolean with
integer field edit_topic_policy and includes both frontend and
backend changes.

We also update settings_ui.disable_sub_settings_onchange to not
change the color of label as we did previously when the setting
was a checkbox. But now as the setting is dropdown we keep the
label as it is and we don't do anything with label when disabling
dropdowns. Also, this function was used only here so we can safely
change this.
2021-06-16 14:59:36 -07:00
Steve Howell d5c4495fa5 zjsunit: Wire $ to zjquery by default.
I introduce `mock_jquery` for modules that
want their own mock implementation.
2021-06-16 12:55:53 -04:00
Steve Howell 9e657dd795 node tests: Use {override} in run_test. 2021-06-16 12:55:53 -04:00
Abhijeet Prasad Bodas 30023d4b76 node tests: Use mock_template in settings_org. 2021-06-14 09:17:50 -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
Steve Howell 94ffef4de9 zjquery: Eliminate css() helper.
We use css() pretty rarely in our codebase, and
it can sometimes be used mistakenly, when a better
alternative is to toggle a class for external css.

It's hard to support the full API in zjquery, so
we just punt and tell folks to create their own
stubs.

Most of the existing tests that were "fixed" here
weren't actually verifying the behavior of the css()
calls, and for those I just create no-op stubs.

In a few places I verify that css() was called as
expected.
2021-06-04 20:08:19 -07:00
sahil839 d8c4b96b12 setting: Divide user_invite_restriction into a checkbox and dropdown.
This commit divides the user_invite_restriction setting dropdown to
a checkbox and a dropdown.
The checkbox is used for 'realm_invite_required' setting and dropdown
for 'realm_invite_to_realm_policy'.

This separation of UI elements is fine as these two settings are
separate in database also and also helps in removing excess if-else
conditions and switch cases.
2021-06-03 18:45:29 -07:00
sahil839 8846df6b53 node_tests: Deduplicate test_sync_realm_settings in settings_org tests.
There was a lot of duplicate code in test_sync_realm_settings where
each value in common_policy_values was being tested for different
policies (create_stream_policy and invite_to_stream_policy).

This commit deduplicates is by using a for-loop for testing all
common_policy values and extracting the code as a function to test
different policies.
2021-06-03 18:45:29 -07:00
Priyank Patel 2441138a7b settings_orgs: Use button element for save-discard button.
There is no clear reason to not use a button element here. According
to the spec pharasing content, which includes the <span> element,
are allowed in the button element.

Manually tested both buttons to make sure it works and made sure all
the selectors are updated by grepping all the selector classes/id in
the handlebars templates that are parents of the button or are
present on the button.

(One of the jQuery handler code got reformatted due to it fitting
the line limit due to one character deletion for the selector)
2021-06-03 12:41:10 -07:00