Class: SimpleTeams::MembershipsController

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

Instance Method Summary collapse

Instance Method Details

#createObject

POST /memberships



24
25
26
27
28
29
30
31
32
# File 'app/controllers/simple_teams/admin/memberships_controller.rb', line 24

def create
  @membership = Membership.new(membership_params)

  if @membership.save
    redirect_to @membership, notice: "Membership was successfully created."
  else
    render :new, status: :unprocessable_entity
  end
end

#destroyObject

DELETE /memberships/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/memberships_controller.rb', line 44

def destroy
  authorize! :destroy, @membership

  member_id = @membership.member.id
  member_name = @membership.member.full_name
  recipients = @team.members.to_a

  @membership.destroy

  SimpleTeams::Memberships::DestroyedNotification.with(
    :team_id => @team.id,
    :member_id => member_id,
    :user_id => current_user.id,
    :team_name => @team.name,
    :member_name => member_name,
    :user_name => current_user.full_name
  ).deliver_later(recipients)

  redirect_to team_path(@team)
end

#editObject

GET /memberships/1/edit



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

def edit
  authorize! :edit, @membership
  @service_object = SimpleTeams::MembershipForm.new(@membership, current_user)
end

#indexObject

GET /memberships



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

def index
  @memberships = Membership.all
end

#newObject

GET /memberships/new



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

def new
  @membership = Membership.new
end

#showObject

GET /memberships/1



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

def show
end

#updateObject

PATCH/PUT /memberships/1



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

def update
  authorize! :edit, @membership
  @service_object = SimpleTeams::MembershipForm.new(@membership, current_user)

  respond_to do |format|
    if @service_object.perform(service_object_params)
      format.html { redirect_to team_path(@team), notice: "Membership was updated successfully." }
      format.json { render :show, status: :created, location: @service_object.membership }
    else
      format.html { render :edit, status: :unprocessable_entity }
      format.json { render json: @service_object.errors, status: :unprocessable_entity }
    end
  end
end