Commit f6c482c06f48449e7dcff34455b5bbdfbd8f6c7b

Authored by Dmitriy Zaporozhets
1 parent d9027df5

User can create group

app/controllers/groups_controller.rb
1 1 class GroupsController < ApplicationController
2 2 respond_to :html
3   - layout 'group'
  3 + layout 'group', except: [:new, :create]
4 4  
5   - before_filter :group
6   - before_filter :projects
  5 + before_filter :group, except: [:new, :create]
7 6  
8 7 # Authorize
9   - before_filter :authorize_read_group!
  8 + before_filter :authorize_read_group!, except: [:new, :create]
  9 +
  10 + # Load group projects
  11 + before_filter :projects, except: [:new, :create]
  12 +
  13 + def new
  14 + @group = Group.new
  15 + end
  16 +
  17 + def create
  18 + @group = Group.new(params[:group])
  19 + @group.path = @group.name.dup.parameterize if @group.name
  20 + @group.owner = current_user
  21 +
  22 + if @group.save
  23 + redirect_to @group, notice: 'Group was successfully created.'
  24 + else
  25 + render action: "new"
  26 + end
  27 + end
10 28  
11 29 def show
12 30 @events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0)
... ...
app/helpers/tab_helper.rb
... ... @@ -39,7 +39,12 @@ module TabHelper
39 39 # Returns a list item element String
40 40 def nav_link(options = {}, &block)
41 41 if path = options.delete(:path)
42   - c, a, _ = path.split('#')
  42 + if path.respond_to?(:each)
  43 + c = path.map { |p| p.split('#').first }
  44 + a = path.map { |p| p.split('#').last }
  45 + else
  46 + c, a, _ = path.split('#')
  47 + end
43 48 else
44 49 c = options.delete(:controller)
45 50 a = options.delete(:action)
... ...
app/models/user.rb
... ... @@ -220,7 +220,7 @@ class User &lt; ActiveRecord::Base
220 220 end
221 221  
222 222 def can_create_group?
223   - is_admin?
  223 + can_create_project?
224 224 end
225 225  
226 226 def abilities
... ...
app/views/dashboard/_groups.html.haml
... ... @@ -5,7 +5,7 @@
5 5 (#{groups.count})
6 6 - if current_user.can_create_group?
7 7 %span.right
8   - = link_to new_admin_group_path, class: "btn very_small info" do
  8 + = link_to new_group_path, class: "btn very_small info" do
9 9 %i.icon-plus
10 10 New Group
11 11 %ul.well-list
... ...
app/views/groups/new.html.haml 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +%h3.page_title New Group
  2 +%hr
  3 += form_for @group do |f|
  4 + - if @group.errors.any?
  5 + .alert-message.block-message.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 + &nbsp;
  13 + = f.submit 'Create group', class: "btn primary"
  14 + %hr
  15 + .padded
  16 + %ul
  17 + %li Group is kind of directory for several projects
  18 + %li All created groups are private
  19 + %li People within a group see only projects they have access to
  20 + %li All projects of group will be stored in group directory
  21 + %li You will be able to move existing projects into group
... ...
app/views/layouts/_head_panel.html.haml
... ... @@ -17,7 +17,7 @@
17 17 = link_to new_project_path, title: "Create New Project", class: 'has_bottom_tooltip', 'data-original-title' => 'New project' do
18 18 %i.icon-plus
19 19 %li
20   - = link_to profile_path, title: "Your Profile", class: 'has_bottom_tooltip', 'data-original-title' => 'Your profile' do
  20 + = link_to profile_path, title: "My Profile", class: 'has_bottom_tooltip', 'data-original-title' => 'Your profile' do
21 21 %i.icon-user
22 22 %li.separator
23 23 %li
... ...
app/views/projects/_new_form.html.haml
... ... @@ -15,6 +15,12 @@
15 15 %span Namespace
16 16 .input
17 17 = f.select :namespace_id, namespaces_options(params[:namespace_id] || :current_user), {}, {class: 'chosen'}
  18 + - elsif current_user.can_create_group?
  19 + .clearfix
  20 + .input.light
  21 + Need a group for several projects?
  22 + = link_to new_group_path, class: "btn very_small" do
  23 + Create a group
18 24 %hr
19 25 %p.padded
20 26 New projects are private by default. You choose who can see the project and commit to repository.
... ...
app/views/users/_profile.html.haml 0 → 100644
... ... @@ -0,0 +1,23 @@
  1 +.ui-box
  2 + %h5.title
  3 + Profile
  4 + %ul.well-list
  5 + %li
  6 + %strong Email
  7 + %span.right= mail_to @user.email
  8 + - unless @user.skype.blank?
  9 + %li
  10 + %strong Skype
  11 + %span.right= @user.skype
  12 + - unless @user.linkedin.blank?
  13 + %li
  14 + %strong LinkedIn
  15 + %span.right= @user.linkedin
  16 + - unless @user.twitter.blank?
  17 + %li
  18 + %strong Twitter
  19 + %span.right= @user.twitter
  20 + - unless @user.bio.blank?
  21 + %li
  22 + %strong Bio
  23 + %span.right= @user.bio
... ...
app/views/users/show.html.haml
... ... @@ -3,6 +3,11 @@
3 3 %h3.page_title
4 4 = image_tag gravatar_icon(@user.email, 90), class: "avatar s90"
5 5 = @user.name
  6 + - if @user == current_user
  7 + .right
  8 + = link_to profile_path, class: 'btn small' do
  9 + %i.icon-edit
  10 + Edit Profile
6 11 %br
7 12 %small @#{@user.username}
8 13 %br
... ... @@ -12,26 +17,5 @@
12 17 %h5 Recent events
13 18 = render @events
14 19 .span4
15   - .ui-box
16   - %h5.title Profile
17   - %ul.well-list
18   - %li
19   - %strong Email
20   - %span.right= mail_to @user.email
21   - - unless @user.skype.blank?
22   - %li
23   - %strong Skype
24   - %span.right= @user.skype
25   - - unless @user.linkedin.blank?
26   - %li
27   - %strong LinkedIn
28   - %span.right= @user.linkedin
29   - - unless @user.twitter.blank?
30   - %li
31   - %strong Twitter
32   - %span.right= @user.twitter
33   - - unless @user.bio.blank?
34   - %li
35   - %strong Bio
36   - %span.right= @user.bio
  20 + = render 'profile'
37 21 = render 'projects'
... ...
config/routes.rb
... ... @@ -112,7 +112,7 @@ Gitlab::Application.routes.draw do
112 112 #
113 113 # Groups Area
114 114 #
115   - resources :groups, constraints: { id: /[^\/]+/ }, only: [:show] do
  115 + resources :groups, constraints: { id: /[^\/]+/ }, only: [:show, :new, :create] do
116 116 member do
117 117 get :issues
118 118 get :merge_requests
... ...
features/group/create_group.feature 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +Feature: Groups
  2 + Background:
  3 + Given I sign in as a user
  4 +
  5 + Scenario: Create a group from dasboard
  6 + Given I have group with projects
  7 + And I visit dashboard page
  8 + When I click new group link
  9 + And submit form with new group info
  10 + Then I should be redirected to group page
  11 + And I should see newly created group
... ...
features/steps/group/group.rb
... ... @@ -64,6 +64,24 @@ class Groups &lt; Spinach::FeatureSteps
64 64 author: current_user
65 65 end
66 66  
  67 + When 'I click new group link' do
  68 + click_link "New Group"
  69 + end
  70 +
  71 + And 'submit form with new group info' do
  72 + fill_in 'group_name', :with => 'Samurai'
  73 + click_button "Create group"
  74 + end
  75 +
  76 + Then 'I should see newly created group' do
  77 + page.should have_content "Samurai"
  78 + page.should have_content "You will only see events from projects in this group"
  79 + end
  80 +
  81 + Then 'I should be redirected to group page' do
  82 + current_path.should == group_path(Group.last)
  83 + end
  84 +
67 85 protected
68 86  
69 87 def current_group
... ...