You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
822 B

  1. # frozen_string_literal: true
  2. class InvitesController < ApplicationController
  3. include Authorization
  4. layout 'admin'
  5. before_action :authenticate_user!
  6. def index
  7. authorize :invite, :create?
  8. @invites = invites
  9. @invite = Invite.new
  10. end
  11. def create
  12. authorize :invite, :create?
  13. @invite = Invite.new(resource_params)
  14. @invite.user = current_user
  15. if @invite.save
  16. redirect_to invites_path
  17. else
  18. @invites = invites
  19. render :index
  20. end
  21. end
  22. def destroy
  23. @invite = invites.find(params[:id])
  24. authorize @invite, :destroy?
  25. @invite.expire!
  26. redirect_to invites_path
  27. end
  28. private
  29. def invites
  30. Invite.where(user: current_user)
  31. end
  32. def resource_params
  33. params.require(:invite).permit(:max_uses, :expires_in, :autofollow)
  34. end
  35. end