Commit e6002bdaffc819ea3b743955315cf50eb804dbdb

Authored by Dmitriy Zaporozhets
1 parent 591e094e

Ability to manage and remove group as owner outside of admin area

app/controllers/groups_controller.rb
@@ -6,6 +6,7 @@ class GroupsController < ApplicationController @@ -6,6 +6,7 @@ class GroupsController < ApplicationController
6 6
7 # Authorize 7 # Authorize
8 before_filter :authorize_read_group!, except: [:new, :create] 8 before_filter :authorize_read_group!, except: [:new, :create]
  9 + before_filter :authorize_admin_group!, only: [:edit, :update, :destroy]
9 before_filter :authorize_create_group!, only: [:new, :create] 10 before_filter :authorize_create_group!, only: [:new, :create]
10 11
11 # Load group projects 12 # Load group projects
@@ -84,6 +85,31 @@ class GroupsController < ApplicationController @@ -84,6 +85,31 @@ class GroupsController < ApplicationController
84 redirect_to people_group_path(@group), notice: 'Users was successfully added.' 85 redirect_to people_group_path(@group), notice: 'Users was successfully added.'
85 end 86 end
86 87
  88 + def edit
  89 + end
  90 +
  91 + def update
  92 + group_params = params[:group].dup
  93 + owner_id =group_params.delete(:owner_id)
  94 +
  95 + if owner_id
  96 + @group.owner = User.find(owner_id)
  97 + end
  98 +
  99 + if @group.update_attributes(group_params)
  100 + redirect_to @group, notice: 'Group was successfully updated.'
  101 + else
  102 + render action: "edit"
  103 + end
  104 + end
  105 +
  106 + def destroy
  107 + @group.truncate_teams
  108 + @group.destroy
  109 +
  110 + redirect_to root_path, notice: 'Group was removed.'
  111 + end
  112 +
87 protected 113 protected
88 114
89 def group 115 def group
@@ -106,6 +132,14 @@ class GroupsController < ApplicationController @@ -106,6 +132,14 @@ class GroupsController < ApplicationController
106 end 132 end
107 133
108 def authorize_create_group! 134 def authorize_create_group!
109 - can?(current_user, :create_group, nil) 135 + unless can?(current_user, :create_group, nil)
  136 + return render_404
  137 + end
  138 + end
  139 +
  140 + def authorize_admin_group!
  141 + unless can?(current_user, :manage_group, group)
  142 + return render_404
  143 + end
110 end 144 end
111 end 145 end
app/views/groups/edit.html.haml 0 → 100644
@@ -0,0 +1,50 @@ @@ -0,0 +1,50 @@
  1 +%h3.page_title Edit Group
  2 +%hr
  3 += form_for @group do |f|
  4 + - if @group.errors.any?
  5 + .alert.alert-error
  6 + %span= @group.errors.full_messages.first
  7 + .clearfix
  8 + = f.label :name do
  9 + Group name is
  10 + .input
  11 + = f.text_field :name, placeholder: "Ex. OpenSource", class: "xxlarge left"
  12 +  
  13 + = f.submit 'Save group', class: "btn btn-save"
  14 +%hr
  15 +
  16 +
  17 +.row
  18 + .span7
  19 + .ui-box
  20 + %h5.title Projects
  21 + %ul.well-list
  22 + - @group.projects.each do |project|
  23 + %li
  24 + - if project.public
  25 + %i.icon-share
  26 + - else
  27 + %i.icon-lock.cgreen
  28 + = link_to project.name_with_namespace, project
  29 + .pull-right
  30 + = link_to 'Team', project_team_index_path(project), id: "edit_#{dom_id(project)}", class: "btn btn-small"
  31 + = link_to 'Edit', edit_project_path(project), id: "edit_#{dom_id(project)}", class: "btn btn-small"
  32 + = link_to 'Remove', project, confirm: "REMOVE #{project.name}? Are you sure?", method: :delete, class: "btn btn-small btn-remove"
  33 +
  34 + .span5
  35 + .ui-box
  36 + %h5.title Transfer group
  37 + .padded
  38 + %p
  39 + Transferring group will cause loss of admin control over group and all child projects
  40 + = form_for @group do |f|
  41 + = f.select :owner_id, User.all.map { |user| [user.name, user.id] }, {}, {class: 'chosen'}
  42 + = f.submit 'Transfer group', class: "btn btn-small"
  43 + .ui-box
  44 + %h5.title Remove group
  45 + .padded.bgred
  46 + %p
  47 + Remove of group will cause removing all child projects and resources
  48 + %br
  49 + Removed group can not be restored!
  50 + = link_to 'Remove Group', @group, confirm: 'Removed group can not be restored! Are you sure?', method: :delete, class: "btn btn-remove btn-small"
app/views/layouts/group.html.haml
@@ -22,4 +22,10 @@ @@ -22,4 +22,10 @@
22 = nav_link(path: 'groups#people') do 22 = nav_link(path: 'groups#people') do
23 = link_to "People", people_group_path(@group) 23 = link_to "People", people_group_path(@group)
24 24
  25 + - if can?(current_user, :manage_group, @group)
  26 + = nav_link(path: 'groups#edit') do
  27 + = link_to edit_group_path(@group), class: "tab " do
  28 + %i.icon-edit
  29 + Edit Group
  30 +
25 .content= yield 31 .content= yield
app/views/projects/_form.html.haml
@@ -42,7 +42,7 @@ @@ -42,7 +42,7 @@
42 = f.check_box :wiki_enabled 42 = f.check_box :wiki_enabled
43 %span.descr Pages for project documentation 43 %span.descr Pages for project documentation
44 44
45 - - if can? current_user, :change_public_mode, @project 45 + - if can?(current_user, :change_public_mode, @project)
46 %fieldset.features 46 %fieldset.features
47 %legend 47 %legend
48 %i.icon-share 48 %i.icon-share
app/views/teams/edit.html.haml
@@ -15,8 +15,6 @@ @@ -15,8 +15,6 @@
15 Team path is 15 Team path is
16 .input 16 .input
17 = f.text_field :path, placeholder: "opensource", class: "xxlarge left" 17 = f.text_field :path, placeholder: "opensource", class: "xxlarge left"
18 - .clearfix  
19 - .input.span3.center  
20 - = f.submit 'Save team changes', class: "btn btn-primary"  
21 - .input.span3.center  
22 - = link_to 'Delete team', team_path(@team), method: :delete, confirm: "You are shure?", class: "btn btn-remove" 18 + .form-actions
  19 + = f.submit 'Save team changes', class: "btn btn-primary"
  20 + = link_to 'Delete team', team_path(@team), method: :delete, confirm: "You are shure?", class: "btn btn-remove pull-right"
config/routes.rb
@@ -129,7 +129,7 @@ Gitlab::Application.routes.draw do @@ -129,7 +129,7 @@ Gitlab::Application.routes.draw do
129 # 129 #
130 # Groups Area 130 # Groups Area
131 # 131 #
132 - resources :groups, constraints: { id: /[^\/]+/ }, only: [:show, :new, :create] do 132 + resources :groups, constraints: { id: /[^\/]+/ } do
133 member do 133 member do
134 get :issues 134 get :issues
135 get :merge_requests 135 get :merge_requests
features/group/group.feature
@@ -24,3 +24,9 @@ Feature: Groups @@ -24,3 +24,9 @@ Feature: Groups
24 When I visit group people page 24 When I visit group people page
25 And I select user "John" from list with role "Reporter" 25 And I select user "John" from list with role "Reporter"
26 Then I should see user "John" in team list 26 Then I should see user "John" in team list
  27 +
  28 + Scenario: I should see edit group page
  29 + When I visit group settings page
  30 + And I change group name
  31 + Then I should see new group name
  32 +
features/steps/group/group.rb
@@ -82,6 +82,17 @@ class Groups < Spinach::FeatureSteps @@ -82,6 +82,17 @@ class Groups < Spinach::FeatureSteps
82 current_path.should == group_path(Group.last) 82 current_path.should == group_path(Group.last)
83 end 83 end
84 84
  85 + And 'I change group name' do
  86 + fill_in 'group_name', :with => 'new-name'
  87 + click_button "Save group"
  88 + end
  89 +
  90 + Then 'I should see new group name' do
  91 + within ".navbar-gitlab" do
  92 + page.should have_content "group: new-name"
  93 + end
  94 + end
  95 +
85 protected 96 protected
86 97
87 def current_group 98 def current_group
features/steps/shared/paths.rb
@@ -25,6 +25,10 @@ module SharedPaths @@ -25,6 +25,10 @@ module SharedPaths
25 visit people_group_path(current_group) 25 visit people_group_path(current_group)
26 end 26 end
27 27
  28 + When 'I visit group settings page' do
  29 + visit edit_group_path(current_group)
  30 + end
  31 +
28 # ---------------------------------------- 32 # ----------------------------------------
29 # Dashboard 33 # Dashboard
30 # ---------------------------------------- 34 # ----------------------------------------