BigW Consortium Gitlab

projects_controller.rb 1.79 KB
Newer Older
gitlabhq committed
1
class Admin::ProjectsController < ApplicationController
gitlabhq committed
2
  layout "admin"
gitlabhq committed
3 4 5 6
  before_filter :authenticate_user!
  before_filter :authenticate_admin!

  def index
randx committed
7 8 9
    @admin_projects = Project.scoped
    @admin_projects = @admin_projects.search(params[:name]) if params[:name].present?
    @admin_projects = @admin_projects.page(params[:page])
gitlabhq committed
10 11 12 13
  end

  def show
    @admin_project = Project.find_by_code(params[:id])
14 15 16 17 18 19

    @users = if @admin_project.users.empty?
               User
             else
               User.not_in_project(@admin_project)
             end.all
gitlabhq committed
20 21 22 23 24 25 26 27 28 29
  end

  def new
    @admin_project = Project.new
  end

  def edit
    @admin_project = Project.find_by_code(params[:id])
  end

30 31 32 33 34 35
  def team_update
    @admin_project = Project.find_by_code(params[:id])

    UsersProject.bulk_import(
      @admin_project, 
      params[:user_ids],
36
      params[:project_access]
37 38
    )

39 40
    @admin_project.update_repository

41 42 43
    redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
  end

gitlabhq committed
44 45
  def create
    @admin_project = Project.new(params[:project])
gitlabhq committed
46
    @admin_project.owner = current_user
gitlabhq committed
47

gitlabhq committed
48 49 50 51
    if @admin_project.save
      redirect_to [:admin, @admin_project], notice: 'Project was successfully created.'
    else
      render :action => "new"
gitlabhq committed
52 53 54 55 56 57
    end
  end

  def update
    @admin_project = Project.find_by_code(params[:id])

58
    owner_id = params[:project].delete(:owner_id)
59 60 61 62 63

    if owner_id 
      @admin_project.owner = User.find(owner_id)
    end

gitlabhq committed
64 65 66 67
    if @admin_project.update_attributes(params[:project])
      redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
    else
      render :action => "edit"
gitlabhq committed
68 69 70 71 72 73 74
    end
  end

  def destroy
    @admin_project = Project.find_by_code(params[:id])
    @admin_project.destroy

gitlabhq committed
75
    redirect_to admin_projects_url
gitlabhq committed
76 77
  end
end