Merge pull request #1488 from cfstras/removeAllowedUser

Allow removing users from private conversations
This commit is contained in:
Robin Ward 2013-10-03 08:02:41 -07:00
commit 578ef2098b
5 changed files with 30 additions and 3 deletions

View file

@ -476,8 +476,19 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
}, },
removeAllowedUser: function(username) { removeAllowedUser: function(username) {
this.get('details').removeAllowedUser(username); var self = this;
bootbox.dialog(I18n.t("private_message_info.remove_allowed_user", {name: username}), [
{label: I18n.t("no_value"),
'class': 'btn-danger rightg'},
{label: I18n.t("yes_value"),
'class': 'btn-primary',
callback: function() {
self.get('details').removeAllowedUser(username);
}
}
]);
} }
}); });

View file

@ -49,6 +49,15 @@ Discourse.TopicDetails = Discourse.Model.extend({
type: 'POST', type: 'POST',
data: { notification_level: v } data: { notification_level: v }
}); });
} },
removeAllowedUser: function(username) {
var users = this.get('allowed_users');
Discourse.ajax("/t/" + this.get('topic.id') + "/remove-allowed-user", {
type: 'PUT',
data: { username: username }
}).then(function(res) {
users.removeObject(users.findProperty('username', username));
});
}
}); });

View file

@ -382,7 +382,12 @@ class Topic < ActiveRecord::Base
def remove_allowed_user(username) def remove_allowed_user(username)
user = User.where(username: username).first user = User.where(username: username).first
if user if user
topic_allowed_users.where(user_id: user.id).first.destroy topic_user = topic_allowed_users.where(user_id: user.id).first
if topic_user
topic_user.destroy
else
false
end
end end
end end

View file

@ -373,6 +373,7 @@ de:
private_message_info: private_message_info:
title: "Privates Gespräch" title: "Privates Gespräch"
invite: "Andere einladen..." invite: "Andere einladen..."
remove_allowed_user: "Willst du {{name}} wirklich aus diesem Gespräch entfernen?"
email: 'Mail' email: 'Mail'
username: 'Benutzername' username: 'Benutzername'

View file

@ -372,6 +372,7 @@ en:
private_message_info: private_message_info:
title: "Private Message" title: "Private Message"
invite: "Invite Others..." invite: "Invite Others..."
remove_allowed_user: "Do you really want to remove {{name}} from this private message?"
email: 'Email' email: 'Email'
username: 'Username' username: 'Username'