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,9 +64,8 @@ class ApplicationController < ActionController::Base | ||
64 | 64 | ||
65 | def project | 65 | def project |
66 | id = params[:project_id] || params[:id] | 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 | @project || render_404 | 69 | @project || render_404 |
71 | end | 70 | end |
72 | 71 |
app/controllers/groups_controller.rb
@@ -4,6 +4,7 @@ class GroupsController < ApplicationController | @@ -4,6 +4,7 @@ class GroupsController < ApplicationController | ||
4 | 4 | ||
5 | before_filter :group | 5 | before_filter :group |
6 | before_filter :projects | 6 | before_filter :projects |
7 | + before_filter :add_project_abilities | ||
7 | 8 | ||
8 | def show | 9 | def show |
9 | @events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0) | 10 | @events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0) |
app/controllers/projects_controller.rb
@@ -34,8 +34,16 @@ class ProjectsController < ProjectResourceController | @@ -34,8 +34,16 @@ class ProjectsController < ProjectResourceController | ||
34 | end | 34 | end |
35 | 35 | ||
36 | def update | 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 | respond_to do |format| | 44 | respond_to do |format| |
38 | if project.update_attributes(params[:project]) | 45 | if project.update_attributes(params[:project]) |
46 | + flash[:notice] = 'Project was successfully updated.' | ||
39 | format.html { redirect_to edit_project_path(project), notice: 'Project was successfully updated.' } | 47 | format.html { redirect_to edit_project_path(project), notice: 'Project was successfully updated.' } |
40 | format.js | 48 | format.js |
41 | else | 49 | else |
app/models/ability.rb
@@ -7,6 +7,7 @@ class Ability | @@ -7,6 +7,7 @@ class Ability | ||
7 | when "Note" then note_abilities(object, subject) | 7 | when "Note" then note_abilities(object, subject) |
8 | when "Snippet" then snippet_abilities(object, subject) | 8 | when "Snippet" then snippet_abilities(object, subject) |
9 | when "MergeRequest" then merge_request_abilities(object, subject) | 9 | when "MergeRequest" then merge_request_abilities(object, subject) |
10 | + when "Group" then group_abilities(object, subject) | ||
10 | else [] | 11 | else [] |
11 | end | 12 | end |
12 | end | 13 | end |
@@ -61,6 +62,16 @@ class Ability | @@ -61,6 +62,16 @@ class Ability | ||
61 | rules.flatten | 62 | rules.flatten |
62 | end | 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 | [:issue, :note, :snippet, :merge_request].each do |name| | 75 | [:issue, :note, :snippet, :merge_request].each do |name| |
65 | define_method "#{name}_abilities" do |user, subject| | 76 | define_method "#{name}_abilities" do |user, subject| |
66 | if subject.author == user | 77 | if subject.author == user |
app/models/project.rb
@@ -84,6 +84,16 @@ class Project < ActiveRecord::Base | @@ -84,6 +84,16 @@ class Project < ActiveRecord::Base | ||
84 | where("projects.name LIKE :query OR projects.path LIKE :query", query: "%#{query}%") | 84 | where("projects.name LIKE :query OR projects.path LIKE :query", query: "%#{query}%") |
85 | end | 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 | def create_by_user(params, user) | 97 | def create_by_user(params, user) |
88 | namespace_id = params.delete(:namespace_id) | 98 | namespace_id = params.delete(:namespace_id) |
89 | namespace_id ||= user.namespace.try(:id) | 99 | namespace_id ||= user.namespace.try(:id) |
app/views/groups/_projects.html.haml
@@ -3,6 +3,11 @@ | @@ -3,6 +3,11 @@ | ||
3 | Projects | 3 | Projects |
4 | %small | 4 | %small |
5 | (#{projects.count}) | 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 | %ul.unstyled | 11 | %ul.unstyled |
7 | - projects.each do |project| | 12 | - projects.each do |project| |
8 | %li.wll | 13 | %li.wll |
app/views/projects/_form.html.haml
@@ -9,41 +9,45 @@ | @@ -9,41 +9,45 @@ | ||
9 | Project name is | 9 | Project name is |
10 | .input | 10 | .input |
11 | = f.text_field :name, placeholder: "Example Project", class: "xxlarge" | 11 | = f.text_field :name, placeholder: "Example Project", class: "xxlarge" |
12 | - | ||
13 | %fieldset | 12 | %fieldset |
14 | %legend Advanced settings: | 13 | %legend Advanced settings: |
15 | - .clearfix | 14 | + .control-group |
16 | = f.label :path do | 15 | = f.label :path do |
17 | Path | 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 | .clearfix | 29 | .clearfix |
25 | = f.label :default_branch, "Default Branch" | 30 | = f.label :default_branch, "Default Branch" |
26 | .input= f.select(:default_branch, @project.heads.map(&:name), {}, style: "width:210px;") | 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 | %br | 52 | %br |
49 | 53 |
app/views/projects/_new_form.html.haml
@@ -14,7 +14,7 @@ | @@ -14,7 +14,7 @@ | ||
14 | = f.label :namespace_id do | 14 | = f.label :namespace_id do |
15 | %span.cgray Namespace | 15 | %span.cgray Namespace |
16 | .input | 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 | %hr | 18 | %hr |
19 | %p.padded | 19 | %p.padded |
20 | All created project are private. You choose who can see project and commit to repository. | 20 | All created project are private. You choose who can see project and commit to repository. |
app/views/projects/update.js.haml
1 | - if @project.valid? | 1 | - if @project.valid? |
2 | :plain | 2 | :plain |
3 | - location.href = "#{edit_project_path(@project, notice: 'Project was successfully updated.')}"; | 3 | + location.href = "#{edit_project_path(@project)}"; |
4 | - else | 4 | - else |
5 | :plain | 5 | :plain |
6 | $('.project_edit_holder').show(); | 6 | $('.project_edit_holder').show(); |