Class: SimpleTeams::InvitationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/simple_teams/invitations_controller.rb,
app/controllers/simple_teams/admin/invitations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /invitations



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/simple_teams/admin/invitations_controller.rb', line 24

def create
  authorize! :create, @team.invitations.new
  @service_object = SimpleTeams::InvitationForms::CreateCombo.new(@team, current_user)

  respond_to do |format|
    if @service_object.perform(new_service_object_params)
      format.html { redirect_to team_path(@team), notice: "Invitations were successfully created." }
      format.json { render :show, status: :created, location: @invitation }
    else
      format.html { render :new, status: :unprocessable_entity }
      format.json { render json: @invitation.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /invitations/1



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/simple_teams/admin/invitations_controller.rb', line 44

def destroy
  authorize! :destroy, @invitation
  invitation_id = @invitation.id
  invitation_email = @invitation.email
  @invitation.destroy

  SimpleTeams::Invitations::DestroyedNotification.with(
    :team_id => @team.id,
    :invitation_id => invitation_id,
    :user_id => current_user.id,
    :team_name => @team.name,
    :invitation_name => invitation_email,
    :user_name => current_user.full_name
  ).deliver_later(@team.members)

  respond_to do |format|
    format.html { redirect_to team_path(@team), notice: "Invitation was successfully destroyed." }
    format.json { head :no_content }
  end
end

#editObject

GET /invitations/1/edit



20
21
22
23
# File 'app/controllers/simple_teams/admin/invitations_controller.rb', line 20

def edit
  authorize! :update, @invitation
  @service_object = SimpleTeams::InvitationForms::Update.new(@invitation, current_user)
end

#indexObject

GET /invitations



6
7
8
# File 'app/controllers/simple_teams/admin/invitations_controller.rb', line 6

def index
  @invitations = Invitation.all
end

#newObject

GET /invitations/new



15
16
17
18
# File 'app/controllers/simple_teams/admin/invitations_controller.rb', line 15

def new
  authorize! :create, @team.invitations.new
  @service_object = SimpleTeams::InvitationForms::CreateCombo.new(@team, current_user)
end

#resendObject



47
48
49
50
51
52
53
54
55
# File 'app/controllers/simple_teams/invitations_controller.rb', line 47

def resend
  authorize! :update, @invitation
  @invitation.resend_invitation_notification

  respond_to do |format|
    format.html { redirect_to team_path(@team), notice: "Invitation was successfully resent." }
    format.json { head :no_content }
  end
end

#showObject

GET /invitations/1



11
12
# File 'app/controllers/simple_teams/admin/invitations_controller.rb', line 11

def show
end

#updateObject

PATCH/PUT /invitations/1



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/simple_teams/admin/invitations_controller.rb', line 35

def update
  authorize! :update, @invitation
  @service_object = SimpleTeams::InvitationForms::Update.new(@invitation, current_user)

  respond_to do |format|
    if @service_object.perform(service_object_params)
      format.html { redirect_to team_path(@team), notice: "Invitation was successfully updated." }
      format.json { head :no_content }
    else
      format.html { render :edit, status: :unprocessable_entity }
      format.json { render json: @invitation.errors, status: :unprocessable_entity }
    end
  end

end