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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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>
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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)