summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/admin/groups_controller.rb11
-rw-r--r--app/controllers/groups_controller.rb2
-rw-r--r--app/controllers/profiles/groups_controller.rb4
-rw-r--r--app/models/ability.rb4
-rw-r--r--app/models/group.rb25
-rw-r--r--app/models/namespace.rb2
-rw-r--r--app/models/project.rb10
-rw-r--r--app/models/user.rb2
-rw-r--r--app/services/system_hooks_service.rb6
-rw-r--r--app/views/admin/groups/index.html.haml7
-rw-r--r--app/views/admin/groups/show.html.haml23
-rw-r--r--app/views/admin/projects/show.html.haml2
12 files changed, 32 insertions, 66 deletions
diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb
index a2201f732e6..89b395786b3 100644
--- a/app/controllers/admin/groups_controller.rb
+++ b/app/controllers/admin/groups_controller.rb
@@ -20,9 +20,9 @@ class Admin::GroupsController < Admin::ApplicationController
def create
@group = Group.new(params[:group])
@group.path = @group.name.dup.parameterize if @group.name
- @group.owner = current_user
if @group.save
+ @group.add_owner(current_user)
redirect_to [:admin, @group], notice: 'Group was successfully created.'
else
render "new"
@@ -30,14 +30,7 @@ class Admin::GroupsController < Admin::ApplicationController
end
def update
- group_params = params[:group].dup
- owner_id =group_params.delete(:owner_id)
-
- if owner_id
- @group.change_owner(User.find(owner_id))
- end
-
- if @group.update_attributes(group_params)
+ if @group.update_attributes(params[:group])
redirect_to [:admin, @group], notice: 'Group was successfully updated.'
else
render "edit"
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index caf8ef85e87..f80167da4cb 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -21,9 +21,9 @@ class GroupsController < ApplicationController
def create
@group = Group.new(params[:group])
@group.path = @group.name.dup.parameterize if @group.name
- @group.owner = current_user
if @group.save
+ @group.add_owner(current_user)
redirect_to @group, notice: 'Group was successfully created.'
else
render action: "new"
diff --git a/app/controllers/profiles/groups_controller.rb b/app/controllers/profiles/groups_controller.rb
index e276d07b489..378ff6bcf34 100644
--- a/app/controllers/profiles/groups_controller.rb
+++ b/app/controllers/profiles/groups_controller.rb
@@ -8,8 +8,8 @@ class Profiles::GroupsController < ApplicationController
def leave
@users_group = group.users_groups.where(user_id: current_user.id).first
- if group.owner == current_user
- redirect_to(profile_groups_path, alert: "You can't leave group. You must transfer it to another owner before leaving.")
+ if group.last_owner?(current_user)
+ redirect_to(profile_groups_path, alert: "You can't leave group. You must add at least one more owner to it.")
else
@users_group.destroy
redirect_to(profile_groups_path, info: "You left #{group.name} group.")
diff --git a/app/models/ability.rb b/app/models/ability.rb
index ad070dad296..85476089145 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -79,7 +79,7 @@ class Ability
rules << project_admin_rules
end
- if project.group && project.group.owners.include?(user)
+ if project.group && project.group.has_owner?(user)
rules << project_admin_rules
end
@@ -159,7 +159,7 @@ class Ability
end
# Only group owner and administrators can manage group
- if group.owners.include?(user) || user.admin?
+ if group.has_owner?(user) || user.admin?
rules << [
:manage_group,
:manage_namespace
diff --git a/app/models/group.rb b/app/models/group.rb
index 0b36c934375..0cc3a3a0f41 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -16,14 +16,12 @@ class Group < Namespace
has_many :users_groups, dependent: :destroy
has_many :users, through: :users_groups
- after_create :add_owner
-
def human_name
name
end
def owners
- @owners ||= (users_groups.owners.map(&:user) << owner).uniq
+ @owners ||= users_groups.owners.map(&:user)
end
def add_users(user_ids, group_access)
@@ -36,20 +34,19 @@ class Group < Namespace
self.users_groups.create(user_id: user.id, group_access: group_access)
end
- def change_owner(user)
- self.owner = user
- membership = users_groups.where(user_id: user.id).first
+ def add_owner(user)
+ self.add_user(user, UsersGroup::OWNER)
+ end
- if membership
- membership.update_attributes(group_access: UsersGroup::OWNER)
- else
- add_owner
- end
+ def has_owner?(user)
+ owners.include?(user)
end
- private
+ def last_owner?(user)
+ has_owner?(user) && owners.size == 1
+ end
- def add_owner
- self.add_users([owner.id], UsersGroup::OWNER)
+ def members
+ users_groups
end
end
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index 18959166931..6ac94c06604 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -20,7 +20,7 @@ class Namespace < ActiveRecord::Base
has_many :projects, dependent: :destroy
belongs_to :owner, class_name: "User"
- validates :owner, presence: true
+ validates :owner, presence: true, unless: ->(n) { n.type == "Group" }
validates :name, presence: true, uniqueness: true,
length: { within: 0..255 },
format: { with: Gitlab::Regex.name_regex,
diff --git a/app/models/project.rb b/app/models/project.rb
index 63cd3505ec4..c4f4b06713d 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -249,10 +249,10 @@ class Project < ActiveRecord::Base
end
def owner
- if namespace
- namespace_owner
+ if group
+ group
else
- creator
+ namespace.try(:owner)
end
end
@@ -276,10 +276,6 @@ class Project < ActiveRecord::Base
end
end
- def namespace_owner
- namespace.try(:owner)
- end
-
def path_with_namespace
if namespace
namespace.path + '/' + path
diff --git a/app/models/user.rb b/app/models/user.rb
index ea004e4c9a7..f1f93eadc1a 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -135,7 +135,7 @@ class User < ActiveRecord::Base
# Remove user from all groups
user.users_groups.find_each do |membership|
# skip owned resources
- next if membership.group.owners.include?(user)
+ next if membership.group.last_owner?(user)
return false unless membership.destroy
end
diff --git a/app/services/system_hooks_service.rb b/app/services/system_hooks_service.rb
index c872b27ba39..39aec943f75 100644
--- a/app/services/system_hooks_service.rb
+++ b/app/services/system_hooks_service.rb
@@ -23,13 +23,15 @@ class SystemHooksService
case model
when Project
+ owner = model.owner
+
data.merge!({
name: model.name,
path: model.path,
path_with_namespace: model.path_with_namespace,
project_id: model.id,
- owner_name: model.owner.name,
- owner_email: model.owner.email
+ owner_name: owner.name,
+ owner_email: owner.respond_to?(:email) ? owner.email : nil
})
when User
data.merge!({
diff --git a/app/views/admin/groups/index.html.haml b/app/views/admin/groups/index.html.haml
index 8e45dc76ec6..c9d7c24f204 100644
--- a/app/views/admin/groups/index.html.haml
+++ b/app/views/admin/groups/index.html.haml
@@ -31,11 +31,8 @@
.clearfix.light.append-bottom-10
%span
- %b Owner:
- - if group.owner
- = link_to group.owner_name, admin_user_path(group.owner)
- - else
- (deleted)
+ %b Members:
+ %span.badge= group.members.size
\|
%span
%b Projects:
diff --git a/app/views/admin/groups/show.html.haml b/app/views/admin/groups/show.html.haml
index 5509811bae5..1566c345809 100644
--- a/app/views/admin/groups/show.html.haml
+++ b/app/views/admin/groups/show.html.haml
@@ -25,26 +25,6 @@
= @group.description
%li
- %span.light Owned by:
- %strong
- - if @group.owner
- = link_to @group.owner_name, admin_user_path(@group.owner)
- - else
- (deleted)
- .pull-right
- = link_to "#", class: "btn btn-small change-owner-link" do
- %i.icon-edit
- Change owner
- %li.change-owner-holder.hide.bgred
- .form-holder
- %strong.cred New Owner:
- = form_for [:admin, @group] do |f|
- = users_select_tag(:"group[owner_id]")
- .prepend-top-10
- = f.submit 'Change Owner', class: "btn btn-remove"
- = link_to "Cancel", "#", class: "btn change-owner-cancel-link"
-
- %li
%span.light Created at:
%strong
= @group.created_at.stamp("March 1, 1999")
@@ -92,4 +72,5 @@
= link_to user.name, admin_user_path(user)
%span.pull-right.light
= member.human_access
-
+ = link_to group_users_group_path(@group, member), confirm: remove_user_from_group_message(@group, user), method: :delete, remote: true, class: "btn-tiny btn btn-remove", title: 'Remove user from group' do
+ %i.icon-minus.icon-white
diff --git a/app/views/admin/projects/show.html.haml b/app/views/admin/projects/show.html.haml
index cecc84fe093..c8a87328207 100644
--- a/app/views/admin/projects/show.html.haml
+++ b/app/views/admin/projects/show.html.haml
@@ -25,7 +25,7 @@
%span.light Owned by:
%strong
- if @project.owner
- = link_to @project.owner_name, admin_user_path(@project.owner)
+ = link_to @project.owner_name, [:admin, @project.owner]
- else
(deleted)