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.

57 lines
1003 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. before_action :set_body_classes
  8. def index
  9. authorize :invite, :create?
  10. @invites = invites
  11. @invite = Invite.new
  12. end
  13. def create
  14. authorize :invite, :create?
  15. @invite = Invite.new(resource_params)
  16. @invite.user = current_user
  17. if @invite.save
  18. redirect_to invites_path
  19. else
  20. @invites = invites
  21. render :index
  22. end
  23. end
  24. def destroy
  25. @invite = invites.find(params[:id])
  26. authorize @invite, :destroy?
  27. @invite.expire!
  28. redirect_to invites_path
  29. end
  30. private
  31. def set_pack
  32. use_pack 'settings'
  33. end
  34. def invites
  35. Invite.where(user: current_user).order(id: :desc)
  36. end
  37. def resource_params
  38. params.require(:invite).permit(:max_uses, :expires_in, :autofollow)
  39. end
  40. def set_body_classes
  41. @body_classes = 'admin'
  42. end
  43. end