Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

stream: Allow non-admins to create channel without subscribing to it.

Shubham Padia41c68fad2ca4
diff --git a/web/src/stream_create.ts b/web/src/stream_create.ts
index 7454ca64d0c..e1596962be8 100644
--- a/web/src/stream_create.ts
+++ b/web/src/stream_create.ts
@@ -12,7 +12,6 @@ import {$t, $t_html} from "./i18n.ts";
import * as keydown_util from "./keydown_util.ts";
import * as loading from "./loading.ts";
import * as onboarding_steps from "./onboarding_steps.ts";
-import * as people from "./people.ts";
import * as settings_components from "./settings_components.ts";
import * as settings_data from "./settings_data.ts";
import {current_user, realm} from "./state_data.ts";
@@ -84,16 +83,6 @@ class StreamSubscriptionError {
$("#stream_subscription_error").show();
}
- cant_create_stream_without_subscribing(): void {
- $("#stream_subscription_error").text(
- $t({
- defaultMessage:
- "You must be an organization administrator to create a channel without subscribing.",
- }),
- );
- $("#stream_subscription_error").show();
- }
-
clear_errors(): void {
$("#stream_subscription_error").hide();
}
@@ -596,11 +585,6 @@ export function set_up_handlers(): void {
return;
}
- if (!principals.includes(people.my_current_user_id()) && !current_user.is_admin) {
- stream_subscription_error.cant_create_stream_without_subscribing();
- return;
- }
-
if (principals.length >= 50) {
const html_body = render_subscription_invites_warning_modal({
channel_name: stream_name,
diff --git a/web/src/stream_create_subscribers.ts b/web/src/stream_create_subscribers.ts
index adeaa8af2ba..4790b7cb1aa 100644
--- a/web/src/stream_create_subscribers.ts
+++ b/web/src/stream_create_subscribers.ts
@@ -11,6 +11,7 @@ import {current_user} from "./state_data.ts";
import * as stream_create_subscribers_data from "./stream_create_subscribers_data.ts";
import type {CombinedPillContainer} from "./typeahead_helper.ts";
import * as user_groups from "./user_groups.ts";
+import * as user_pill from "./user_pill.ts";
import * as user_sort from "./user_sort.ts";
export let pill_widget: CombinedPillContainer;
@@ -113,7 +114,6 @@ export function build_widgets(): void {
user_id: user.user_id,
full_name: user.full_name,
is_current_user: user.user_id === current_user_id,
- disabled: stream_create_subscribers_data.must_be_subscribed(user.user_id),
img_src: people.small_avatar_url_for_person(user),
soft_removed: stream_create_subscribers_data.user_id_in_soft_remove_list(
user.user_id,
@@ -137,6 +137,8 @@ export function build_widgets(): void {
return $(`#${CSS.escape("user_checkbox_" + user.user_id)}`);
},
});
+ const current_person = people.get_by_user_id(current_user.user_id);
+ user_pill.append_user(current_person, pill_widget);
}
export function add_user_id_to_new_stream(user_id: number): void {
diff --git a/web/src/stream_create_subscribers_data.ts b/web/src/stream_create_subscribers_data.ts
index b0d701140f3..ace39b034ac 100644
--- a/web/src/stream_create_subscribers_data.ts
+++ b/web/src/stream_create_subscribers_data.ts
@@ -35,11 +35,6 @@ export function get_potential_subscribers(): User[] {
const potential_subscribers = people.get_realm_users();
return potential_subscribers.filter((user) => !user_id_set.has(user.user_id));
}
-
-export function must_be_subscribed(user_id: number): boolean {
- return !current_user.is_admin && user_id === current_user.user_id;
-}
-
export function add_user_ids(user_ids: number[]): void {
for (const user_id of user_ids) {
if (!user_id_set.has(user_id)) {
@@ -62,12 +57,6 @@ export function remove_user_ids(user_ids: number[]): void {
}
export function sync_user_ids(user_ids: number[]): void {
- // Current user does not have their pill in their input
- // box, so we need to make sure that we don't delete
- // it unnecessarily while syncing.
- if (user_id_set.has(current_user.user_id)) {
- user_ids.push(current_user.user_id);
- }
user_id_set = new Set(user_ids);
}
diff --git a/web/templates/stream_settings/new_stream_user.hbs b/web/templates/stream_settings/new_stream_user.hbs
index 695104b3dc0..7b222e022aa 100644
--- a/web/templates/stream_settings/new_stream_user.hbs
+++ b/web/templates/stream_settings/new_stream_user.hbs
@@ -11,7 +11,7 @@
{{#if soft_removed}}
<button data-user-id="{{user_id}}" class="undo_soft_removed_potential_subscriber button small rounded white">{{t 'Add' }}</button>
{{else}}
- <button {{#if disabled}} disabled="disabled"{{/if}} data-user-id="{{user_id}}" class="remove_potential_subscriber button small rounded white">{{t 'Remove' }}</button>
+ <button data-user-id="{{user_id}}" class="remove_potential_subscriber button small rounded white">{{t 'Remove' }}</button>
{{/if}}
</td>
</tr>
diff --git a/web/tests/stream_create_subscribers_data.test.cjs b/web/tests/stream_create_subscribers_data.test.cjs
index 756b6ed1f58..da0bf168706 100644
--- a/web/tests/stream_create_subscribers_data.test.cjs
+++ b/web/tests/stream_create_subscribers_data.test.cjs
@@ -68,33 +68,11 @@ test("basics", () => {
test_user101,
test_user103,
]);
-
- assert.ok(stream_create_subscribers_data.must_be_subscribed(me.user_id));
- assert.ok(!stream_create_subscribers_data.must_be_subscribed(test_user101.user_id));
-});
-
-test("must_be_subscribed", ({override}) => {
- override(current_user, "is_admin", false);
- assert.ok(stream_create_subscribers_data.must_be_subscribed(me.user_id));
- assert.ok(!stream_create_subscribers_data.must_be_subscribed(test_user101.user_id));
- override(current_user, "is_admin", true);
- assert.ok(!stream_create_subscribers_data.must_be_subscribed(me.user_id));
- assert.ok(!stream_create_subscribers_data.must_be_subscribed(test_user101.user_id));
});
test("sync_user_ids", () => {
- // sync_user_ids should not remove current user if already present.
stream_create_subscribers_data.initialize_with_current_user();
stream_create_subscribers_data.sync_user_ids([test_user101.user_id, test_user102.user_id]);
- assert.deepEqual(stream_create_subscribers_data.sorted_user_ids(), [
- me.user_id,
- test_user101.user_id,
- test_user102.user_id,
- ]);
-
- // sync_user_ids should not add current user if already not present.
- stream_create_subscribers_data.remove_user_ids([me.user_id]);
- stream_create_subscribers_data.sync_user_ids([test_user101.user_id, test_user102.user_id]);
assert.deepEqual(stream_create_subscribers_data.sorted_user_ids(), [
test_user101.user_id,
test_user102.user_id,