Commit f37fa968 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

add ability to change namespace from project edit page

parent f9979476
...@@ -64,9 +64,8 @@ class ApplicationController < ActionController::Base ...@@ -64,9 +64,8 @@ class ApplicationController < ActionController::Base
def project def project
id = params[:project_id] || params[:id] id = params[:project_id] || params[:id]
id = id.split("/") if id.include?("/")
@project ||= current_user.projects.find_by_path(id) @project ||= current_user.projects.find_with_namespace(id)
@project || render_404 @project || render_404
end end
......
...@@ -4,6 +4,7 @@ class GroupsController < ApplicationController ...@@ -4,6 +4,7 @@ class GroupsController < ApplicationController
before_filter :group before_filter :group
before_filter :projects before_filter :projects
before_filter :add_project_abilities
def show def show
@events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0) @events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0)
......
...@@ -34,8 +34,16 @@ class ProjectsController < ProjectResourceController ...@@ -34,8 +34,16 @@ class ProjectsController < ProjectResourceController
end end
def update def update
namespace_id = params[:project].delete(:namespace_id)
if namespace_id
namespace = Namespace.find(namespace_id)
project.transfer(namespace)
end
respond_to do |format| respond_to do |format|
if project.update_attributes(params[:project]) if project.update_attributes(params[:project])
flash[:notice] = 'Project was successfully updated.'
format.html { redirect_to edit_project_path(project), notice: 'Project was successfully updated.' } format.html { redirect_to edit_project_path(project), notice: 'Project was successfully updated.' }
format.js format.js
else else
......
...@@ -7,6 +7,7 @@ class Ability ...@@ -7,6 +7,7 @@ class Ability
when "Note" then note_abilities(object, subject) when "Note" then note_abilities(object, subject)
when "Snippet" then snippet_abilities(object, subject) when "Snippet" then snippet_abilities(object, subject)
when "MergeRequest" then merge_request_abilities(object, subject) when "MergeRequest" then merge_request_abilities(object, subject)
when "Group" then group_abilities(object, subject)
else [] else []
end end
end end
...@@ -61,6 +62,16 @@ class Ability ...@@ -61,6 +62,16 @@ class Ability
rules.flatten rules.flatten
end end
def group_abilities user, group
rules = []
rules << [
:manage_group
] if group.owner == user
rules.flatten
end
[:issue, :note, :snippet, :merge_request].each do |name| [:issue, :note, :snippet, :merge_request].each do |name|
define_method "#{name}_abilities" do |user, subject| define_method "#{name}_abilities" do |user, subject|
if subject.author == user if subject.author == user
......
...@@ -84,6 +84,16 @@ class Project < ActiveRecord::Base ...@@ -84,6 +84,16 @@ class Project < ActiveRecord::Base
where("projects.name LIKE :query OR projects.path LIKE :query", query: "%#{query}%") where("projects.name LIKE :query OR projects.path LIKE :query", query: "%#{query}%")
end end
def find_with_namespace(id)
if id.include?("/")
id = id.split("/")
namespace_id = Namespace.find_by_path(id.first).id
where(namespace_id: namespace_id).find_by_path(id.last)
else
find_by_path(id)
end
end
def create_by_user(params, user) def create_by_user(params, user)
namespace_id = params.delete(:namespace_id) namespace_id = params.delete(:namespace_id)
namespace_id ||= user.namespace.try(:id) namespace_id ||= user.namespace.try(:id)
......
...@@ -3,6 +3,11 @@ ...@@ -3,6 +3,11 @@
Projects Projects
%small %small
(#{projects.count}) (#{projects.count})
- if can? current_user, :manage_group, @group
%span.right
= link_to new_project_path(namespace_id: @group.id), class: "btn very_small info" do
%i.icon-plus
New Project
%ul.unstyled %ul.unstyled
- projects.each do |project| - projects.each do |project|
%li.wll %li.wll
......
...@@ -9,41 +9,45 @@ ...@@ -9,41 +9,45 @@
Project name is Project name is
.input .input
= f.text_field :name, placeholder: "Example Project", class: "xxlarge" = f.text_field :name, placeholder: "Example Project", class: "xxlarge"
%fieldset %fieldset
%legend Advanced settings: %legend Advanced settings:
.clearfix .control-group
= f.label :path do = f.label :path do
Path Path
.input .controls
.input-prepend = text_field_tag :ppath, @project.path_to_repo, class: "xlarge", disabled: true
%strong
= text_field_tag :ppath, @project.path_to_repo, class: "xlarge", disabled: true .control-group
= f.label :namespace_id do
- unless @project.new_record? || @project.heads.empty? %span Namespace
.controls
= f.select :namespace_id, namespaces_options(@project.namespace_id), {}, {class: 'chosen'}
&nbsp;
%span.cred Be careful. Changing project namespace can have unintended side effects
- unless @project.heads.empty?
.clearfix .clearfix
= f.label :default_branch, "Default Branch" = f.label :default_branch, "Default Branch"
.input= f.select(:default_branch, @project.heads.map(&:name), {}, style: "width:210px;") .input= f.select(:default_branch, @project.heads.map(&:name), {}, style: "width:210px;")
- unless @project.new_record? %fieldset
%fieldset %legend Features:
%legend Features:
.clearfix .clearfix
= f.label :issues_enabled, "Issues" = f.label :issues_enabled, "Issues"
.input= f.check_box :issues_enabled .input= f.check_box :issues_enabled
.clearfix .clearfix
= f.label :merge_requests_enabled, "Merge Requests" = f.label :merge_requests_enabled, "Merge Requests"
.input= f.check_box :merge_requests_enabled .input= f.check_box :merge_requests_enabled
.clearfix .clearfix
= f.label :wall_enabled, "Wall" = f.label :wall_enabled, "Wall"
.input= f.check_box :wall_enabled .input= f.check_box :wall_enabled
.clearfix .clearfix
= f.label :wiki_enabled, "Wiki" = f.label :wiki_enabled, "Wiki"
.input= f.check_box :wiki_enabled .input= f.check_box :wiki_enabled
%br %br
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
= f.label :namespace_id do = f.label :namespace_id do
%span.cgray Namespace %span.cgray Namespace
.input .input
= f.select :namespace_id, namespaces_options, {}, {class: 'chosen'} = f.select :namespace_id, namespaces_options(params[:namespace_id] || :current_user), {}, {class: 'chosen'}
%hr %hr
%p.padded %p.padded
All created project are private. You choose who can see project and commit to repository. All created project are private. You choose who can see project and commit to repository.
- if @project.valid? - if @project.valid?
:plain :plain
location.href = "#{edit_project_path(@project, notice: 'Project was successfully updated.')}"; location.href = "#{edit_project_path(@project)}";
- else - else
:plain :plain
$('.project_edit_holder').show(); $('.project_edit_holder').show();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment