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:
parent
5cbb522c41
commit
872f3e6934
|
@ -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) => {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue