Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
ec20fdf3
Commit
ec20fdf3
authored
Mar 16, 2016
by
Felipe Artur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code improvements and add Create group service
parent
de251bcf
Changes
17
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
97 additions
and
84 deletions
+97
-84
app/assets/stylesheets/framework/common.scss
app/assets/stylesheets/framework/common.scss
+18
-28
app/assets/stylesheets/framework/mobile.scss
app/assets/stylesheets/framework/mobile.scss
+1
-1
app/assets/stylesheets/pages/projects.scss
app/assets/stylesheets/pages/projects.scss
+0
-22
app/controllers/groups_controller.rb
app/controllers/groups_controller.rb
+1
-3
app/controllers/users_controller.rb
app/controllers/users_controller.rb
+1
-8
app/finders/joined_groups_finder.rb
app/finders/joined_groups_finder.rb
+1
-1
app/models/ability.rb
app/models/ability.rb
+2
-2
app/services/groups/base_service.rb
app/services/groups/base_service.rb
+4
-0
app/services/groups/create_service.rb
app/services/groups/create_service.rb
+17
-0
app/services/groups/update_service.rb
app/services/groups/update_service.rb
+3
-10
app/services/projects/create_service.rb
app/services/projects/create_service.rb
+5
-1
app/views/groups/show.html.haml
app/views/groups/show.html.haml
+2
-2
app/views/projects/_home_panel.html.haml
app/views/projects/_home_panel.html.haml
+1
-1
db/migrate/20160308212903_add_default_group_visibility_to_application_settings.rb
...3_add_default_group_visibility_to_application_settings.rb
+18
-2
db/schema.rb
db/schema.rb
+1
-1
spec/features/security/group/internal_access_spec.rb
spec/features/security/group/internal_access_spec.rb
+0
-2
spec/services/groups/create_service_spec.rb
spec/services/groups/create_service_spec.rb
+22
-0
No files found.
app/assets/stylesheets/framework/common.scss
View file @
ec20fdf3
...
@@ -383,18 +383,8 @@ table {
...
@@ -383,18 +383,8 @@ table {
margin-right
:
-
$gl-padding
;
margin-right
:
-
$gl-padding
;
border-top
:
1px
solid
$border-color
;
border-top
:
1px
solid
$border-color
;
}
}
.message
{
border
:
1px
solid
#ccc
;
padding
:
10px
;
color
:
#333
;
}
.message
{
border
:
1px
solid
#ccc
;
padding
:
10px
;
color
:
#333
;
}
.
group-projects-show
-title
{
.
cover
-title
{
h1
{
h1
{
color
:
#313236
;
color
:
#313236
;
margin
:
0
;
margin
:
0
;
...
@@ -414,4 +404,4 @@ table {
...
@@ -414,4 +404,4 @@ table {
padding
:
0
$gl-padding
;
padding
:
0
$gl-padding
;
color
:
#5c5d5e
;
color
:
#5c5d5e
;
}
}
}
}
app/assets/stylesheets/framework/mobile.scss
View file @
ec20fdf3
...
@@ -48,7 +48,7 @@
...
@@ -48,7 +48,7 @@
display
:
block
;
display
:
block
;
}
}
.
project-home-desc
{
#
project-home-desc
{
font-size
:
21px
;
font-size
:
21px
;
}
}
...
...
app/assets/stylesheets/pages/projects.scss
View file @
ec20fdf3
...
@@ -61,28 +61,6 @@
...
@@ -61,28 +61,6 @@
}
}
}
}
.project-home-desc
{
h1
{
color
:
#313236
;
margin
:
0
;
margin-bottom
:
6px
;
font-size
:
23px
;
font-weight
:
normal
;
}
.visibility-icon
{
display
:
inline-block
;
margin-left
:
5px
;
font-size
:
18px
;
color
:
$gray
;
}
p
{
padding
:
0
$gl-padding
;
color
:
#5c5d5e
;
}
}
.project-repo-buttons
{
.project-repo-buttons
{
margin-top
:
20px
;
margin-top
:
20px
;
margin-bottom
:
0px
;
margin-bottom
:
0px
;
...
...
app/controllers/groups_controller.rb
View file @
ec20fdf3
...
@@ -29,10 +29,8 @@ class GroupsController < Groups::ApplicationController
...
@@ -29,10 +29,8 @@ class GroupsController < Groups::ApplicationController
def
create
def
create
@group
=
Group
.
new
(
group_params
)
@group
=
Group
.
new
(
group_params
)
@group
.
name
=
@group
.
path
.
dup
unless
@group
.
name
if
@group
.
save
if
Groups
::
CreateService
.
new
(
@group
,
current_user
,
group_params
).
execute
@group
.
add_owner
(
current_user
)
redirect_to
@group
,
notice:
"Group '
#{
@group
.
name
}
' was successfully created."
redirect_to
@group
,
notice:
"Group '
#{
@group
.
name
}
' was successfully created."
else
else
render
action:
"new"
render
action:
"new"
...
...
app/controllers/users_controller.rb
View file @
ec20fdf3
...
@@ -3,13 +3,6 @@ class UsersController < ApplicationController
...
@@ -3,13 +3,6 @@ class UsersController < ApplicationController
before_action
:set_user
before_action
:set_user
def
show
def
show
@contributed_projects
=
contributed_projects
.
joined
(
@user
).
reject
(
&
:forked?
)
@projects
=
PersonalProjectsFinder
.
new
(
@user
).
execute
(
current_user
)
@projects
=
@projects
.
page
(
params
[
:page
]).
per
(
PER_PAGE
)
@groups
=
JoinedGroupsFinder
.
new
(
@user
).
execute
(
current_user
)
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
html
format
.
html
...
@@ -115,7 +108,7 @@ class UsersController < ApplicationController
...
@@ -115,7 +108,7 @@ class UsersController < ApplicationController
end
end
def
load_groups
def
load_groups
@groups
=
@user
.
groups
.
order_id_desc
@groups
=
JoinedGroupsFinder
.
new
(
@user
).
execute
(
current_user
)
end
end
def
projects_for_current_user
def
projects_for_current_user
...
...
app/finders/joined_groups_finder.rb
View file @
ec20fdf3
#Shows only authorized groups of a user
#Shows only authorized groups of a user
class
JoinedGroupsFinder
class
JoinedGroupsFinder
def
initialize
(
user
=
nil
)
def
initialize
(
user
)
@user
=
user
@user
=
user
end
end
...
...
app/models/ability.rb
View file @
ec20fdf3
...
@@ -295,8 +295,8 @@ class Ability
...
@@ -295,8 +295,8 @@ class Ability
end
end
def
can_read_group?
(
user
,
group
)
def
can_read_group?
(
user
,
group
)
is_project_member
=
ProjectsFinder
.
new
.
execute
(
user
,
group:
group
).
any?
user
.
admin?
||
group
.
public?
||
group
.
internal?
||
group
.
users
.
include?
(
user
)
||
user
.
admin?
||
group
.
public?
||
group
.
internal?
||
is_project_member
||
group
.
users
.
include?
(
user
)
ProjectsFinder
.
new
.
execute
(
user
,
group:
group
).
any?
end
end
def
namespace_abilities
(
user
,
namespace
)
def
namespace_abilities
(
user
,
namespace
)
...
...
app/services/groups/base_service.rb
View file @
ec20fdf3
...
@@ -5,5 +5,9 @@ module Groups
...
@@ -5,5 +5,9 @@ module Groups
def
initialize
(
group
,
user
,
params
=
{})
def
initialize
(
group
,
user
,
params
=
{})
@group
,
@current_user
,
@params
=
group
,
user
,
params
.
dup
@group
,
@current_user
,
@params
=
group
,
user
,
params
.
dup
end
end
def
add_error_message
(
message
)
group
.
errors
.
add
(
:visibility_level
,
message
)
end
end
end
end
end
app/services/groups/create_service.rb
0 → 100644
View file @
ec20fdf3
module
Groups
class
CreateService
<
Groups
::
BaseService
def
execute
return
false
unless
visibility_level_allowed?
(
params
[
:visibility_level
])
@group
.
name
=
@group
.
path
.
dup
unless
@group
.
name
@group
.
save
(
params
)
&&
@group
.
add_owner
(
current_user
)
end
private
def
visibility_level_allowed?
(
level
)
allowed
=
Gitlab
::
VisibilityLevel
.
allowed_for?
(
current_user
,
params
[
:visibility_level
])
add_error_message
(
"Visibility level restricted by admin."
)
unless
allowed
allowed
end
end
end
app/services/groups/update_service.rb
View file @
ec20fdf3
...
@@ -5,7 +5,8 @@
...
@@ -5,7 +5,8 @@
module
Groups
module
Groups
class
UpdateService
<
Groups
::
BaseService
class
UpdateService
<
Groups
::
BaseService
def
execute
def
execute
visibility_level_allowed?
(
params
[
:visibility_level
])
?
group
.
update_attributes
(
params
)
:
false
return
false
unless
visibility_level_allowed?
(
params
[
:visibility_level
])
group
.
update_attributes
(
params
)
end
end
private
private
...
@@ -22,7 +23,7 @@ module Groups
...
@@ -22,7 +23,7 @@ module Groups
def
visibility_by_project
(
level
)
def
visibility_by_project
(
level
)
projects_visibility
=
group
.
projects
.
pluck
(
:visibility_level
)
projects_visibility
=
group
.
projects
.
pluck
(
:visibility_level
)
allowed_by_projects
=
!
projects_visibility
.
any?
{
|
project_visibility
|
level
.
to_i
<
project_visibility
}
allowed_by_projects
=
!
projects_visibility
.
any?
{
|
project_visibility
|
level
.
to_i
<
project_visibility
}
add_error_message
(
"Cannot be changed. There are projects with higher visibility permissions."
)
unless
allowed_by_projects
add_error_message
(
"Cannot be changed. There are projects with higher visibility permissions."
)
unless
allowed_by_projects
allowed_by_projects
allowed_by_projects
end
end
...
@@ -32,13 +33,5 @@ module Groups
...
@@ -32,13 +33,5 @@ module Groups
add_error_message
(
"You are not authorized to set this permission level."
)
unless
allowed_by_user
add_error_message
(
"You are not authorized to set this permission level."
)
unless
allowed_by_user
allowed_by_user
allowed_by_user
end
end
def
add_error_message
(
message
)
level_name
=
Gitlab
::
VisibilityLevel
.
level_name
(
params
[
:visibility_level
])
group
.
errors
.
add
(
:visibility_level
,
message
)
end
end
end
end
end
app/services/projects/create_service.rb
View file @
ec20fdf3
...
@@ -12,7 +12,7 @@ module Projects
...
@@ -12,7 +12,7 @@ module Projects
# Make sure that the user is allowed to use the specified visibility
# Make sure that the user is allowed to use the specified visibility
# level
# level
unless
Gitlab
::
VisibilityLevel
.
allowed_for?
(
current_user
,
params
[
:visibility_level
])
&&
@project
.
visibility_level_allowed?
(
@project
.
visibility_level
)
unless
visibility_level_allowed?
deny_visibility_level
(
@project
)
deny_visibility_level
(
@project
)
return
@project
return
@project
end
end
...
@@ -100,5 +100,9 @@ module Projects
...
@@ -100,5 +100,9 @@ module Projects
@project
.
import_start
if
@project
.
import?
@project
.
import_start
if
@project
.
import?
end
end
def
visibility_level_allowed?
Gitlab
::
VisibilityLevel
.
allowed_for?
(
current_user
,
params
[
:visibility_level
])
&&
@project
.
visibility_level_allowed?
(
@project
.
visibility_level
)
end
end
end
end
end
app/views/groups/show.html.haml
View file @
ec20fdf3
...
@@ -14,11 +14,11 @@
...
@@ -14,11 +14,11 @@
.avatar-holder
.avatar-holder
=
link_to
group_icon
(
@group
),
target:
'_blank'
do
=
link_to
group_icon
(
@group
),
target:
'_blank'
do
=
image_tag
group_icon
(
@group
),
class:
"avatar group-avatar s90"
=
image_tag
group_icon
(
@group
),
class:
"avatar group-avatar s90"
.
group-projects-show
-title
.
cover
-title
%h1
%h1
=
@group
.
name
=
@group
.
name
%span
.visibility-icon.has_tooltip
{
data:
{
container:
'body'
,
placement:
'left'
},
title:
"#{visibility_level_label(@group.visibility_level)} - #{
project_visibility_level_description(@group.visibility_level
)}"
}
%span
.visibility-icon.has_tooltip
{
data:
{
container:
'body'
,
placement:
'left'
},
title:
"#{visibility_level_label(@group.visibility_level)} - #{
group_visibility_description(@group
)}"
}
=
visibility_level_icon
(
@group
.
visibility_level
,
fw:
false
)
=
visibility_level_icon
(
@group
.
visibility_level
,
fw:
false
)
.cover-desc.username
.cover-desc.username
...
...
app/views/projects/_home_panel.html.haml
View file @
ec20fdf3
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
.project-home-panel.cover-block.clearfix
{
:class
=>
(
"empty-project"
if
empty_repo
)}
.project-home-panel.cover-block.clearfix
{
:class
=>
(
"empty-project"
if
empty_repo
)}
.project-identicon-holder
.project-identicon-holder
=
project_icon
(
@project
,
alt:
''
,
class:
'project-avatar avatar s90'
)
=
project_icon
(
@project
,
alt:
''
,
class:
'project-avatar avatar s90'
)
.
group-projects-show-title
.
cover-title
#project-home-desc
%h1
%h1
=
@project
.
name
=
@project
.
name
%span
.visibility-icon.has_tooltip
{
data:
{
container:
'body'
},
%span
.visibility-icon.has_tooltip
{
data:
{
container:
'body'
},
...
...
db/migrate/20160308212903_add_default_group_visibility_to_application_settings.rb
View file @
ec20fdf3
#Create visibility level field on DB
#Sets default_visibility_level to value on settings if not restricted
#If value is restricted takes higher visibility level allowed
class
AddDefaultGroupVisibilityToApplicationSettings
<
ActiveRecord
::
Migration
class
AddDefaultGroupVisibilityToApplicationSettings
<
ActiveRecord
::
Migration
def
up
def
up
add_column
:application_settings
,
:default_group_visibility
,
:integer
add_column
:application_settings
,
:default_group_visibility
,
:integer
visibility
=
Settings
.
gitlab
.
default_groups_features
[
'visibility_level'
]
execute
(
"update application_settings set default_group_visibility =
#{
allowed_visibility_level
}
"
)
execute
(
"update application_settings set default_group_visibility =
#{
visibility
}
"
)
end
end
def
down
def
down
remove_column
:application_settings
,
:default_group_visibility
remove_column
:application_settings
,
:default_group_visibility
end
end
private
def
allowed_visibility_level
default_visibility
=
Settings
.
gitlab
.
default_groups_features
[
'visibility_level'
]
restricted_levels
=
current_application_settings
.
restricted_visibility_levels
return
default_visibility
unless
restricted_levels
.
present?
if
restricted_levels
.
include?
(
default_visibility
)
Gitlab
::
VisibilityLevel
.
values
.
select
{
|
vis_level
|
vis_level
unless
restricted_levels
.
include?
(
vis_level
)
}.
last
else
default_visibility
end
end
end
end
db/schema.rb
View file @
ec20fdf3
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#
#
# It's strongly recommended that you check this file into your version control system.
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2016030
8212903
)
do
ActiveRecord
::
Schema
.
define
(
version:
2016030
9140734
)
do
# These are extensions that must be enabled in order to support this database
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
enable_extension
"plpgsql"
...
...
spec/features/security/group/internal_access_spec.rb
View file @
ec20fdf3
...
@@ -4,8 +4,6 @@ describe 'Internal group access', feature: true do
...
@@ -4,8 +4,6 @@ describe 'Internal group access', feature: true do
include
AccessMatchers
include
AccessMatchers
include
GroupAccessHelper
include
GroupAccessHelper
describe
'GET /groups/:path'
do
describe
'GET /groups/:path'
do
subject
{
group_path
(
group
(
Gitlab
::
VisibilityLevel
::
INTERNAL
))
}
subject
{
group_path
(
group
(
Gitlab
::
VisibilityLevel
::
INTERNAL
))
}
...
...
spec/services/groups/create_service_spec.rb
0 → 100644
View file @
ec20fdf3
require
'spec_helper'
describe
Groups
::
CreateService
,
services:
true
do
let!
(
:user
)
{
create
(
:user
)
}
let!
(
:private_group
)
{
create
(
:group
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PRIVATE
)
}
let!
(
:internal_group
)
{
create
(
:group
,
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
)
}
let!
(
:public_group
)
{
create
(
:group
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
)
}
describe
"execute"
do
let!
(
:service
)
{
described_class
.
new
(
public_group
,
user
,
visibility_level:
Gitlab
::
VisibilityLevel
::
PUBLIC
)
}
subject
{
service
.
execute
}
context
"create groups without restricted visibility level"
do
it
{
is_expected
.
to
be_truthy
}
end
context
"cannot create group with restricted visibility level"
do
before
{
allow
(
current_application_settings
).
to
receive
(
:restricted_visibility_levels
).
and_return
([
Gitlab
::
VisibilityLevel
::
PUBLIC
])
}
it
{
is_expected
.
to
be_falsy
}
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment