Skip to content

Commit f6c482c

Browse files
committed
User can create group
1 parent d9027df commit f6c482c

File tree

12 files changed

+117
-31
lines changed

12 files changed

+117
-31
lines changed

app/controllers/groups_controller.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
class GroupsController < ApplicationController
22
respond_to :html
3-
layout 'group'
3+
layout 'group', except: [:new, :create]
44

5-
before_filter :group
6-
before_filter :projects
5+
before_filter :group, except: [:new, :create]
76

87
# 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
1028

1129
def show
1230
@events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0)

app/helpers/tab_helper.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ module TabHelper
3939
# Returns a list item element String
4040
def nav_link(options = {}, &block)
4141
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
4348
else
4449
c = options.delete(:controller)
4550
a = options.delete(:action)

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def can_create_project?
220220
end
221221

222222
def can_create_group?
223-
is_admin?
223+
can_create_project?
224224
end
225225

226226
def abilities

app/views/dashboard/_groups.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
(#{groups.count})
66
- if current_user.can_create_group?
77
%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
99
%i.icon-plus
1010
New Group
1111
%ul.well-list

app/views/groups/new.html.haml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
= link_to new_project_path, title: "Create New Project", class: 'has_bottom_tooltip', 'data-original-title' => 'New project' do
1818
%i.icon-plus
1919
%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
2121
%i.icon-user
2222
%li.separator
2323
%li

app/views/projects/_new_form.html.haml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
%span Namespace
1616
.input
1717
= 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
1824
%hr
1925
%p.padded
2026
New projects are private by default. You choose who can see the project and commit to repository.

app/views/users/_profile.html.haml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
%h3.page_title
44
= image_tag gravatar_icon(@user.email, 90), class: "avatar s90"
55
= @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
611
%br
712
%small @#{@user.username}
813
%br
@@ -12,26 +17,5 @@
1217
%h5 Recent events
1318
= render @events
1419
.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'
3721
= render 'projects'

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
#
113113
# Groups Area
114114
#
115-
resources :groups, constraints: { id: /[^\/]+/ }, only: [:show] do
115+
resources :groups, constraints: { id: /[^\/]+/ }, only: [:show, :new, :create] do
116116
member do
117117
get :issues
118118
get :merge_requests

0 commit comments

Comments
 (0)