Module: Account::Invitations::ControllerBase
- Extended by:
- ActiveSupport::Concern
- Included in:
- Account::InvitationsController
- Defined in:
- app/controllers/concerns/account/invitations/controller_base.rb
Instance Method Summary collapse
-
#accept ⇒ Object
POST /invitations/1/accept POST /invitations/1/accept.json.
-
#create ⇒ Object
POST /invitations POST /invitations.json.
-
#destroy ⇒ Object
DELETE /invitations/1 DELETE /invitations/1.json.
-
#index ⇒ Object
GET /invitations GET /invitations.json.
-
#new ⇒ Object
GET /invitations/new.
-
#resend ⇒ Object
POST /invitations/1/resend.
-
#show ⇒ Object
GET /invitations/1 GET /invitations/1.json.
Instance Method Details
#accept ⇒ Object
POST /invitations/1/accept POST /invitations/1/accept.json
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/concerns/account/invitations/controller_base.rb', line 44 def accept # The user should be alerted when there is no # invitation regardless if they're registered or not. @invitation = Invitation.find_by(uuid: params[:id]) flash[:alert] = t("invitations.notifications.doesnt_exist") if @invitation.nil? # unless the user is signed in. if !current_user.present? # We need them to register. # We have to send `invitation_uuid` via params, not session, because Safari doesn't set cookies on redirect. redirect_to new_user_registration_path(invitation_uuid: @invitation&.uuid) # session[:invitation_uuid] should only be present if the user is registering for the first time. elsif (@invitation = Invitation.find_by(uuid: session[:invitation_uuid] || params[:id])) session.delete(:invitation_uuid) if session[:invitation_uuid].present? if @invitation @team = @invitation.team if @invitation.is_for?(current_user) || request.post? @invitation.accept_for(current_user) redirect_to account_dashboard_path, notice: I18n.t("invitations.notifications.welcome", team_name: @team.name) else redirect_to account_invitation_path(@invitation.uuid) end else redirect_to account_invitation_path(@invitation.uuid) end else redirect_to account_dashboard_path end end |
#create ⇒ Object
POST /invitations POST /invitations.json
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/controllers/concerns/account/invitations/controller_base.rb', line 95 def create @invitation.membership.team = current_team # this allows notifications to be sent to a user before they've accepted their invitation. @invitation.membership.user_email = @invitation.email @invitation.from_membership = current_membership respond_to do |format| if @invitation.save format.html { redirect_to account_team_invitations_path(@team), notice: I18n.t("invitations.notifications.created") } format.json { render :show, status: :created, location: [:account, @team, @invitation] } else format.html { render :new, status: :unprocessable_entity } format.json { render json: @invitation.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /invitations/1 DELETE /invitations/1.json
113 114 115 116 117 118 119 |
# File 'app/controllers/concerns/account/invitations/controller_base.rb', line 113 def destroy @invitation.destroy respond_to do |format| format.html { redirect_to account_team_invitations_path(@team), notice: I18n.t("invitations.notifications.destroyed") } format.json { head :no_content } end end |
#index ⇒ Object
GET /invitations GET /invitations.json
19 20 21 |
# File 'app/controllers/concerns/account/invitations/controller_base.rb', line 19 def index redirect_to [:account, @team, :memberships] end |
#new ⇒ Object
GET /invitations/new
88 89 90 91 |
# File 'app/controllers/concerns/account/invitations/controller_base.rb', line 88 def new @invitation.build_membership @cancel_path = only_allow_path(params[:cancel_path]) end |
#resend ⇒ Object
POST /invitations/1/resend
77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/concerns/account/invitations/controller_base.rb', line 77 def resend @invitation = Invitation.find_by(uuid: params[:id]) if @invitation&.touch UserMailer.invited(params[:id]).deliver_later redirect_to account_team_invitations_path(@invitation.membership.team), notice: I18n.t("invitations.notifications.resent") else redirect_to account_dashboard_path, alert: I18n.t("invitations.notifications.resent_error") end end |
#show ⇒ Object
GET /invitations/1 GET /invitations/1.json
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/concerns/account/invitations/controller_base.rb', line 25 def show # it's important that we only allow invitations to be shown via their uuid, # otherwise team members can just step the id in the url to claim an # invitation that would escalate their privileges. @invitation = Invitation.find_by(uuid: params[:id]) unless @invitation raise I18n.t("global.notifications.not_found") end @team = @invitation.team # backfill these objects for the locale magic, since we didn't use `account_load_and_authorize_resource`. @child_object = @invitation @parent_object = @team render layout: "devise" end |