Skip to content

Commit

Permalink
FEATURE: Resend all pending invitations
Browse files Browse the repository at this point in the history
  • Loading branch information
arpitjalan committed Jun 3, 2016
1 parent a3d72ef commit c4e1ad0
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
Expand Up @@ -10,6 +10,7 @@ export default Ember.Controller.extend({
invitesCount: null,
canLoadMore: true,
invitesLoading: false,
reinvitedAll: false,

init: function() {
this._super();
Expand All @@ -32,6 +33,10 @@ export default Ember.Controller.extend({

inviteRedeemed: Em.computed.equal('filter', 'redeemed'),

showReinviteAllButton: function() {
return (this.get('filter') === "pending" && this.get('model').invites.length > 4);
}.property('filter'),

/**
Can the currently logged in user invite users to the site
Expand Down Expand Up @@ -87,6 +92,13 @@ export default Ember.Controller.extend({
return false;
},

reinviteAll() {
const self = this;
Invite.reinviteAll().then(function() {
self.set('reinvitedAll', true);
});
},

loadMore() {
var self = this;
var model = self.get('model');
Expand Down
4 changes: 4 additions & 0 deletions app/assets/javascripts/discourse/models/invite.js.es6
Expand Up @@ -48,6 +48,10 @@ Invite.reopenClass({
findInvitedCount(user) {
if (!user) { return Em.RSVP.resolve(); }
return Discourse.ajax("/users/" + user.get('username_lower') + "/invited_count.json").then(result => Em.Object.create(result.counts));
},

reinviteAll() {
return Discourse.ajax('/invites/reinvite-all', { type: 'POST' });
}

});
Expand Down
Expand Up @@ -17,6 +17,13 @@
{{#if canBulkInvite}}
{{resumable-upload target="/invites/upload" success="uploadSuccess" error="uploadError" uploadText=uploadText}}
{{/if}}
{{#if showReinviteAllButton}}
{{#if reinvitedAll}}
{{i18n 'user.invited.reinvited_all'}}
{{else}}
{{d-button icon="refresh" action="reinviteAll" class="btn" label="user.invited.reinvite_all"}}
{{/if}}
{{/if}}
</div>
</div>
{{/if}}
Expand Down
9 changes: 8 additions & 1 deletion app/controllers/invites_controller.rb
Expand Up @@ -4,7 +4,7 @@ class InvitesController < ApplicationController
skip_before_filter :check_xhr, :preload_json
skip_before_filter :redirect_to_login_if_required

before_filter :ensure_logged_in, only: [:destroy, :create, :create_invite_link, :resend_invite, :check_csv_chunk, :upload_csv_chunk]
before_filter :ensure_logged_in, only: [:destroy, :create, :create_invite_link, :resend_invite, :resend_all_invites, :check_csv_chunk, :upload_csv_chunk]
before_filter :ensure_new_registrations_allowed, only: [:show, :redeem_disposable_invite]
before_filter :ensure_not_logged_in, only: [:show, :redeem_disposable_invite]

Expand Down Expand Up @@ -135,6 +135,13 @@ def resend_invite
render nothing: true
end

def resend_all_invites
guardian.ensure_can_invite_to_forum!

Invite.resend_all_invites_from(current_user.id)
render nothing: true
end

def check_csv_chunk
guardian.ensure_can_bulk_invite_to_forum!(current_user)

Expand Down
6 changes: 6 additions & 0 deletions app/models/invite.rb
Expand Up @@ -233,6 +233,12 @@ def resend_invite
Jobs.enqueue(:invite_email, invite_id: self.id)
end

def self.resend_all_invites_from(user_id)
Invite.where('invites.user_id IS NULL AND invites.email IS NOT NULL AND invited_by_id = ?', user_id).find_each do |invite|
invite.resend_invite unless invite.blank?
end
end

def limit_invites_per_day
RateLimiter.new(invited_by, "invites-per-day", SiteSetting.max_invites_per_day, 1.day.to_i)
end
Expand Down
2 changes: 2 additions & 0 deletions config/locales/client.en.yml
Expand Up @@ -723,7 +723,9 @@ en:
rescind: "Remove"
rescinded: "Invite removed"
reinvite: "Resend Invite"
reinvite_all: "Resend all Invites"
reinvited: "Invite re-sent"
reinvited_all: "All Invites re-sent!"
time_read: "Read Time"
days_visited: "Days Visited"
account_age_days: "Account age in days"
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -580,6 +580,7 @@
end
end
post "invites/reinvite" => "invites#resend_invite"
post "invites/reinvite-all" => "invites#resend_all_invites"
post "invites/link" => "invites#create_invite_link"
post "invites/disposable" => "invites#create_disposable_invite"
get "invites/redeem/:token" => "invites#redeem_disposable_invite"
Expand Down

0 comments on commit c4e1ad0

Please sign in to comment.