Class: Organizations::InvitationsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Organizations::InvitationsController
- Defined in:
- app/controllers/organizations/invitations_controller.rb
Overview
Controller for managing organization invitations. Requires admin/invite_members permission for all actions.
Note: Public invitation routes (show/accept) are handled by PublicInvitationsController to avoid host app authentication filters.
Instance Method Summary collapse
-
#create ⇒ Object
POST /invitations Create a new invitation for the current organization.
-
#destroy ⇒ Object
DELETE /invitations/:id Revoke/delete an invitation.
-
#index ⇒ Object
GET /invitations List all invitations for the current organization.
-
#new ⇒ Object
GET /invitations/new Form to create a new invitation.
-
#resend ⇒ Object
POST /invitations/:id/resend Resend an invitation email.
Methods included from ControllerHelpers
#accept_pending_organization_invitation!, #clear_pending_organization_invitation!, #create_organization_and_switch!, #current_membership, #current_organization, #current_organization=, #handle_pending_invitation_acceptance_for, #no_organization_redirect_path, #organization_signed_in?, #pending_invitation_acceptance_redirect_path_for, #pending_organization_invitation, #pending_organization_invitation?, #pending_organization_invitation_email, #pending_organization_invitation_token, #redirect_path_after_invitation_accepted, #redirect_path_after_organization_switched, #redirect_path_when_invitation_requires_authentication, #redirect_path_when_no_organization, #redirect_to_no_organization!, #require_organization!, #require_organization_admin!, #require_organization_owner!, #require_organization_permission_to!, #require_organization_role!, #switch_to_organization!
Instance Method Details
#create ⇒ Object
POST /invitations Create a new invitation for the current organization
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/controllers/organizations/invitations_controller.rb', line 34 def create email = invitation_params[:email] role = invitation_params[:role] || ::Organizations.configuration.default_invitation_role begin @invitation = current_user.send_organization_invite_to!( email, organization: current_organization, role: role ) respond_to do |format| return_to = params[:return_to].presence || organization_invitations_path format.html { redirect_to return_to, notice: "Invitation sent to #{email}" } format.json { render json: invitation_json(@invitation), status: :created } end rescue ::Organizations::InvitationError, ActiveRecord::RecordInvalid, ArgumentError => e respond_to do |format| format.html do @invitation = current_organization.invitations.build(invitation_params) flash.now[:alert] = e. render :new, status: :unprocessable_entity end format.json { render json: { error: e. }, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /invitations/:id Revoke/delete an invitation
64 65 66 67 68 69 70 71 |
# File 'app/controllers/organizations/invitations_controller.rb', line 64 def destroy @invitation.destroy! respond_to do |format| format.html { redirect_back fallback_location: organization_invitations_path, notice: "Invitation revoked" } format.json { head :no_content } end end |
#index ⇒ Object
GET /invitations List all invitations for the current organization
16 17 18 19 20 21 22 23 |
# File 'app/controllers/organizations/invitations_controller.rb', line 16 def index @invitations = current_organization.invitations.includes(:invited_by).order(created_at: :desc) respond_to do |format| format.html format.json { render json: invitations_json(@invitations) } end end |
#new ⇒ Object
GET /invitations/new Form to create a new invitation
27 28 29 30 |
# File 'app/controllers/organizations/invitations_controller.rb', line 27 def new @invitation = current_organization.invitations.build @return_to = request.referer end |
#resend ⇒ Object
POST /invitations/:id/resend Resend an invitation email
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/organizations/invitations_controller.rb', line 75 def resend begin @invitation.resend! respond_to do |format| format.html { redirect_back fallback_location: organization_invitations_path, notice: "Invitation resent to #{@invitation.email}" } format.json { render json: invitation_json(@invitation) } end rescue ::Organizations::InvitationAlreadyAccepted => e respond_to do |format| format.html { redirect_back fallback_location: organization_invitations_path, alert: e. } format.json { render json: { error: e. }, status: :unprocessable_entity } end end end |