Commit 552b3105fba11493d25575ee9220631a816141f6

Authored by Dmitriy Zaporozhets
1 parent 2b683b0d

Fixed admin area. Create project only from one place

app/controllers/admin/projects_controller.rb
1 1 class Admin::ProjectsController < AdminController
2   - before_filter :admin_project, only: [:edit, :show, :update, :destroy, :team_update]
  2 + before_filter :project, only: [:edit, :show, :update, :destroy, :team_update]
3 3  
4 4 def index
5   - @admin_projects = Project.scoped
6   - @admin_projects = @admin_projects.search(params[:name]) if params[:name].present?
7   - @admin_projects = @admin_projects.order("name ASC").page(params[:page]).per(20)
  5 + @projects = Project.scoped
  6 + @projects = @projects.search(params[:name]) if params[:name].present?
  7 + @projects = @projects.order("name ASC").page(params[:page]).per(20)
8 8 end
9 9  
10 10 def show
11 11 @users = User.scoped
12   - @users = @users.not_in_project(@admin_project) if @admin_project.users.present?
  12 + @users = @users.not_in_project(@project) if @project.users.present?
13 13 @users = @users.all
14 14 end
15 15  
16   - def new
17   - @admin_project = Project.new
18   - end
19   -
20 16 def edit
21 17 end
22 18  
23 19 def team_update
24   - @admin_project.add_users_ids_to_team(params[:user_ids], params[:project_access])
25   -
26   - redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
27   - end
28   -
29   - def create
30   - @admin_project = Project.new(params[:project])
31   - @admin_project.owner = current_user
  20 + @project.add_users_ids_to_team(params[:user_ids], params[:project_access])
32 21  
33   - if @admin_project.save
34   - redirect_to [:admin, @admin_project], notice: 'Project was successfully created.'
35   - else
36   - render action: "new"
37   - end
  22 + redirect_to [:admin, @project], notice: 'Project was successfully updated.'
38 23 end
39 24  
40 25 def update
41 26 owner_id = params[:project].delete(:owner_id)
42 27  
43 28 if owner_id
44   - @admin_project.owner = User.find(owner_id)
  29 + @project.owner = User.find(owner_id)
45 30 end
46 31  
47   - if @admin_project.update_attributes(params[:project])
48   - redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.'
  32 + if @project.update_attributes(params[:project], as: :admin)
  33 + redirect_to [:admin, @project], notice: 'Project was successfully updated.'
49 34 else
50 35 render action: "edit"
51 36 end
52 37 end
53 38  
54 39 def destroy
55   - @admin_project.destroy
56   -
57   - redirect_to admin_projects_url, notice: 'Project was successfully deleted.'
58   - end
59   -
60   - private
  40 + @project.destroy
61 41  
62   - def admin_project
63   - @admin_project = Project.find_by_code(params[:id])
  42 + redirect_to projects_url, notice: 'Project was successfully deleted.'
64 43 end
65 44 end
... ...
app/models/project.rb
... ... @@ -28,7 +28,10 @@ class Project &lt; ActiveRecord::Base
28 28 include Team
29 29  
30 30 attr_accessible :name, :path, :description, :code, :default_branch, :issues_enabled,
31   - :wall_enabled, :merge_requests_enabled, :wiki_enabled
  31 + :wall_enabled, :merge_requests_enabled, :wiki_enabled, as: [:default, :admin]
  32 +
  33 + attr_accessible :namespace_id, as: :admin
  34 +
32 35 attr_accessor :error_code
33 36  
34 37 # Relations
... ...
app/views/admin/projects/_form.html.haml
... ... @@ -11,16 +11,13 @@
11 11 .input
12 12 = f.text_field :name, placeholder: "Example Project", class: "xxlarge"
13 13  
14   - %hr
15   - .adv_settings
16   - %h6 Advanced settings:
  14 + %fieldset.adv_settings
  15 + %legend Advanced settings:
17 16 .clearfix
18 17 = f.label :path do
19 18 Path
20 19 .input
21   - .input-prepend
22   - %strong
23   - = text_field_tag :ppath, @admin_project.path_to_repo, class: "xlarge", disabled: true
  20 + = text_field_tag :ppath, @project.path_to_repo, class: "xlarge", disabled: true
24 21 .clearfix
25 22 = f.label :code do
26 23 URL
... ... @@ -31,6 +28,10 @@
31 28  
32 29 - unless project.new_record?
33 30 .clearfix
  31 + = f.label :namespace_id
  32 + .input= f.select :namespace_id, namespaces_options, {}, {class: 'chosen'}
  33 +
  34 + .clearfix
34 35 = f.label :owner_id
35 36 .input= f.select :owner_id, User.all.map { |user| [user.name, user.id] }, {}, {class: 'chosen'}
36 37  
... ... @@ -40,9 +41,8 @@
40 41 .input= f.select(:default_branch, project.heads.map(&:name), {}, style: "width:210px;")
41 42  
42 43 - unless project.new_record?
43   - %hr
44   - .adv_settings
45   - %h6 Features:
  44 + %fieldset.adv_settings
  45 + %legend Features:
46 46  
47 47 .clearfix
48 48 = f.label :issues_enabled, "Issues"
... ...
app/views/admin/projects/_new_form.html.haml
... ... @@ -1,29 +0,0 @@
1   -= form_for [:admin, @admin_project] do |f|
2   - - if @admin_project.errors.any?
3   - .alert-message.block-message.error
4   - %span= @admin_project.errors.full_messages.first
5   - .clearfix.project_name_holder
6   - = f.label :name do
7   - Project name is
8   - .input
9   - = f.text_field :name, placeholder: "Example Project", class: "xxlarge"
10   - = f.submit 'Create project', class: "btn primary project-submit"
11   -
12   - %hr
13   - %div.adv_settings
14   - %h6 Advanced settings:
15   - .clearfix
16   - = f.label :path do
17   - Git Clone
18   - .input
19   - .input-prepend
20   - %span.add-on= Gitlab.config.ssh_path
21   - = f.text_field :path, placeholder: "example_project", disabled: !@admin_project.new_record?
22   - %span.add-on= ".git"
23   - .clearfix
24   - = f.label :code do
25   - URL
26   - .input
27   - .input-prepend
28   - %span.add-on= web_app_url
29   - = f.text_field :code, placeholder: "example"
app/views/admin/projects/edit.html.haml
1   -%h3.page_title #{@admin_project.name} &rarr; Edit project
  1 +%h3.page_title #{@project.name} &rarr; Edit project
2 2 %hr
3   -= render 'form', project: @admin_project
  3 += render 'form', project: @project
... ...
app/views/admin/projects/index.html.haml
1 1 = render 'admin/shared/projects_head'
2 2 %h3.page_title
3 3 Projects
4   - = link_to 'New Project', new_admin_project_path, class: "btn small right"
  4 + = link_to 'New Project', new_project_path, class: "btn small right"
5 5 %br
6 6 = form_tag admin_projects_path, method: :get, class: 'form-inline' do
7 7 = text_field_tag :name, params[:name], class: "xlarge"
... ... @@ -16,7 +16,7 @@
16 16 %th Edit
17 17 %th.cred Danger Zone!
18 18  
19   - - @admin_projects.each do |project|
  19 + - @projects.each do |project|
20 20 %tr
21 21 %td= link_to project.name, [:admin, project]
22 22 %td= project.path
... ... @@ -24,4 +24,4 @@
24 24 %td= last_commit(project)
25 25 %td= link_to 'Edit', edit_admin_project_path(project), id: "edit_#{dom_id(project)}", class: "btn small"
26 26 %td.bgred= link_to 'Destroy', [:admin, project], confirm: "REMOVE #{project.name}? Are you sure?", method: :delete, class: "btn small danger"
27   -= paginate @admin_projects, theme: "admin"
  27 += paginate @projects, theme: "admin"
... ...
app/views/admin/projects/new.html.haml
... ... @@ -1,12 +0,0 @@
1   -.project_new_holder
2   - %h3.page_title
3   - New Project
4   - %hr
5   - = render 'new_form'
6   -%div.save-project-loader.hide
7   - %center
8   - = image_tag "ajax_loader.gif"
9   - %h3 Creating project &amp; repository. Please wait a few minutes
10   -
11   -:javascript
12   - $(function(){ new Projects(); });
app/views/admin/projects/show.html.haml
1 1 = render 'admin/shared/projects_head'
2 2 %h3.page_title
3   - Project: #{@admin_project.name}
4   - = link_to edit_admin_project_path(@admin_project), class: "btn right" do
  3 + Project: #{@project.name}
  4 + = link_to edit_admin_project_path(@project), class: "btn right" do
5 5 %i.icon-edit
6 6 Edit
7 7  
8   -- if !@admin_project.has_post_receive_file? && @admin_project.has_commits?
  8 +- if !@project.has_post_receive_file? && @project.has_commits?
9 9 %br
10 10 .alert.alert-error
11 11 %span
... ... @@ -25,36 +25,36 @@
25 25 %b
26 26 Name:
27 27 %td
28   - = @admin_project.name
  28 + = @project.name
29 29 %tr
30 30 %td
31 31 %b
32 32 Code:
33 33 %td
34   - = @admin_project.code
  34 + = @project.code
35 35 %tr
36 36 %td
37 37 %b
38 38 Path:
39 39 %td
40   - = @admin_project.path
  40 + %code= @project.path_to_repo
41 41 %tr
42 42 %td
43 43 %b
44 44 Owner:
45 45 %td
46   - = @admin_project.owner_name || '(deleted)'
  46 + = @project.owner_name || '(deleted)'
47 47 %tr
48 48 %td
49 49 %b
50 50 Post Receive File:
51 51 %td
52   - = check_box_tag :post_receive_file, 1, @admin_project.has_post_receive_file?, disabled: true
  52 + = check_box_tag :post_receive_file, 1, @project.has_post_receive_file?, disabled: true
53 53 %br
54 54 %h3
55 55 Team
56 56 %small
57   - (#{@admin_project.users_projects.count})
  57 + (#{@project.users_projects.count})
58 58 %br
59 59 %table.zebra-striped
60 60 %thead
... ... @@ -64,7 +64,7 @@
64 64 %th Repository Access
65 65 %th
66 66  
67   - - @admin_project.users_projects.each do |tm|
  67 + - @project.users_projects.each do |tm|
68 68 %tr
69 69 %td
70 70 = link_to tm.user_name, admin_user_path(tm.user)
... ... @@ -75,7 +75,7 @@
75 75 %br
76 76 %h3 Add new team member
77 77 %br
78   -= form_tag team_update_admin_project_path(@admin_project), class: "bulk_import", method: :put do
  78 += form_tag team_update_admin_project_path(@project), class: "bulk_import", method: :put do
79 79 %table.zebra-striped
80 80 %thead
81 81 %tr
... ...
config/routes.rb
... ... @@ -49,7 +49,7 @@ Gitlab::Application.routes.draw do
49 49 delete :remove_project
50 50 end
51 51 end
52   - resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ } do
  52 + resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, except: [:new, :create] do
53 53 member do
54 54 get :team
55 55 put :team_update
... ...