projects_controller.rb 1.56 KB
Newer Older
1
class Admin::ProjectsController < AdminController
2
  before_filter :admin_project, only: [:edit, :show, :update, :destroy, :team_update]
gitlabhq's avatar
gitlabhq committed
3 4

  def index
randx's avatar
randx committed
5 6
    @admin_projects = Project.scoped
    @admin_projects = @admin_projects.search(params[:name]) if params[:name].present?
7
    @admin_projects = @admin_projects.page(params[:page]).per(20)
gitlabhq's avatar
gitlabhq committed
8 9 10
  end

  def show
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
11 12 13
    @users = User.scoped
    @users = @users.not_in_project(@admin_project) if @admin_project.users.present?
    @users = @users.all
gitlabhq's avatar
gitlabhq committed
14 15 16 17 18 19 20 21 22
  end

  def new
    @admin_project = Project.new
  end

  def edit
  end

23
  def team_update
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
24
    @admin_project.add_users_ids_to_team(params[:user_ids], params[:project_access])
25

26 27 28
    redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
  end

gitlabhq's avatar
gitlabhq committed
29 30
  def create
    @admin_project = Project.new(params[:project])
gitlabhq's avatar
gitlabhq committed
31
    @admin_project.owner = current_user
gitlabhq's avatar
gitlabhq committed
32

gitlabhq's avatar
gitlabhq committed
33 34 35
    if @admin_project.save
      redirect_to [:admin, @admin_project], notice: 'Project was successfully created.'
    else
36
      render action: "new"
gitlabhq's avatar
gitlabhq committed
37 38 39 40
    end
  end

  def update
41
    owner_id = params[:project].delete(:owner_id)
42

43
    if owner_id
44 45 46
      @admin_project.owner = User.find(owner_id)
    end

gitlabhq's avatar
gitlabhq committed
47 48 49
    if @admin_project.update_attributes(params[:project])
      redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
    else
50
      render action: "edit"
gitlabhq's avatar
gitlabhq committed
51 52 53 54 55 56
    end
  end

  def destroy
    @admin_project.destroy

57
    redirect_to admin_projects_url, notice: 'Project was successfully deleted.'
gitlabhq's avatar
gitlabhq committed
58
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
59

60
  private
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
61 62 63 64

  def admin_project
    @admin_project = Project.find_by_code(params[:id])
  end
gitlabhq's avatar
gitlabhq committed
65
end