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.

52 lines
931 B

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