FEATURE: remove all expired invitations by default

This commit is contained in:
Arpit Jalan 2019-03-07 15:19:46 +05:30
parent caef0a56d1
commit 2c8e1d3578
5 changed files with 17 additions and 12 deletions

View File

@ -90,7 +90,6 @@ export default Ember.Controller.extend({
Invite.rescindAll()
.then(() => {
this.set("rescindedAll", true);
this.get("model.invites").clear();
})
.catch(popupAjaxError);
}

View File

@ -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

View File

@ -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

View File

@ -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?"

View File

@ -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