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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
1886d727
Commit
1886d727
authored
Jan 07, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add API project upload endpoint
parent
09216e8b
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
70 additions
and
23 deletions
+70
-23
app/assets/javascripts/dropzone_input.js.coffee
app/assets/javascripts/dropzone_input.js.coffee
+2
-12
app/services/projects/download_service.rb
app/services/projects/download_service.rb
+6
-1
app/services/projects/upload_service.rb
app/services/projects/upload_service.rb
+6
-1
doc/api/projects.md
doc/api/projects.md
+28
-0
lib/api/projects.rb
lib/api/projects.rb
+11
-1
lib/gitlab/email/receiver.rb
lib/gitlab/email/receiver.rb
+2
-5
lib/gitlab/fogbugz_import/importer.rb
lib/gitlab/fogbugz_import/importer.rb
+1
-3
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+14
-0
No files found.
app/assets/javascripts/dropzone_input.js.coffee
View file @
1886d727
...
@@ -66,7 +66,7 @@ class @DropzoneInput
...
@@ -66,7 +66,7 @@ class @DropzoneInput
success
:
(
header
,
response
)
->
success
:
(
header
,
response
)
->
child
=
$
(
dropzone
[
0
]).
children
(
"textarea"
)
child
=
$
(
dropzone
[
0
]).
children
(
"textarea"
)
$
(
child
).
val
$
(
child
).
val
()
+
formatLink
(
response
.
link
)
+
"
\n
"
$
(
child
).
val
$
(
child
).
val
()
+
response
.
link
.
markdown
+
"
\n
"
return
return
error
:
(
temp
,
errorMessage
)
->
error
:
(
temp
,
errorMessage
)
->
...
@@ -99,11 +99,6 @@ class @DropzoneInput
...
@@ -99,11 +99,6 @@ class @DropzoneInput
child
=
$
(
dropzone
[
0
]).
children
(
"textarea"
)
child
=
$
(
dropzone
[
0
]).
children
(
"textarea"
)
formatLink
=
(
link
)
->
text
=
"[
#{
link
.
alt
}
](
#{
link
.
url
}
)"
text
=
"!
#{
text
}
"
if
link
.
is_image
text
handlePaste
=
(
event
)
->
handlePaste
=
(
event
)
->
pasteEvent
=
event
.
originalEvent
pasteEvent
=
event
.
originalEvent
if
pasteEvent
.
clipboardData
and
pasteEvent
.
clipboardData
.
items
if
pasteEvent
.
clipboardData
and
pasteEvent
.
clipboardData
.
items
...
@@ -162,7 +157,7 @@ class @DropzoneInput
...
@@ -162,7 +157,7 @@ class @DropzoneInput
closeAlertMessage
()
closeAlertMessage
()
success
:
(
e
,
textStatus
,
response
)
->
success
:
(
e
,
textStatus
,
response
)
->
insertToTextArea
(
filename
,
formatLink
(
response
.
responseJSON
.
link
)
)
insertToTextArea
(
filename
,
response
.
responseJSON
.
link
.
markdown
)
error
:
(
response
)
->
error
:
(
response
)
->
showError
(
response
.
responseJSON
.
message
)
showError
(
response
.
responseJSON
.
message
)
...
@@ -202,8 +197,3 @@ class @DropzoneInput
...
@@ -202,8 +197,3 @@ class @DropzoneInput
e
.
preventDefault
()
e
.
preventDefault
()
$
(
@
).
closest
(
'.gfm-form'
).
find
(
'.div-dropzone'
).
click
()
$
(
@
).
closest
(
'.gfm-form'
).
find
(
'.div-dropzone'
).
click
()
return
return
formatLink
:
(
link
)
->
text
=
"[
#{
link
.
alt
}
](
#{
link
.
url
}
)"
text
=
"!
#{
text
}
"
if
link
.
is_image
text
app/services/projects/download_service.rb
View file @
1886d727
...
@@ -18,10 +18,15 @@ module Projects
...
@@ -18,10 +18,15 @@ module Projects
filename
=
uploader
.
image?
?
uploader
.
file
.
basename
:
uploader
.
file
.
filename
filename
=
uploader
.
image?
?
uploader
.
file
.
basename
:
uploader
.
file
.
filename
escaped_filename
=
filename
.
gsub
(
"]"
,
"
\\
]"
)
markdown
=
"[
#{
escaped_filename
}
](
#{
uploader
.
secure_url
}
)"
markdown
.
prepend
(
"!"
)
if
uploader
.
image?
{
{
'alt'
=>
filename
,
'alt'
=>
filename
,
'url'
=>
uploader
.
secure_url
,
'url'
=>
uploader
.
secure_url
,
'is_image'
=>
uploader
.
image?
'is_image'
=>
uploader
.
image?
,
'markdown'
=>
markdown
}
}
end
end
...
...
app/services/projects/upload_service.rb
View file @
1886d727
...
@@ -12,10 +12,15 @@ module Projects
...
@@ -12,10 +12,15 @@ module Projects
filename
=
uploader
.
image?
?
uploader
.
file
.
basename
:
uploader
.
file
.
filename
filename
=
uploader
.
image?
?
uploader
.
file
.
basename
:
uploader
.
file
.
filename
escaped_filename
=
filename
.
gsub
(
"]"
,
"
\\
]"
)
markdown
=
"[
#{
escaped_filename
}
](
#{
uploader
.
secure_url
}
)"
markdown
.
prepend
(
"!"
)
if
uploader
.
image?
{
{
alt:
filename
,
alt:
filename
,
url:
uploader
.
secure_url
,
url:
uploader
.
secure_url
,
is_image:
uploader
.
image?
is_image:
uploader
.
image?
,
markdown:
markdown
}
}
end
end
...
...
doc/api/projects.md
View file @
1886d727
...
@@ -482,6 +482,34 @@ Parameters:
...
@@ -482,6 +482,34 @@ Parameters:
-
`id`
(required) - The ID of a project
-
`id`
(required) - The ID of a project
## Uploads
### Upload a file
Uploads a file to the specified project to be used in an issue or merge request description, or a comment.
```
POST /projects/:id/uploads
```
Parameters:
-
`id`
(required) - The ID of the project
-
`file`
(required) - The file to be uploaded
```
json
{
"alt"
:
"dk"
,
"url"
:
"/uploads/66dbcd21ec5d24ed6ea225176098d52b/dk.png"
,
"is_image"
:
true
,
"markdown"
:
"![dk](/uploads/66dbcd21ec5d24ed6ea225176098d52b/dk.png)"
}
```
**Note**
: The returned
`url`
is relative to the project path.
In Markdown contexts, the link is automatically expanded when the format in
`markdown`
is used.
## Team members
## Team members
### List project team members
### List project team members
...
...
lib/api/projects.rb
View file @
1886d727
...
@@ -269,7 +269,7 @@ module API
...
@@ -269,7 +269,7 @@ module API
# Remove a forked_from relationship
# Remove a forked_from relationship
#
#
# Parameters:
# Parameters:
# id: (required) - The ID of the project being marked as a fork
#
id: (required) - The ID of the project being marked as a fork
# Example Request:
# Example Request:
# DELETE /projects/:id/fork
# DELETE /projects/:id/fork
delete
":id/fork"
do
delete
":id/fork"
do
...
@@ -278,6 +278,16 @@ module API
...
@@ -278,6 +278,16 @@ module API
user_project
.
forked_project_link
.
destroy
user_project
.
forked_project_link
.
destroy
end
end
end
end
# Upload a file
#
# Parameters:
# id: (required) - The ID of the project
# file: (required) - The file to be uploaded
post
":id/uploads"
do
::
Projects
::
UploadService
.
new
(
user_project
,
params
[
:file
]).
execute
end
# search for projects current_user has access to
# search for projects current_user has access to
#
#
# Parameters:
# Parameters:
...
...
lib/gitlab/email/receiver.rb
View file @
1886d727
...
@@ -74,7 +74,7 @@ module Gitlab
...
@@ -74,7 +74,7 @@ module Gitlab
def
sent_notification
def
sent_notification
return
nil
unless
reply_key
return
nil
unless
reply_key
SentNotification
.
for
(
reply_key
)
SentNotification
.
for
(
reply_key
)
end
end
...
@@ -82,10 +82,7 @@ module Gitlab
...
@@ -82,10 +82,7 @@ module Gitlab
attachments
=
Email
::
AttachmentUploader
.
new
(
message
).
execute
(
sent_notification
.
project
)
attachments
=
Email
::
AttachmentUploader
.
new
(
message
).
execute
(
sent_notification
.
project
)
attachments
.
each
do
|
link
|
attachments
.
each
do
|
link
|
text
=
"[
#{
link
[
:alt
]
}
](
#{
link
[
:url
]
}
)"
reply
<<
"
\n\n
#{
link
[
:markdown
]
}
"
text
.
prepend
(
"!"
)
if
link
[
:is_image
]
reply
<<
"
\n\n
#{
text
}
"
end
end
reply
reply
...
...
lib/gitlab/fogbugz_import/importer.rb
View file @
1886d727
...
@@ -232,9 +232,7 @@ module Gitlab
...
@@ -232,9 +232,7 @@ module Gitlab
return
nil
if
res
.
nil?
return
nil
if
res
.
nil?
text
=
"[
#{
res
[
'alt'
]
}
](
#{
res
[
'url'
]
}
)"
text
=
res
[
'markdown'
]
text
=
"!
#{
text
}
"
if
res
[
'is_image'
]
text
end
end
def
build_attachment_url
(
rel_url
)
def
build_attachment_url
(
rel_url
)
...
...
spec/requests/api/projects_spec.rb
View file @
1886d727
...
@@ -353,6 +353,20 @@ describe API::API, api: true do
...
@@ -353,6 +353,20 @@ describe API::API, api: true do
end
end
end
end
describe
"POST /projects/:id/uploads"
do
before
{
project
}
it
"uploads the file and returns its info"
do
post
api
(
"/projects/
#{
project
.
id
}
/uploads"
,
user
),
file:
fixture_file_upload
(
Rails
.
root
+
"spec/fixtures/dk.png"
,
"image/png"
)
expect
(
response
.
status
).
to
be
(
201
)
expect
(
json_response
[
'alt'
]).
to
eq
(
"dk"
)
expect
(
json_response
[
'url'
]).
to
start_with
(
"/uploads/"
)
expect
(
json_response
[
'url'
]).
to
end_with
(
"/dk.png"
)
expect
(
json_response
[
'is_image'
]).
to
eq
(
true
)
end
end
describe
'GET /projects/:id'
do
describe
'GET /projects/:id'
do
before
{
project
}
before
{
project
}
before
{
project_member
}
before
{
project_member
}
...
...
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