Commit f37fa968b2509d8e2ab0fc72aba1fb53df7451c7
1 parent
f9979476
Exists in
master
and in
4 other branches
add ability to change namespace from project edit page
Showing
9 changed files
with
65 additions
and
27 deletions
Show diff stats
app/controllers/application_controller.rb
... | ... | @@ -64,9 +64,8 @@ class ApplicationController < ActionController::Base |
64 | 64 | |
65 | 65 | def project |
66 | 66 | id = params[:project_id] || params[:id] |
67 | - id = id.split("/") if id.include?("/") | |
68 | 67 | |
69 | - @project ||= current_user.projects.find_by_path(id) | |
68 | + @project ||= current_user.projects.find_with_namespace(id) | |
70 | 69 | @project || render_404 |
71 | 70 | end |
72 | 71 | ... | ... |
app/controllers/groups_controller.rb
app/controllers/projects_controller.rb
... | ... | @@ -34,8 +34,16 @@ class ProjectsController < ProjectResourceController |
34 | 34 | end |
35 | 35 | |
36 | 36 | def update |
37 | + namespace_id = params[:project].delete(:namespace_id) | |
38 | + | |
39 | + if namespace_id | |
40 | + namespace = Namespace.find(namespace_id) | |
41 | + project.transfer(namespace) | |
42 | + end | |
43 | + | |
37 | 44 | respond_to do |format| |
38 | 45 | if project.update_attributes(params[:project]) |
46 | + flash[:notice] = 'Project was successfully updated.' | |
39 | 47 | format.html { redirect_to edit_project_path(project), notice: 'Project was successfully updated.' } |
40 | 48 | format.js |
41 | 49 | else | ... | ... |
app/models/ability.rb
... | ... | @@ -7,6 +7,7 @@ class Ability |
7 | 7 | when "Note" then note_abilities(object, subject) |
8 | 8 | when "Snippet" then snippet_abilities(object, subject) |
9 | 9 | when "MergeRequest" then merge_request_abilities(object, subject) |
10 | + when "Group" then group_abilities(object, subject) | |
10 | 11 | else [] |
11 | 12 | end |
12 | 13 | end |
... | ... | @@ -61,6 +62,16 @@ class Ability |
61 | 62 | rules.flatten |
62 | 63 | end |
63 | 64 | |
65 | + def group_abilities user, group | |
66 | + rules = [] | |
67 | + | |
68 | + rules << [ | |
69 | + :manage_group | |
70 | + ] if group.owner == user | |
71 | + | |
72 | + rules.flatten | |
73 | + end | |
74 | + | |
64 | 75 | [:issue, :note, :snippet, :merge_request].each do |name| |
65 | 76 | define_method "#{name}_abilities" do |user, subject| |
66 | 77 | if subject.author == user | ... | ... |
app/models/project.rb
... | ... | @@ -84,6 +84,16 @@ class Project < ActiveRecord::Base |
84 | 84 | where("projects.name LIKE :query OR projects.path LIKE :query", query: "%#{query}%") |
85 | 85 | end |
86 | 86 | |
87 | + def find_with_namespace(id) | |
88 | + if id.include?("/") | |
89 | + id = id.split("/") | |
90 | + namespace_id = Namespace.find_by_path(id.first).id | |
91 | + where(namespace_id: namespace_id).find_by_path(id.last) | |
92 | + else | |
93 | + find_by_path(id) | |
94 | + end | |
95 | + end | |
96 | + | |
87 | 97 | def create_by_user(params, user) |
88 | 98 | namespace_id = params.delete(:namespace_id) |
89 | 99 | namespace_id ||= user.namespace.try(:id) | ... | ... |
app/views/groups/_projects.html.haml
... | ... | @@ -3,6 +3,11 @@ |
3 | 3 | Projects |
4 | 4 | %small |
5 | 5 | (#{projects.count}) |
6 | + - if can? current_user, :manage_group, @group | |
7 | + %span.right | |
8 | + = link_to new_project_path(namespace_id: @group.id), class: "btn very_small info" do | |
9 | + %i.icon-plus | |
10 | + New Project | |
6 | 11 | %ul.unstyled |
7 | 12 | - projects.each do |project| |
8 | 13 | %li.wll | ... | ... |
app/views/projects/_form.html.haml
... | ... | @@ -9,41 +9,45 @@ |
9 | 9 | Project name is |
10 | 10 | .input |
11 | 11 | = f.text_field :name, placeholder: "Example Project", class: "xxlarge" |
12 | - | |
13 | 12 | %fieldset |
14 | 13 | %legend Advanced settings: |
15 | - .clearfix | |
14 | + .control-group | |
16 | 15 | = f.label :path do |
17 | 16 | Path |
18 | - .input | |
19 | - .input-prepend | |
20 | - %strong | |
21 | - = text_field_tag :ppath, @project.path_to_repo, class: "xlarge", disabled: true | |
22 | - | |
23 | - - unless @project.new_record? || @project.heads.empty? | |
17 | + .controls | |
18 | + = text_field_tag :ppath, @project.path_to_repo, class: "xlarge", disabled: true | |
19 | + | |
20 | + .control-group | |
21 | + = f.label :namespace_id do | |
22 | + %span Namespace | |
23 | + .controls | |
24 | + = f.select :namespace_id, namespaces_options(@project.namespace_id), {}, {class: 'chosen'} | |
25 | + | |
26 | + %span.cred Be careful. Changing project namespace can have unintended side effects | |
27 | + | |
28 | + - unless @project.heads.empty? | |
24 | 29 | .clearfix |
25 | 30 | = f.label :default_branch, "Default Branch" |
26 | 31 | .input= f.select(:default_branch, @project.heads.map(&:name), {}, style: "width:210px;") |
27 | 32 | |
28 | - - unless @project.new_record? | |
29 | - %fieldset | |
30 | - %legend Features: | |
33 | + %fieldset | |
34 | + %legend Features: | |
31 | 35 | |
32 | - .clearfix | |
33 | - = f.label :issues_enabled, "Issues" | |
34 | - .input= f.check_box :issues_enabled | |
36 | + .clearfix | |
37 | + = f.label :issues_enabled, "Issues" | |
38 | + .input= f.check_box :issues_enabled | |
35 | 39 | |
36 | - .clearfix | |
37 | - = f.label :merge_requests_enabled, "Merge Requests" | |
38 | - .input= f.check_box :merge_requests_enabled | |
40 | + .clearfix | |
41 | + = f.label :merge_requests_enabled, "Merge Requests" | |
42 | + .input= f.check_box :merge_requests_enabled | |
39 | 43 | |
40 | - .clearfix | |
41 | - = f.label :wall_enabled, "Wall" | |
42 | - .input= f.check_box :wall_enabled | |
44 | + .clearfix | |
45 | + = f.label :wall_enabled, "Wall" | |
46 | + .input= f.check_box :wall_enabled | |
43 | 47 | |
44 | - .clearfix | |
45 | - = f.label :wiki_enabled, "Wiki" | |
46 | - .input= f.check_box :wiki_enabled | |
48 | + .clearfix | |
49 | + = f.label :wiki_enabled, "Wiki" | |
50 | + .input= f.check_box :wiki_enabled | |
47 | 51 | |
48 | 52 | %br |
49 | 53 | ... | ... |
app/views/projects/_new_form.html.haml
... | ... | @@ -14,7 +14,7 @@ |
14 | 14 | = f.label :namespace_id do |
15 | 15 | %span.cgray Namespace |
16 | 16 | .input |
17 | - = f.select :namespace_id, namespaces_options, {}, {class: 'chosen'} | |
17 | + = f.select :namespace_id, namespaces_options(params[:namespace_id] || :current_user), {}, {class: 'chosen'} | |
18 | 18 | %hr |
19 | 19 | %p.padded |
20 | 20 | All created project are private. You choose who can see project and commit to repository. | ... | ... |
app/views/projects/update.js.haml