Commit 552b3105fba11493d25575ee9220631a816141f6
1 parent
2b683b0d
Exists in
master
and in
4 other branches
Fixed admin area. Create project only from one place
Showing
9 changed files
with
42 additions
and
101 deletions
Show diff stats
app/controllers/admin/projects_controller.rb
1 | class Admin::ProjectsController < AdminController | 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 | def index | 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 | end | 8 | end |
9 | 9 | ||
10 | def show | 10 | def show |
11 | @users = User.scoped | 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 | @users = @users.all | 13 | @users = @users.all |
14 | end | 14 | end |
15 | 15 | ||
16 | - def new | ||
17 | - @admin_project = Project.new | ||
18 | - end | ||
19 | - | ||
20 | def edit | 16 | def edit |
21 | end | 17 | end |
22 | 18 | ||
23 | def team_update | 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 | end | 23 | end |
39 | 24 | ||
40 | def update | 25 | def update |
41 | owner_id = params[:project].delete(:owner_id) | 26 | owner_id = params[:project].delete(:owner_id) |
42 | 27 | ||
43 | if owner_id | 28 | if owner_id |
44 | - @admin_project.owner = User.find(owner_id) | 29 | + @project.owner = User.find(owner_id) |
45 | end | 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 | else | 34 | else |
50 | render action: "edit" | 35 | render action: "edit" |
51 | end | 36 | end |
52 | end | 37 | end |
53 | 38 | ||
54 | def destroy | 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 | end | 43 | end |
65 | end | 44 | end |
app/models/project.rb
@@ -28,7 +28,10 @@ class Project < ActiveRecord::Base | @@ -28,7 +28,10 @@ class Project < ActiveRecord::Base | ||
28 | include Team | 28 | include Team |
29 | 29 | ||
30 | attr_accessible :name, :path, :description, :code, :default_branch, :issues_enabled, | 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 | attr_accessor :error_code | 35 | attr_accessor :error_code |
33 | 36 | ||
34 | # Relations | 37 | # Relations |
app/views/admin/projects/_form.html.haml
@@ -11,16 +11,13 @@ | @@ -11,16 +11,13 @@ | ||
11 | .input | 11 | .input |
12 | = f.text_field :name, placeholder: "Example Project", class: "xxlarge" | 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 | .clearfix | 16 | .clearfix |
18 | = f.label :path do | 17 | = f.label :path do |
19 | Path | 18 | Path |
20 | .input | 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 | .clearfix | 21 | .clearfix |
25 | = f.label :code do | 22 | = f.label :code do |
26 | URL | 23 | URL |
@@ -31,6 +28,10 @@ | @@ -31,6 +28,10 @@ | ||
31 | 28 | ||
32 | - unless project.new_record? | 29 | - unless project.new_record? |
33 | .clearfix | 30 | .clearfix |
31 | + = f.label :namespace_id | ||
32 | + .input= f.select :namespace_id, namespaces_options, {}, {class: 'chosen'} | ||
33 | + | ||
34 | + .clearfix | ||
34 | = f.label :owner_id | 35 | = f.label :owner_id |
35 | .input= f.select :owner_id, User.all.map { |user| [user.name, user.id] }, {}, {class: 'chosen'} | 36 | .input= f.select :owner_id, User.all.map { |user| [user.name, user.id] }, {}, {class: 'chosen'} |
36 | 37 | ||
@@ -40,9 +41,8 @@ | @@ -40,9 +41,8 @@ | ||
40 | .input= f.select(:default_branch, project.heads.map(&:name), {}, style: "width:210px;") | 41 | .input= f.select(:default_branch, project.heads.map(&:name), {}, style: "width:210px;") |
41 | 42 | ||
42 | - unless project.new_record? | 43 | - unless project.new_record? |
43 | - %hr | ||
44 | - .adv_settings | ||
45 | - %h6 Features: | 44 | + %fieldset.adv_settings |
45 | + %legend Features: | ||
46 | 46 | ||
47 | .clearfix | 47 | .clearfix |
48 | = f.label :issues_enabled, "Issues" | 48 | = f.label :issues_enabled, "Issues" |
app/views/admin/projects/_new_form.html.haml
@@ -1,29 +0,0 @@ | @@ -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
app/views/admin/projects/index.html.haml
1 | = render 'admin/shared/projects_head' | 1 | = render 'admin/shared/projects_head' |
2 | %h3.page_title | 2 | %h3.page_title |
3 | Projects | 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 | %br | 5 | %br |
6 | = form_tag admin_projects_path, method: :get, class: 'form-inline' do | 6 | = form_tag admin_projects_path, method: :get, class: 'form-inline' do |
7 | = text_field_tag :name, params[:name], class: "xlarge" | 7 | = text_field_tag :name, params[:name], class: "xlarge" |
@@ -16,7 +16,7 @@ | @@ -16,7 +16,7 @@ | ||
16 | %th Edit | 16 | %th Edit |
17 | %th.cred Danger Zone! | 17 | %th.cred Danger Zone! |
18 | 18 | ||
19 | - - @admin_projects.each do |project| | 19 | + - @projects.each do |project| |
20 | %tr | 20 | %tr |
21 | %td= link_to project.name, [:admin, project] | 21 | %td= link_to project.name, [:admin, project] |
22 | %td= project.path | 22 | %td= project.path |
@@ -24,4 +24,4 @@ | @@ -24,4 +24,4 @@ | ||
24 | %td= last_commit(project) | 24 | %td= last_commit(project) |
25 | %td= link_to 'Edit', edit_admin_project_path(project), id: "edit_#{dom_id(project)}", class: "btn small" | 25 | %td= link_to 'Edit', edit_admin_project_path(project), id: "edit_#{dom_id(project)}", class: "btn small" |
26 | %td.bgred= link_to 'Destroy', [:admin, project], confirm: "REMOVE #{project.name}? Are you sure?", method: :delete, class: "btn small danger" | 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,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 & repository. Please wait a few minutes | ||
10 | - | ||
11 | -:javascript | ||
12 | - $(function(){ new Projects(); }); |
app/views/admin/projects/show.html.haml
1 | = render 'admin/shared/projects_head' | 1 | = render 'admin/shared/projects_head' |
2 | %h3.page_title | 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 | %i.icon-edit | 5 | %i.icon-edit |
6 | Edit | 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 | %br | 9 | %br |
10 | .alert.alert-error | 10 | .alert.alert-error |
11 | %span | 11 | %span |
@@ -25,36 +25,36 @@ | @@ -25,36 +25,36 @@ | ||
25 | %b | 25 | %b |
26 | Name: | 26 | Name: |
27 | %td | 27 | %td |
28 | - = @admin_project.name | 28 | + = @project.name |
29 | %tr | 29 | %tr |
30 | %td | 30 | %td |
31 | %b | 31 | %b |
32 | Code: | 32 | Code: |
33 | %td | 33 | %td |
34 | - = @admin_project.code | 34 | + = @project.code |
35 | %tr | 35 | %tr |
36 | %td | 36 | %td |
37 | %b | 37 | %b |
38 | Path: | 38 | Path: |
39 | %td | 39 | %td |
40 | - = @admin_project.path | 40 | + %code= @project.path_to_repo |
41 | %tr | 41 | %tr |
42 | %td | 42 | %td |
43 | %b | 43 | %b |
44 | Owner: | 44 | Owner: |
45 | %td | 45 | %td |
46 | - = @admin_project.owner_name || '(deleted)' | 46 | + = @project.owner_name || '(deleted)' |
47 | %tr | 47 | %tr |
48 | %td | 48 | %td |
49 | %b | 49 | %b |
50 | Post Receive File: | 50 | Post Receive File: |
51 | %td | 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 | %br | 53 | %br |
54 | %h3 | 54 | %h3 |
55 | Team | 55 | Team |
56 | %small | 56 | %small |
57 | - (#{@admin_project.users_projects.count}) | 57 | + (#{@project.users_projects.count}) |
58 | %br | 58 | %br |
59 | %table.zebra-striped | 59 | %table.zebra-striped |
60 | %thead | 60 | %thead |
@@ -64,7 +64,7 @@ | @@ -64,7 +64,7 @@ | ||
64 | %th Repository Access | 64 | %th Repository Access |
65 | %th | 65 | %th |
66 | 66 | ||
67 | - - @admin_project.users_projects.each do |tm| | 67 | + - @project.users_projects.each do |tm| |
68 | %tr | 68 | %tr |
69 | %td | 69 | %td |
70 | = link_to tm.user_name, admin_user_path(tm.user) | 70 | = link_to tm.user_name, admin_user_path(tm.user) |
@@ -75,7 +75,7 @@ | @@ -75,7 +75,7 @@ | ||
75 | %br | 75 | %br |
76 | %h3 Add new team member | 76 | %h3 Add new team member |
77 | %br | 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 | %table.zebra-striped | 79 | %table.zebra-striped |
80 | %thead | 80 | %thead |
81 | %tr | 81 | %tr |
config/routes.rb
@@ -49,7 +49,7 @@ Gitlab::Application.routes.draw do | @@ -49,7 +49,7 @@ Gitlab::Application.routes.draw do | ||
49 | delete :remove_project | 49 | delete :remove_project |
50 | end | 50 | end |
51 | end | 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 | member do | 53 | member do |
54 | get :team | 54 | get :team |
55 | put :team_update | 55 | put :team_update |