mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 11:13:22 +08:00
FEATURE: remove all expired invitations by default
This commit is contained in:
parent
caef0a56d1
commit
2c8e1d3578
|
@ -90,7 +90,6 @@ export default Ember.Controller.extend({
|
|||
Invite.rescindAll()
|
||||
.then(() => {
|
||||
this.set("rescindedAll", true);
|
||||
this.get("model.invites").clear();
|
||||
})
|
||||
.catch(popupAjaxError);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user