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
def project
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
end
......
......@@ -4,6 +4,7 @@ class GroupsController < ApplicationController
before_filter :group
before_filter :projects
before_filter :add_project_abilities
def show
@events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0)
......
......@@ -34,8 +34,16 @@ class ProjectsController < ProjectResourceController
end
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|
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.js
else
......
......@@ -7,6 +7,7 @@ class Ability
when "Note" then note_abilities(object, subject)
when "Snippet" then snippet_abilities(object, subject)
when "MergeRequest" then merge_request_abilities(object, subject)
when "Group" then group_abilities(object, subject)
else []
end
end
......@@ -61,6 +62,16 @@ class Ability
rules.flatten
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|
define_method "#{name}_abilities" do |user, subject|
if subject.author == user
......
......@@ -84,6 +84,16 @@ class Project < ActiveRecord::Base
where("projects.name LIKE :query OR projects.path LIKE :query", query: "%#{query}%")
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)
namespace_id = params.delete(:namespace_id)
namespace_id ||= user.namespace.try(:id)
......
......@@ -3,6 +3,11 @@
Projects
%small
(#{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
- projects.each do |project|
%li.wll
......
......@@ -9,41 +9,45 @@
Project name is
.input
= f.text_field :name, placeholder: "Example Project", class: "xxlarge"
%fieldset
%legend Advanced settings:
.clearfix
.control-group
= f.label :path do
Path
.input
.input-prepend
%strong
= text_field_tag :ppath, @project.path_to_repo, class: "xlarge", disabled: true
- unless @project.new_record? || @project.heads.empty?
.controls
= text_field_tag :ppath, @project.path_to_repo, class: "xlarge", disabled: true
.control-group
= f.label :namespace_id do
%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
= f.label :default_branch, "Default Branch"
.input= f.select(:default_branch, @project.heads.map(&:name), {}, style: "width:210px;")
- unless @project.new_record?
%fieldset
%legend Features:
%fieldset
%legend Features:
.clearfix
= f.label :issues_enabled, "Issues"
.input= f.check_box :issues_enabled
.clearfix
= f.label :issues_enabled, "Issues"
.input= f.check_box :issues_enabled
.clearfix
= f.label :merge_requests_enabled, "Merge Requests"
.input= f.check_box :merge_requests_enabled
.clearfix
= f.label :merge_requests_enabled, "Merge Requests"
.input= f.check_box :merge_requests_enabled
.clearfix
= f.label :wall_enabled, "Wall"
.input= f.check_box :wall_enabled
.clearfix
= f.label :wall_enabled, "Wall"
.input= f.check_box :wall_enabled
.clearfix
= f.label :wiki_enabled, "Wiki"
.input= f.check_box :wiki_enabled
.clearfix
= f.label :wiki_enabled, "Wiki"
.input= f.check_box :wiki_enabled
%br
......
......@@ -14,7 +14,7 @@
= f.label :namespace_id do
%span.cgray Namespace
.input
= f.select :namespace_id, namespaces_options, {}, {class: 'chosen'}
= f.select :namespace_id, namespaces_options(params[:namespace_id] || :current_user), {}, {class: 'chosen'}
%hr
%p.padded
All created project are private. You choose who can see project and commit to repository.
- if @project.valid?
:plain
location.href = "#{edit_project_path(@project, notice: 'Project was successfully updated.')}";
location.href = "#{edit_project_path(@project)}";
- else
:plain
$('.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