-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinvitation_attempts_controller.rb
40 lines (34 loc) · 1.66 KB
/
invitation_attempts_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module UserListUploads
class InvitationAttemptsController < BaseController
before_action :set_user_list_upload, only: [:index, :select_rows, :create_many]
def select_rows
@user_collection = @user_list_upload.user_collection
@user_collection.sort_by!(**sort_params) if sort_params_valid?
@user_collection.search!(params[:search_query]) if params[:search_query].present?
@user_rows = @user_collection.user_rows_with_user_save_success
@all_user_rows_selected = @user_rows.all?(&:marked_for_invitation)
end
def create_many
@user_collection = @user_list_upload.user_collection
UserListUpload::InviteUsersJob.perform_later(@user_list_upload.id, invitation_formats)
redirect_to user_list_upload_invitation_attempts_path(user_list_upload_id: @user_list_upload.id)
end
def index
@user_collection = @user_list_upload.user_collection
@user_collection.sort_by!(**sort_params) if sort_params_valid?
@user_collection.search!(params[:search_query]) if params[:search_query].present?
@user_rows = @user_collection.user_rows_marked_for_invitation
@user_rows_with_invitation_errors = @user_collection.user_rows_with_invitation_errors
@user_rows_with_invitation_attempted = @user_collection.user_rows_with_invitation_attempted
@all_invitations_attempted = @user_rows_with_invitation_attempted.count == @user_rows.count
end
private
def set_user_list_upload
@user_list_upload = UserListUpload.find(params[:user_list_upload_id])
authorize @user_list_upload, :edit?
end
def invitation_formats
[params[:email], params[:sms]].compact.map(&:downcase)
end
end
end