From b089805dc04659ba6f96b53dff8744862305697d Mon Sep 17 00:00:00 2001 From: Claus Strasburger Date: Tue, 1 Oct 2013 16:34:04 +0200 Subject: [PATCH 1/2] Added method removeAllowedUser to topic_details.js perform a request to /t/:id/remove-allowed-user, then delete the user from the local list --- .../discourse/controllers/topic_controller.js | 1 + .../javascripts/discourse/models/topic_details.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index e6a01bbe405..a68bb037c10 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -473,6 +473,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected removeAllowedUser: function(username) { this.get('details').removeAllowedUser(username); } + }); diff --git a/app/assets/javascripts/discourse/models/topic_details.js b/app/assets/javascripts/discourse/models/topic_details.js index a4f4858e913..59fe80302c8 100644 --- a/app/assets/javascripts/discourse/models/topic_details.js +++ b/app/assets/javascripts/discourse/models/topic_details.js @@ -49,6 +49,19 @@ Discourse.TopicDetails = Discourse.Model.extend({ type: 'POST', 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.forEach(function(user, i) { + if (user.username === username) { + users.removeAt(i); + } + }); + }); + } }); From 15a973fd451ab5d870ecacba08f8c02dd1ca41cd Mon Sep 17 00:00:00 2001 From: Claus Strasburger Date: Wed, 2 Oct 2013 19:11:48 +0200 Subject: [PATCH 2/2] Improved private message user removal, locale edit replaced array iteration with findProperty (will be renamed and aliased to findBy with Ember 1.1) added modal dialog to verify catched nil-error on topic.rb --- .../discourse/controllers/topic_controller.js | 12 +++++++++++- .../javascripts/discourse/models/topic_details.js | 6 +----- app/models/topic.rb | 7 ++++++- config/locales/client.de.yml | 1 + config/locales/client.en.yml | 1 + 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index a68bb037c10..f94607567fb 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -471,7 +471,17 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected }, 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); + } + } + ]); } }); diff --git a/app/assets/javascripts/discourse/models/topic_details.js b/app/assets/javascripts/discourse/models/topic_details.js index 59fe80302c8..40bb8859234 100644 --- a/app/assets/javascripts/discourse/models/topic_details.js +++ b/app/assets/javascripts/discourse/models/topic_details.js @@ -57,11 +57,7 @@ Discourse.TopicDetails = Discourse.Model.extend({ type: 'PUT', data: { username: username } }).then(function(res) { - users.forEach(function(user, i) { - if (user.username === username) { - users.removeAt(i); - } - }); + users.removeObject(users.findProperty('username', username)); }); } }); diff --git a/app/models/topic.rb b/app/models/topic.rb index 570fabf68be..33b3160e391 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -382,7 +382,12 @@ class Topic < ActiveRecord::Base def remove_allowed_user(username) user = User.where(username: username).first 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 diff --git a/config/locales/client.de.yml b/config/locales/client.de.yml index e08ee8b0989..4a6857f8ce4 100644 --- a/config/locales/client.de.yml +++ b/config/locales/client.de.yml @@ -373,6 +373,7 @@ de: private_message_info: title: "Privates Gespräch" invite: "Andere einladen..." + remove_allowed_user: "Willst du {{name}} wirklich aus diesem Gespräch entfernen?" email: 'Mail' username: 'Benutzername' diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index d1c22dec2c9..7891f01c090 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -372,6 +372,7 @@ en: private_message_info: title: "Private Message" invite: "Invite Others..." + remove_allowed_user: "Do you really want to remove {{name}} from this private message?" email: 'Email' username: 'Username'