UX: warn about messages to be orphaned while deleting a group. (#11727)

Currently, after destroying a group its messages are inaccessible to everyone. Only admins can access using direct URLs.
This commit is contained in:
Vinoth Kannan 2021-01-22 03:29:34 +05:30 committed by GitHub
parent 5cbb522c41
commit 872f3e6934
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 4 deletions

View File

@ -142,13 +142,22 @@ export default Controller.extend({
destroyGroup() {
this.set("destroying", true);
const model = this.model;
let message = I18n.t("admin.groups.delete_confirm");
if (model.has_messages && model.message_count > 0) {
message = I18n.t("admin.groups.delete_with_messages_confirm", {
count: model.message_count,
});
}
bootbox.confirm(
I18n.t("admin.groups.delete_confirm"),
message,
I18n.t("no_value"),
I18n.t("yes_value"),
(confirmed) => {
if (confirmed) {
this.model
model
.destroy()
.then(() => this.transitionToRoute("groups.index"))
.catch((error) => {

View File

@ -261,6 +261,18 @@ acceptance("Group - Authenticated", function (needs) {
"Awesome Team",
"it should display the group name"
);
await click(".group-details-button button.btn-danger");
assert.equal(
queryAll(".bootbox .modal-body").html(),
I18n.t("admin.groups.delete_with_messages_confirm", {
count: 2,
}),
"it should warn about orphan messages"
);
await click(".modal-footer .btn-default");
});
test("Moderator Viewing Group", async function (assert) {

View File

@ -46,7 +46,9 @@ export default {
is_group_owner: true,
mentionable: true,
messageable: true,
can_see_members: true
can_see_members: true,
has_messages: true,
message_count: 2
},
extras: {
visible_group_names: ["discourse"]

View File

@ -838,6 +838,11 @@ class Group < ActiveRecord::Base
)
end
def message_count
return 0 unless self.has_messages
TopicAllowedGroup.where(group_id: self.id).joins(:topic).count
end
protected
def name_format_validator

View File

@ -25,7 +25,8 @@ class GroupShowSerializer < BasicGroupSerializer
:email_password,
:imap_last_error,
:imap_old_emails,
:imap_new_emails
:imap_new_emails,
:message_count
def self.admin_or_owner_attributes(*attrs)
attributes(*attrs)

View File

@ -3734,6 +3734,9 @@ en:
group_members: "Group members"
delete: "Delete"
delete_confirm: "Delete this group?"
delete_with_messages_confirm:
one: "Deleting this group will cause %{count} message to be orphaned, group members will no longer have access to it.<br><br>Are you sure?"
other: "Deleting this group will cause %{count} messages to be orphaned, group members will no longer have access to them.<br><br>Are you sure?"
delete_failed: "Unable to delete group. If this is an automatic group, it cannot be destroyed."
delete_owner_confirm: "Remove owner privilege for '%{username}'?"
add: "Add"

View File

@ -79,6 +79,7 @@ describe GroupShowSerializer do
it 'are visible' do
expect(subject.as_json[:email_username]).to eq('foo@bar.com')
expect(subject.as_json[:email_password]).to eq('pa$$w0rd')
expect(subject.as_json[:message_count]).to eq(0)
end
end
end