FEATURE: remove all expired invitations by default

FEATURE: remove all expired invitations by default

diff --git a/app/assets/javascripts/discourse/controllers/user-invited-show.js.es6 b/app/assets/javascripts/discourse/controllers/user-invited-show.js.es6
index a157abe..1bb292b 100644
--- a/app/assets/javascripts/discourse/controllers/user-invited-show.js.es6
+++ b/app/assets/javascripts/discourse/controllers/user-invited-show.js.es6
@@ -90,7 +90,6 @@ export default Ember.Controller.extend({
           Invite.rescindAll()
             .then(() => {
               this.set("rescindedAll", true);
-              this.get("model.invites").clear();
             })
             .catch(popupAjaxError);
         }
diff --git a/app/controllers/invites_controller.rb b/app/controllers/invites_controller.rb
index 884f67e..30e06c2 100644
--- a/app/controllers/invites_controller.rb
+++ b/app/controllers/invites_controller.rb
@@ -143,7 +143,7 @@ class InvitesController < ApplicationController
   def rescind_all_invites
     guardian.ensure_can_rescind_all_invites!(current_user)
 
-    Invite.rescind_all_invites_from(current_user)
+    Invite.rescind_all_expired_invites_from(current_user)
     render body: nil
   end
 
diff --git a/app/models/invite.rb b/app/models/invite.rb
index b201240..6e02242 100644
--- a/app/models/invite.rb
+++ b/app/models/invite.rb
@@ -226,8 +226,9 @@ class Invite < ActiveRecord::Base
     end
   end
 
-  def self.rescind_all_invites_from(user)
-    Invite.where('invites.user_id IS NULL AND invites.email IS NOT NULL AND invited_by_id = ?', user.id).find_each do |invite|
+  def self.rescind_all_expired_invites_from(user)
+    Invite.where('invites.user_id IS NULL AND invites.email IS NOT NULL AND invited_by_id = ? AND invites.created_at < ?',
+                user.id, SiteSetting.invite_expiry_days.days.ago).find_each do |invite|
       invite.trash!(user)
     end
   end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index 5ae7ddc..3ee598c 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -1000,9 +1000,9 @@ en:
         expired: "This invite has expired."
         rescind: "Remove"
         rescinded: "Invite removed"
-        rescind_all: "Remove all Invites"
-        rescinded_all: "All Invites removed!"
-        rescind_all_confirm: "Are you sure you want to remove all invites?"
+        rescind_all: "Remove all Expired Invites"
+        rescinded_all: "All Expired Invites removed!"
+        rescind_all_confirm: "Are you sure you want to remove all expired invites?"
         reinvite: "Resend Invite"
         reinvite_all: "Resend all Invites"
         reinvite_all_confirm: "Are you sure you want to resend all invites?"
diff --git a/spec/models/invite_spec.rb b/spec/models/invite_spec.rb
index 15ebea3..bdf7a02 100644
--- a/spec/models/invite_spec.rb
+++ b/spec/models/invite_spec.rb
@@ -477,16 +477,21 @@ describe Invite do
 
   end
 
-  describe '.rescind_all_invites_from' do
-    it 'removes all invites sent by a user' do
+  describe '.rescind_all_expired_invites_from' do
+    it 'removes all expired invites sent by a user' do
+      SiteSetting.invite_expiry_days = 1
       user = Fabricate(:user)
       invite_1 = Fabricate(:invite, invited_by: user)
       invite_2 = Fabricate(:invite, invited_by: user)
-      Invite.rescind_all_invites_from(user)
+      expired_invite = Fabricate(:invite, invited_by: user)
+      expired_invite.update!(created_at: 2.days.ago)
+      Invite.rescind_all_expired_invites_from(user)
       invite_1.reload
       invite_2.reload
-      expect(invite_1.deleted_at).to be_present
-      expect(invite_2.deleted_at).to be_present
+      expired_invite.reload
+      expect(invite_1.deleted_at).to eq(nil)
+      expect(invite_2.deleted_at).to eq(nil)
+      expect(expired_invite.deleted_at).to be_present
     end
   end
 end

GitHub sha: 2c8e1d35

This commit has been mentioned on Discourse Meta. There might be relevant details there: