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
911 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_pack
  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 set_pack
  31. use_pack 'settings'
  32. end
  33. def invites
  34. Invite.where(user: current_user).order(id: :desc)
  35. end
  36. def resource_params
  37. params.require(:invite).permit(:max_uses, :expires_in, :autofollow)
  38. end
  39. end