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
Boxiang Sun
gitlab-ce
Commits
93aa6d04
Commit
93aa6d04
authored
Sep 29, 2017
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved fork checks into policies
parent
8585ae61
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
9 deletions
+61
-9
app/policies/global_policy.rb
app/policies/global_policy.rb
+6
-0
app/policies/namespace_policy.rb
app/policies/namespace_policy.rb
+4
-0
app/views/projects/buttons/_fork.html.haml
app/views/projects/buttons/_fork.html.haml
+3
-3
app/views/projects/forks/new.html.haml
app/views/projects/forks/new.html.haml
+5
-6
spec/policies/global_policy_spec.rb
spec/policies/global_policy_spec.rb
+23
-0
spec/policies/namespace_policy_spec.rb
spec/policies/namespace_policy_spec.rb
+20
-0
No files found.
app/policies/global_policy.rb
View file @
93aa6d04
...
...
@@ -11,6 +11,8 @@ class GlobalPolicy < BasePolicy
with_options
scope: :user
,
score:
0
condition
(
:access_locked
)
{
@user
.
access_locked?
}
condition
(
:can_create_fork
,
scope: :user
)
{
@user
.
manageable_namespaces
.
any?
{
|
namespace
|
@user
.
can?
(
:create_projects
,
namespace
)
}
}
rule
{
anonymous
}.
policy
do
prevent
:log_in
prevent
:access_api
...
...
@@ -40,6 +42,10 @@ class GlobalPolicy < BasePolicy
enable
:create_group
end
rule
{
can_create_fork
}.
policy
do
enable
:create_fork
end
rule
{
access_locked
}.
policy
do
prevent
:log_in
end
...
...
app/policies/namespace_policy.rb
View file @
93aa6d04
class
NamespacePolicy
<
BasePolicy
rule
{
anonymous
}.
prevent_all
condition
(
:personal_project
,
scope: :subject
)
{
@subject
.
kind
==
'user'
}
condition
(
:can_create_personal_project
,
scope: :user
)
{
@user
.
can_create_project?
}
condition
(
:owner
)
{
@subject
.
owner
==
@user
}
rule
{
owner
|
admin
}.
policy
do
enable
:create_projects
enable
:admin_namespace
end
rule
{
personal_project
&
~
can_create_personal_project
}.
prevent
:create_projects
end
app/views/projects/buttons/_fork.html.haml
View file @
93aa6d04
...
...
@@ -5,10 +5,10 @@
=
custom_icon
(
'icon_fork'
)
%span
=
s_
(
'GoToYourFork|Fork'
)
-
else
-
can_
fork
=
current_user
.
can_create_project?
||
current_user
.
manageable_namespaces
.
count
>
1
-
can_
create_fork
=
current_user
.
can?
(
:create_fork
)
=
link_to
new_project_fork_path
(
@project
),
class:
"btn btn-default
#{
'has-tooltip disabled'
unless
can_fork
}
"
,
title:
(
_
(
'You have reached your project limit'
)
unless
can_fork
)
do
class:
"btn btn-default
#{
'has-tooltip disabled'
unless
can_
create_
fork
}
"
,
title:
(
_
(
'You have reached your project limit'
)
unless
can_
create_
fork
)
do
=
custom_icon
(
'icon_fork'
)
%span
=
s_
(
'CreateNewFork|Fork'
)
.count-with-arrow
...
...
app/views/projects/forks/new.html.haml
View file @
93aa6d04
-
page_title
"Fork project"
-
can_create_project
=
current_user
.
can_create_project?
.row.prepend-top-default
.col-lg-3
...
...
@@ -14,7 +13,7 @@
-
if
@namespaces
.
present?
%label
.label-light
%span
#{
"Click to fork the project to a #{'user or' if can_create_project} group"
}
Click to fork the project
-
@namespaces
.
in_groups_of
(
6
,
false
)
do
|
group
|
.row
-
group
.
each
do
|
namespace
|
...
...
@@ -30,12 +29,12 @@
.caption
=
namespace
.
human_name
-
else
-
is_disabled
=
namespace
.
kind
===
'user'
&&
!
can_create_project
.fork-thumbnail
{
class:
(
"disabled"
if
is_disabled
)
}
-
can_create_project
=
current_user
.
can?
(
:create_projects
,
namespace
)
.fork-thumbnail
{
class:
(
"disabled"
unless
can_create_project
)
}
=
link_to
project_forks_path
(
@project
,
namespace_key:
namespace
.
id
),
method:
"POST"
,
class:
(
"disabled has-tooltip"
if
is_disabled
),
title:
(
_
(
'You have reached your project limit'
)
if
is_disabled
)
do
class:
(
"disabled has-tooltip"
unless
can_create_project
),
title:
(
_
(
'You have reached your project limit'
)
unless
can_create_project
)
do
-
if
/no_((\w*)_)*avatar/
.
match
(
avatar
)
.no-avatar
=
icon
'question'
...
...
spec/policies/global_policy_spec.rb
View file @
93aa6d04
...
...
@@ -52,6 +52,29 @@ describe GlobalPolicy do
end
end
describe
"create fork"
do
context
"when user has not exceeded project limit"
do
it
{
is_expected
.
to
be_allowed
(
:create_fork
)
}
end
context
"when user has exceeded project limit"
do
let
(
:current_user
)
{
create
(
:user
,
projects_limit:
0
)
}
it
{
is_expected
.
not_to
be_allowed
(
:create_fork
)
}
end
context
"when user is a master in a group"
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:current_user
)
{
create
(
:user
,
projects_limit:
0
)
}
before
do
group
.
add_master
(
current_user
)
end
it
{
is_expected
.
to
be_allowed
(
:create_fork
)
}
end
end
describe
'custom attributes'
do
context
'regular user'
do
it
{
is_expected
.
not_to
be_allowed
(
:read_custom_attribute
)
}
...
...
spec/policies/namespace_policy_spec.rb
0 → 100644
View file @
93aa6d04
require
'spec_helper'
describe
NamespacePolicy
do
let
(
:current_user
)
{
create
(
:user
)
}
let
(
:namespace
)
{
current_user
.
namespace
}
subject
{
described_class
.
new
(
current_user
,
namespace
)
}
context
"create projects"
do
context
"user namespace"
do
it
{
is_expected
.
to
be_allowed
(
:create_projects
)
}
end
context
"user who has exceeded project limit"
do
let
(
:current_user
)
{
create
(
:user
,
projects_limit:
0
)
}
it
{
is_expected
.
not_to
be_allowed
(
:create_projects
)
}
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