Refactor project creation. Added logout link to profile page
This commit is contained in:
parent
c7c1a97c2f
commit
232d61d598
19 changed files with 126 additions and 116 deletions
|
@ -7,7 +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)
|
||||
when "Group", "Namespace" then group_abilities(object, subject)
|
||||
else []
|
||||
end
|
||||
end
|
||||
|
@ -102,7 +102,8 @@ class Ability
|
|||
# Only group owner and administrators can manage group
|
||||
if group.owner == user || user.admin?
|
||||
rules << [
|
||||
:manage_group
|
||||
:manage_group,
|
||||
:manage_namespace
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -116,55 +116,6 @@ class Project < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def create_by_user(params, user)
|
||||
namespace_id = params.delete(:namespace_id)
|
||||
|
||||
project = Project.new params
|
||||
|
||||
Project.transaction do
|
||||
|
||||
# Parametrize path for project
|
||||
#
|
||||
# Ex.
|
||||
# 'GitLab HQ'.parameterize => "gitlab-hq"
|
||||
#
|
||||
project.path = project.name.dup.parameterize
|
||||
|
||||
project.creator = user
|
||||
|
||||
# Apply namespace if user has access to it
|
||||
# else fallback to user namespace
|
||||
if namespace_id != Namespace.global_id
|
||||
project.namespace_id = user.namespace_id
|
||||
|
||||
if namespace_id
|
||||
group = Group.find_by_id(namespace_id)
|
||||
if user.can? :manage_group, group
|
||||
project.namespace_id = namespace_id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
project.save!
|
||||
|
||||
# Add user as project master
|
||||
project.users_projects.create!(project_access: UsersProject::MASTER, user: user)
|
||||
|
||||
# when project saved no team member exist so
|
||||
# project repository should be updated after first user add
|
||||
project.update_repository
|
||||
end
|
||||
|
||||
project
|
||||
rescue Gitlab::Gitolite::AccessDenied => ex
|
||||
project.error_code = :gitolite
|
||||
project
|
||||
rescue => ex
|
||||
project.error_code = :db
|
||||
project.errors.add(:base, "Can't save project. Please try again later")
|
||||
project
|
||||
end
|
||||
|
||||
def access_options
|
||||
UsersProject.access_roles
|
||||
end
|
||||
|
|
|
@ -152,11 +152,8 @@ class User < ActiveRecord::Base
|
|||
namespaces << self.namespace if self.namespace
|
||||
|
||||
# Add groups you can manage
|
||||
namespaces += if admin
|
||||
Group.all
|
||||
else
|
||||
groups.all
|
||||
end
|
||||
namespaces += groups.all
|
||||
|
||||
namespaces
|
||||
end
|
||||
|
||||
|
@ -234,6 +231,10 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def can_select_namespace?
|
||||
several_namespaces? || admin
|
||||
end
|
||||
|
||||
def can? action, subject
|
||||
abilities.allowed?(self, action, subject)
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue