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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
b094855a
Commit
b094855a
authored
Jan 16, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
8b8a86c0
dedaec13
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
12 deletions
+96
-12
app/models/project.rb
app/models/project.rb
+14
-10
locale/gitlab.pot
locale/gitlab.pot
+6
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+76
-2
No files found.
app/models/project.rb
View file @
b094855a
...
...
@@ -331,7 +331,7 @@ class Project < ActiveRecord::Base
ports:
->
(
project
)
{
project
.
persisted?
?
VALID_MIRROR_PORTS
:
VALID_IMPORT_PORTS
},
enforce_user:
true
},
if:
[
:external_import?
,
:import_url_changed?
]
validates
:star_count
,
numericality:
{
greater_than_or_equal_to:
0
}
validate
:check_limit
,
on: :create
validate
:check_
personal_projects_
limit
,
on: :create
validate
:check_repository_path_availability
,
on: :update
,
if:
->
(
project
)
{
project
.
renamed?
}
validate
:visibility_level_allowed_by_group
,
if:
->
{
changes
.
has_key?
(
:visibility_level
)
}
validate
:visibility_level_allowed_as_fork
,
if:
->
{
changes
.
has_key?
(
:visibility_level
)
}
...
...
@@ -809,18 +809,22 @@ class Project < ActiveRecord::Base
::
Gitlab
::
CurrentSettings
.
mirror_available
end
def
check_limit
unless
creator
.
can_create_project?
||
namespace
.
kind
==
'group'
projects_limit
=
creator
.
projects_limit
def
check_personal_projects_limit
# Since this method is called as validation hook, `creator` might not be
# present. Since the validation for that will fail, we can just return
# early.
return
if
!
creator
||
creator
.
can_create_project?
||
namespace
.
kind
==
'group'
if
projects_limit
==
0
self
.
errors
.
add
(
:limit_reached
,
"Personal project creation is not allowed. Please contact your administrator with questions"
)
limit
=
creator
.
projects_limit
error
=
if
limit
.
zero?
_
(
'Personal project creation is not allowed. Please contact your administrator with questions'
)
else
self
.
errors
.
add
(
:limit_reached
,
"Your project limit is
#{
projects_limit
}
projects! Please contact your administrator to increase it"
)
_
(
'Your project limit is %{limit} projects! Please contact your administrator to increase it'
)
end
end
rescue
self
.
errors
.
add
(
:base
,
"Can't check your ability to create project"
)
self
.
errors
.
add
(
:limit_reached
,
error
%
{
limit:
limit
})
end
def
visibility_level_allowed_by_group
...
...
locale/gitlab.pot
View file @
b094855a
...
...
@@ -6485,6 +6485,9 @@ msgstr ""
msgid "Personal Access Token"
msgstr ""
msgid "Personal project creation is not allowed. Please contact your administrator with questions"
msgstr ""
msgid "Pick a name"
msgstr ""
...
...
@@ -10506,6 +10509,9 @@ msgstr ""
msgid "Your name"
msgstr ""
msgid "Your project limit is %{limit} projects! Please contact your administrator to increase it"
msgstr ""
msgid "Your projects"
msgstr ""
...
...
spec/models/project_spec.rb
View file @
b094855a
...
...
@@ -213,9 +213,14 @@ describe Project do
it
'does not allow new projects beyond user limits'
do
project2
=
build
(
:project
)
allow
(
project2
).
to
receive
(
:creator
).
and_return
(
double
(
can_create_project?:
false
,
projects_limit:
0
).
as_null_object
)
allow
(
project2
)
.
to
receive
(
:creator
)
.
and_return
(
double
(
can_create_project?:
false
,
projects_limit:
0
).
as_null_object
)
expect
(
project2
).
not_to
be_valid
expect
(
project2
.
errors
[
:limit_reached
].
first
).
to
match
(
/Personal project creation is not allowed/
)
end
describe
'wiki path conflict'
do
...
...
@@ -4712,6 +4717,75 @@ describe Project do
end
end
describe
'#check_personal_projects_limit'
do
context
'when creating a project for a group'
do
it
'does nothing'
do
creator
=
build
(
:user
)
project
=
build
(
:project
,
namespace:
build
(
:group
),
creator:
creator
)
allow
(
creator
)
.
to
receive
(
:can_create_project?
)
.
and_return
(
false
)
project
.
check_personal_projects_limit
expect
(
project
.
errors
).
to
be_empty
end
end
context
'when the user is not allowed to create a personal project'
do
let
(
:user
)
{
build
(
:user
)
}
let
(
:project
)
{
build
(
:project
,
creator:
user
)
}
before
do
allow
(
user
)
.
to
receive
(
:can_create_project?
)
.
and_return
(
false
)
end
context
'when the project limit is zero'
do
it
'adds a validation error'
do
allow
(
user
)
.
to
receive
(
:projects_limit
)
.
and_return
(
0
)
project
.
check_personal_projects_limit
expect
(
project
.
errors
[
:limit_reached
].
first
)
.
to
match
(
/Personal project creation is not allowed/
)
end
end
context
'when the project limit is greater than zero'
do
it
'adds a validation error'
do
allow
(
user
)
.
to
receive
(
:projects_limit
)
.
and_return
(
5
)
project
.
check_personal_projects_limit
expect
(
project
.
errors
[
:limit_reached
].
first
)
.
to
match
(
/Your project limit is 5 projects/
)
end
end
end
context
'when the user is allowed to create personal projects'
do
it
'does nothing'
do
user
=
build
(
:user
)
project
=
build
(
:project
,
creator:
user
)
allow
(
user
)
.
to
receive
(
:can_create_project?
)
.
and_return
(
true
)
project
.
check_personal_projects_limit
expect
(
project
.
errors
).
to
be_empty
end
end
end
def
rugged_config
rugged_repo
(
project
.
repository
).
config
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