groups_controller.rb
2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
class Admin::GroupsController < Admin::ApplicationController
  before_filter :group, only: [:edit, :show, :update, :destroy, :project_update, :project_teams_update]
  def index
    @groups = Group.order('name ASC')
    @groups = @groups.search(params[:name]) if params[:name].present?
    @groups = @groups.page(params[:page]).per(20)
  end
  def show
    @projects = Project.scoped
    @projects = @projects.not_in_group(@group) if @group.projects.present?
    @projects = @projects.all
    @projects.reject!(&:empty_repo?)
    @users = User.active
  end
  def new
    @group = Group.new
  end
  def edit
  end
  def create
    @group = Group.new(params[:group])
    @group.path = @group.name.dup.parameterize if @group.name
    @group.owner = current_user
    if @group.save
      redirect_to [:admin, @group], notice: 'Group was successfully created.'
    else
      render action: "new"
    end
  end
  def update
    group_params = params[:group].dup
    owner_id =group_params.delete(:owner_id)
    if owner_id
      @group.owner = User.find(owner_id)
    end
    if @group.update_attributes(group_params)
      redirect_to [:admin, @group], notice: 'Group was successfully updated.'
    else
      render action: "edit"
    end
  end
  def project_update
    project_ids = params[:project_ids]
    Project.where(id: project_ids).each do |project|
      project.transfer(@group)
    end
    redirect_to :back, notice: 'Group was successfully updated.'
  end
  def remove_project
    @project = Project.find(params[:project_id])
    @project.transfer(nil)
    redirect_to :back, notice: 'Group was successfully updated.'
  end
  def project_teams_update
    @group.add_users_to_project_teams(params[:user_ids], params[:project_access])
    redirect_to [:admin, @group], notice: 'Users was successfully added.'
  end
  def destroy
    @group.truncate_teams
    @group.destroy
    redirect_to admin_groups_path, notice: 'Group was successfully deleted.'
  end
  private
  def group
    @group = Group.find_by_path(params[:id])
  end
end