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

  def index
5
    @projects = Project.scoped
6
    @projects = @projects.where(namespace_id: params[:namespace_id]) if params[:namespace_id].present?
7
    @projects = @projects.where(public: true) if params[:public_only].present?
8
    @projects = @projects.where(namespace_id: nil) if params[:namespace_id] == Namespace.global_id
9
    @projects = @projects.search(params[:name]) if params[:name].present?
10
    @projects = @projects.includes(:namespace).order("namespaces.path, projects.name ASC").page(params[:page]).per(20)
gitlabhq's avatar
gitlabhq committed
11
12
13
  end

  def show
14
    @repository = @project.repository
15
    @users = User.active
16
    @users = @users.not_in_project(@project) if @project.users.present?
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
17
    @users = @users.all
gitlabhq's avatar
gitlabhq committed
18
19
20
21
22
  end

  def edit
  end

23
  def team_update
24
    @project.team.add_users_ids(params[:user_ids], params[:project_access])
gitlabhq's avatar
gitlabhq committed
25

26
    redirect_to [:admin, @project], notice: 'Project was successfully updated.'
gitlabhq's avatar
gitlabhq committed
27
28
29
  end

  def update
30
    status = ProjectUpdateContext.new(project, current_user, params).execute(:admin)
31

32
    if status
33
      redirect_to [:admin, @project], notice: 'Project was successfully updated.'
gitlabhq's avatar
gitlabhq committed
34
    else
35
      render action: "edit"
gitlabhq's avatar
gitlabhq committed
36
37
38
39
    end
  end

  def destroy
40
    # Delete team first in order to prevent multiple gitolite calls
41
    @project.team.truncate
42

43
    @project.destroy
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
44

Cyril Jouve's avatar
Cyril Jouve committed
45
    redirect_to admin_projects_path, notice: 'Project was successfully deleted.'
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
46
  end
47
48
49
50
51
52

  protected

  def project
    id = params[:project_id] || params[:id]

53
    @project = Project.find_with_namespace(id)
54
55
    @project || render_404
  end
gitlabhq's avatar
gitlabhq committed
56
end