users_groups_controller.rb 957 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
class UsersGroupsController < ApplicationController
  before_filter :group

  # Authorize
  before_filter :authorize_admin_group!

  layout 'group'

  def create
    @group.add_users(params[:user_ids].split(','), params[:group_access])

12
    redirect_to members_group_path(@group), notice: 'Users were successfully added.'
13
14
15
  end

  def update
16
17
    @member = @group.users_groups.find(params[:id])
    @member.update_attributes(params[:users_group])
18
19
20
21
  end

  def destroy
    @users_group = @group.users_groups.find(params[:id])
22
    @users_group.destroy
23
24

    respond_to do |format|
25
      format.html { redirect_to members_group_path(@group), notice: 'User was  successfully removed from group.' }
26
27
28
29
30
31
32
      format.js { render nothing: true }
    end
  end

  protected

  def group
skv's avatar
skv committed
33
    @group ||= Group.find_by(path: params[:group_id])
34
35
36
37
38
39
40
41
  end

  def authorize_admin_group!
    unless can?(current_user, :manage_group, group)
      return render_404
    end
  end
end