add ability to change namespace from project edit page

This commit is contained in:
Dmitriy Zaporozhets 2012-11-24 22:00:30 +02:00
parent f997947664
commit f37fa968b2
9 changed files with 64 additions and 26 deletions

View file

@ -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

View file

@ -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)