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
Léo-Paul Géneau
gitlab-ce
Commits
93bacb03
Commit
93bacb03
authored
Mar 01, 2015
by
Jeroen van Baarsen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8890 from sue445/feature/project_api_avatar_url
Expose avatar_url in projects API
parents
7486bc0a
51abeaa1
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
55 additions
and
9 deletions
+55
-9
CHANGELOG
CHANGELOG
+1
-0
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+2
-4
app/models/project.rb
app/models/project.rb
+10
-0
doc/api/projects.md
doc/api/projects.md
+6
-3
lib/api/entities.rb
lib/api/entities.rb
+1
-0
spec/helpers/application_helper_spec.rb
spec/helpers/application_helper_spec.rb
+4
-2
spec/models/project_spec.rb
spec/models/project_spec.rb
+31
-0
No files found.
CHANGELOG
View file @
93bacb03
...
@@ -10,6 +10,7 @@ v 7.9.0 (unreleased)
...
@@ -10,6 +10,7 @@ v 7.9.0 (unreleased)
- Save web edit in new branch
- Save web edit in new branch
- Fix ordering of imported but unchanged projects (Marco Wessel)
- Fix ordering of imported but unchanged projects (Marco Wessel)
- Mobile UI improvements: make aside content expandable
- Mobile UI improvements: make aside content expandable
- Expose avatar_url in projects API
- Generalize image upload in drag and drop in markdown to all files (Hannes Rosenögger)
- Generalize image upload in drag and drop in markdown to all files (Hannes Rosenögger)
- Fix mass-unassignment of issues (Robert Speicher)
- Fix mass-unassignment of issues (Robert Speicher)
- Allow user confirmation to be skipped for new users via API
- Allow user confirmation to be skipped for new users via API
...
...
app/helpers/application_helper.rb
View file @
93bacb03
...
@@ -58,10 +58,8 @@ module ApplicationHelper
...
@@ -58,10 +58,8 @@ module ApplicationHelper
Project
.
find_with_namespace
(
project_id
)
Project
.
find_with_namespace
(
project_id
)
end
end
if
project
.
avatar
.
present?
if
project
.
avatar_url
image_tag
project
.
avatar
.
url
,
options
image_tag
project
.
avatar_url
,
options
elsif
project
.
avatar_in_git
image_tag
namespace_project_avatar_path
(
project
.
namespace
,
project
),
options
else
# generated icon
else
# generated icon
project_identicon
(
project
,
options
)
project_identicon
(
project
,
options
)
end
end
...
...
app/models/project.rb
View file @
93bacb03
...
@@ -37,6 +37,8 @@ class Project < ActiveRecord::Base
...
@@ -37,6 +37,8 @@ class Project < ActiveRecord::Base
include
Gitlab
::
ShellAdapter
include
Gitlab
::
ShellAdapter
include
Gitlab
::
VisibilityLevel
include
Gitlab
::
VisibilityLevel
include
Gitlab
::
ConfigHelper
include
Gitlab
::
ConfigHelper
include
Rails
.
application
.
routes
.
url_helpers
extend
Gitlab
::
ConfigHelper
extend
Gitlab
::
ConfigHelper
extend
Enumerize
extend
Enumerize
...
@@ -408,6 +410,14 @@ class Project < ActiveRecord::Base
...
@@ -408,6 +410,14 @@ class Project < ActiveRecord::Base
@avatar_file
@avatar_file
end
end
def
avatar_url
if
avatar
.
present?
[
gitlab_config
.
url
,
avatar
.
url
].
join
elsif
avatar_in_git
[
gitlab_config
.
url
,
namespace_project_avatar_path
(
namespace
,
self
)].
join
end
end
# For compatibility with old code
# For compatibility with old code
def
code
def
code
path
path
...
...
doc/api/projects.md
View file @
93bacb03
...
@@ -68,7 +68,8 @@ Parameters:
...
@@ -68,7 +68,8 @@ Parameters:
"path"
:
"diaspora"
,
"path"
:
"diaspora"
,
"updated_at"
:
"2013-09-30T13: 46: 02Z"
"updated_at"
:
"2013-09-30T13: 46: 02Z"
},
},
"archived"
:
false
"archived"
:
false
,
"avatar_url"
:
"http://example.com/uploads/project/avatar/4/uploads/avatar.png"
},
},
{
{
"id"
:
6
,
"id"
:
6
,
...
@@ -103,7 +104,8 @@ Parameters:
...
@@ -103,7 +104,8 @@ Parameters:
"path"
:
"brightbox"
,
"path"
:
"brightbox"
,
"updated_at"
:
"2013-09-30T13:46:02Z"
"updated_at"
:
"2013-09-30T13:46:02Z"
},
},
"archived"
:
false
"archived"
:
false
,
"avatar_url"
:
null
}
}
]
]
```
```
...
@@ -195,7 +197,8 @@ Parameters:
...
@@ -195,7 +197,8 @@ Parameters:
"notification_level"
:
3
"notification_level"
:
3
}
}
},
},
"archived"
:
false
"archived"
:
false
,
"avatar_url"
:
"http://example.com/uploads/project/avatar/3/uploads/avatar.png"
}
}
```
```
...
...
lib/api/entities.rb
View file @
93bacb03
...
@@ -56,6 +56,7 @@ module API
...
@@ -56,6 +56,7 @@ module API
expose
:issues_enabled
,
:merge_requests_enabled
,
:wiki_enabled
,
:snippets_enabled
,
:created_at
,
:last_activity_at
expose
:issues_enabled
,
:merge_requests_enabled
,
:wiki_enabled
,
:snippets_enabled
,
:created_at
,
:last_activity_at
expose
:namespace
expose
:namespace
expose
:forked_from_project
,
using:
Entities
::
ForkedFromProject
,
if:
lambda
{
|
project
,
options
|
project
.
forked?
}
expose
:forked_from_project
,
using:
Entities
::
ForkedFromProject
,
if:
lambda
{
|
project
,
options
|
project
.
forked?
}
expose
:avatar_url
end
end
class
ProjectMember
<
UserBasic
class
ProjectMember
<
UserBasic
...
...
spec/helpers/application_helper_spec.rb
View file @
93bacb03
...
@@ -64,8 +64,9 @@ describe ApplicationHelper do
...
@@ -64,8 +64,9 @@ describe ApplicationHelper do
project
=
create
(
:project
)
project
=
create
(
:project
)
project
.
avatar
=
File
.
open
(
avatar_file_path
)
project
.
avatar
=
File
.
open
(
avatar_file_path
)
project
.
save!
project
.
save!
avatar_url
=
"http://localhost/uploads/project/avatar/
#{
project
.
id
}
/gitlab_logo.png"
expect
(
project_icon
(
"
#{
project
.
namespace
.
to_param
}
/
#{
project
.
to_param
}
"
).
to_s
).
to
eq
(
expect
(
project_icon
(
"
#{
project
.
namespace
.
to_param
}
/
#{
project
.
to_param
}
"
).
to_s
).
to
eq
(
"<img alt=
\"
Gitlab logo
\"
src=
\"
/uploads/project/avatar/
#{
project
.
id
}
/gitlab_logo.png
\"
/>"
"<img alt=
\"
Gitlab logo
\"
src=
\"
#{
avatar_url
}
\"
/>"
)
)
end
end
...
@@ -75,8 +76,9 @@ describe ApplicationHelper do
...
@@ -75,8 +76,9 @@ describe ApplicationHelper do
allow_any_instance_of
(
Project
).
to
receive
(
:avatar_in_git
).
and_return
(
true
)
allow_any_instance_of
(
Project
).
to
receive
(
:avatar_in_git
).
and_return
(
true
)
avatar_url
=
'http://localhost'
+
namespace_project_avatar_path
(
project
.
namespace
,
project
)
expect
(
project_icon
(
"
#{
project
.
namespace
.
to_param
}
/
#{
project
.
to_param
}
"
).
to_s
).
to
match
(
expect
(
project_icon
(
"
#{
project
.
namespace
.
to_param
}
/
#{
project
.
to_param
}
"
).
to_s
).
to
match
(
image_tag
(
namespace_project_avatar_path
(
project
.
namespace
,
project
)
))
image_tag
(
avatar_url
))
end
end
end
end
...
...
spec/models/project_spec.rb
View file @
93bacb03
...
@@ -326,4 +326,35 @@ describe Project do
...
@@ -326,4 +326,35 @@ describe Project do
expect
(
project
.
avatar_type
).
to
eq
([
'only images allowed'
])
expect
(
project
.
avatar_type
).
to
eq
([
'only images allowed'
])
end
end
end
end
describe
:avatar_url
do
subject
{
project
.
avatar_url
}
let
(
:project
)
{
create
(
:project
)
}
context
'When avatar file is uploaded'
do
before
do
project
.
update_columns
(
avatar:
'uploads/avatar.png'
)
allow
(
project
.
avatar
).
to
receive
(
:present?
)
{
true
}
end
let
(
:avatar_path
)
do
"/uploads/project/avatar/
#{
project
.
id
}
/uploads/avatar.png"
end
it
{
should
eq
"http://localhost
#{
avatar_path
}
"
}
end
context
'When avatar file in git'
do
before
do
allow
(
project
).
to
receive
(
:avatar_in_git
)
{
true
}
end
let
(
:avatar_path
)
do
"/
#{
project
.
namespace
.
name
}
/
#{
project
.
path
}
/avatar"
end
it
{
should
eq
"http://localhost
#{
avatar_path
}
"
}
end
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