闭社主体 forked from https://github.com/tootsuite/mastodon
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.

43 lines
850 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 = Invite.where(user: current_user)
  9. @invite = Invite.new(expires_in: 1.day.to_i)
  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 = Invite.where(user: current_user)
  19. render :index
  20. end
  21. end
  22. def destroy
  23. @invite = Invite.where(user: current_user).find(params[:id])
  24. authorize @invite, :destroy?
  25. @invite.expire!
  26. redirect_to invites_path
  27. end
  28. private
  29. def resource_params
  30. params.require(:invite).permit(:max_uses, :expires_in)
  31. end
  32. end