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
4f5ed812
Commit
4f5ed812
authored
Nov 24, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: Introduce `#find_project!` which also check access permission
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
304163be
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
lib/api/helpers.rb
lib/api/helpers.rb
+10
-7
lib/api/projects.rb
lib/api/projects.rb
+1
-1
No files found.
lib/api/helpers.rb
View file @
4f5ed812
...
@@ -68,7 +68,7 @@ module API
...
@@ -68,7 +68,7 @@ module API
end
end
def
user_project
def
user_project
@project
||=
find_project
(
params
[
:id
])
@project
||=
find_project
!
(
params
[
:id
])
end
end
def
available_labels
def
available_labels
...
@@ -76,12 +76,15 @@ module API
...
@@ -76,12 +76,15 @@ module API
end
end
def
find_project
(
id
)
def
find_project
(
id
)
project
=
if
id
=~
/^\d+$/
if
id
=~
/^\d+$/
Project
.
find_by
(
id:
id
)
Project
.
find_by
(
id:
id
)
else
else
Project
.
find_with_namespace
(
id
)
Project
.
find_with_namespace
(
id
)
end
end
end
def
find_project!
(
id
)
project
=
find_project
(
id
)
if
can?
(
current_user
,
:read_project
,
project
)
if
can?
(
current_user
,
:read_project
,
project
)
project
project
...
...
lib/api/projects.rb
View file @
4f5ed812
...
@@ -379,7 +379,7 @@ module API
...
@@ -379,7 +379,7 @@ module API
# POST /projects/:id/fork/:forked_from_id
# POST /projects/:id/fork/:forked_from_id
post
":id/fork/:forked_from_id"
do
post
":id/fork/:forked_from_id"
do
authenticated_as_admin!
authenticated_as_admin!
forked_from_project
=
find_project
(
params
[
:forked_from_id
])
forked_from_project
=
find_project
!
(
params
[
:forked_from_id
])
unless
forked_from_project
.
nil?
unless
forked_from_project
.
nil?
if
user_project
.
forked_from_project
.
nil?
if
user_project
.
forked_from_project
.
nil?
user_project
.
create_forked_project_link
(
forked_to_project_id:
user_project
.
id
,
forked_from_project_id:
forked_from_project
.
id
)
user_project
.
create_forked_project_link
(
forked_to_project_id:
user_project
.
id
,
forked_from_project_id:
forked_from_project
.
id
)
...
...
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