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
e40d626b
Commit
e40d626b
authored
Aug 09, 2018
by
George Tsiolis
Committed by
Rémy Coutable
Aug 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add default avatar to group
parent
d90676b1
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
99 additions
and
50 deletions
+99
-50
app/assets/stylesheets/framework/avatar.scss
app/assets/stylesheets/framework/avatar.scss
+1
-0
app/assets/stylesheets/pages/projects.scss
app/assets/stylesheets/pages/projects.scss
+0
-4
app/helpers/avatars_helper.rb
app/helpers/avatars_helper.rb
+31
-21
app/helpers/groups_helper.rb
app/helpers/groups_helper.rb
+0
-5
app/views/projects/forks/_fork_button.html.haml
app/views/projects/forks/_fork_button.html.haml
+2
-2
changelogs/unreleased/feat-add-default-avatar-to-group.yml
changelogs/unreleased/feat-add-default-avatar-to-group.yml
+5
-0
spec/helpers/avatars_helper_spec.rb
spec/helpers/avatars_helper_spec.rb
+60
-5
spec/helpers/groups_helper_spec.rb
spec/helpers/groups_helper_spec.rb
+0
-13
No files found.
app/assets/stylesheets/framework/avatar.scss
View file @
e40d626b
...
...
@@ -103,6 +103,7 @@
display
:
flex
;
a
{
width
:
100%
;
display
:
flex
;
}
...
...
app/assets/stylesheets/pages/projects.scss
View file @
e40d626b
...
...
@@ -823,10 +823,6 @@ pre.light-well {
.avatar-container
{
align-self
:
flex-start
;
>
a
{
width
:
100%
;
}
}
.project-details
{
...
...
app/helpers/avatars_helper.rb
View file @
e40d626b
module
AvatarsHelper
def
project_icon
(
project_id
,
options
=
{})
project
=
if
project_id
.
respond_to?
(
:avatar_url
)
project_id
else
Project
.
find_by_full_path
(
project_id
)
end
if
project
.
avatar_url
image_tag
project
.
avatar_url
,
options
else
# generated icon
project_identicon
(
project
,
options
)
end
source_icon
(
Project
,
project_id
,
options
)
end
def
project_identicon
(
project
,
options
=
{})
bg_key
=
(
project
.
id
%
7
)
+
1
options
[
:class
]
||=
''
options
[
:class
]
<<
' identicon'
options
[
:class
]
<<
" bg
#{
bg_key
}
"
content_tag
(
:div
,
class:
options
[
:class
])
do
project
.
name
[
0
,
1
].
upcase
end
def
group_icon
(
group_id
,
options
=
{})
source_icon
(
Group
,
group_id
,
options
)
end
# Takes both user and email and returns the avatar_icon by
...
...
@@ -123,4 +105,32 @@ module AvatarsHelper
mail_to
(
options
[
:user_email
],
avatar
)
end
end
private
def
source_icon
(
klass
,
source_id
,
options
=
{})
source
=
if
source_id
.
respond_to?
(
:avatar_url
)
source_id
else
klass
.
find_by_full_path
(
source_id
)
end
if
source
.
avatar_url
image_tag
source
.
avatar_url
,
options
else
source_identicon
(
source
,
options
)
end
end
def
source_identicon
(
source
,
options
=
{})
bg_key
=
(
source
.
id
%
7
)
+
1
options
[
:class
]
||=
''
options
[
:class
]
<<
' identicon'
options
[
:class
]
<<
" bg
#{
bg_key
}
"
content_tag
(
:div
,
class:
options
[
:class
].
strip
)
do
source
.
name
[
0
,
1
].
upcase
end
end
end
app/helpers/groups_helper.rb
View file @
e40d626b
...
...
@@ -33,11 +33,6 @@ module GroupsHelper
.
count
end
def
group_icon
(
group
,
options
=
{})
img_path
=
group_icon_url
(
group
,
options
)
image_tag
img_path
,
options
end
def
group_icon_url
(
group
,
options
=
{})
if
group
.
is_a?
(
String
)
group
=
Group
.
find_by_full_path
(
group
)
...
...
app/views/projects/forks/_fork_button.html.haml
View file @
e40d626b
...
...
@@ -5,7 +5,7 @@
.bordered-box.fork-thumbnail.text-center.prepend-left-default.append-right-default.prepend-top-default.append-bottom-default.forked
=
link_to
project_path
(
forked_project
)
do
-
if
/no_((\w*)_)*avatar/
.
match
(
avatar
)
=
project_i
denti
con
(
namespace
,
class:
"avatar s100 identicon"
)
=
project_icon
(
namespace
,
class:
"avatar s100 identicon"
)
-
else
.avatar-container.s100
=
image_tag
(
avatar
,
class:
"avatar s100"
)
...
...
@@ -18,7 +18,7 @@
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
)
=
project_i
denti
con
(
namespace
,
class:
"avatar s100 identicon"
)
=
project_icon
(
namespace
,
class:
"avatar s100 identicon"
)
-
else
.avatar-container.s100
=
image_tag
(
avatar
,
class:
"avatar s100"
)
...
...
changelogs/unreleased/feat-add-default-avatar-to-group.yml
0 → 100644
View file @
e40d626b
---
title
:
Add default avatar to group
merge_request
:
17271
author
:
George Tsiolis
type
:
changed
spec/helpers/avatars_helper_spec.rb
View file @
e40d626b
...
...
@@ -5,12 +5,67 @@ describe AvatarsHelper do
let
(
:user
)
{
create
(
:user
)
}
describe
'#project_icon'
do
it
'returns an url for the avatar'
do
project
=
create
(
:project
,
:public
,
avatar:
File
.
open
(
uploaded_image_temp_path
))
describe
'#project_icon & #group_icon'
do
shared_examples
'resource with a default avatar'
do
|
source_type
|
it
'returns a default avatar div'
do
expect
(
public_send
(
"
#{
source_type
}
_icon"
,
*
helper_args
))
.
to
match
(
%r{<div class="identicon bg
\d
+">F</div>}
)
end
end
shared_examples
'resource with a custom avatar'
do
|
source_type
|
it
'returns a custom avatar image'
do
expect
(
public_send
(
"
#{
source_type
}
_icon"
,
*
helper_args
))
.
to
eq
"<img src=
\"
#{
resource
.
avatar
.
url
}
\"
alt=
\"
Banana sample
\"
/>"
end
end
context
'when providing a project'
do
it_behaves_like
'resource with a default avatar'
,
'project'
do
let
(
:resource
)
{
create
(
:project
,
name:
'foo'
)
}
let
(
:helper_args
)
{
[
resource
]
}
end
it_behaves_like
'resource with a custom avatar'
,
'project'
do
let
(
:resource
)
{
create
(
:project
,
:public
,
avatar:
File
.
open
(
uploaded_image_temp_path
))
}
let
(
:helper_args
)
{
[
resource
]
}
end
end
context
'when providing a project path'
do
it_behaves_like
'resource with a default avatar'
,
'project'
do
let
(
:resource
)
{
create
(
:project
,
name:
'foo'
)
}
let
(
:helper_args
)
{
[
resource
.
full_path
]
}
end
expect
(
helper
.
project_icon
(
project
.
full_path
).
to_s
)
.
to
eq
"<img data-src=
\"
#{
project
.
avatar
.
url
}
\"
class=
\"
lazy
\"
src=
\"
#{
LazyImageTagHelper
.
placeholder_image
}
\"
/>"
it_behaves_like
'resource with a custom avatar'
,
'project'
do
let
(
:resource
)
{
create
(
:project
,
:public
,
avatar:
File
.
open
(
uploaded_image_temp_path
))
}
let
(
:helper_args
)
{
[
resource
.
full_path
]
}
end
end
context
'when providing a group'
do
it_behaves_like
'resource with a default avatar'
,
'group'
do
let
(
:resource
)
{
create
(
:group
,
name:
'foo'
)
}
let
(
:helper_args
)
{
[
resource
]
}
end
it_behaves_like
'resource with a custom avatar'
,
'group'
do
let
(
:resource
)
{
create
(
:group
,
avatar:
File
.
open
(
uploaded_image_temp_path
))
}
let
(
:helper_args
)
{
[
resource
]
}
end
end
context
'when providing a group path'
do
it_behaves_like
'resource with a default avatar'
,
'group'
do
let
(
:resource
)
{
create
(
:group
,
name:
'foo'
)
}
let
(
:helper_args
)
{
[
resource
.
full_path
]
}
end
it_behaves_like
'resource with a custom avatar'
,
'group'
do
let
(
:resource
)
{
create
(
:group
,
avatar:
File
.
open
(
uploaded_image_temp_path
))
}
let
(
:helper_args
)
{
[
resource
.
full_path
]
}
end
end
end
...
...
spec/helpers/groups_helper_spec.rb
View file @
e40d626b
...
...
@@ -3,19 +3,6 @@ require 'spec_helper'
describe
GroupsHelper
do
include
ApplicationHelper
describe
'group_icon'
do
it
'returns an url for the avatar'
do
avatar_file_path
=
File
.
join
(
'spec'
,
'fixtures'
,
'banana_sample.gif'
)
group
=
create
(
:group
)
group
.
avatar
=
fixture_file_upload
(
avatar_file_path
)
group
.
save!
expect
(
helper
.
group_icon
(
group
).
to_s
)
.
to
eq
"<img data-src=
\"
#{
group
.
avatar
.
url
}
\"
class=
\"
lazy
\"
src=
\"
#{
LazyImageTagHelper
.
placeholder_image
}
\"
/>"
end
end
describe
'group_icon_url'
do
it
'returns an url for the avatar'
do
avatar_file_path
=
File
.
join
(
'spec'
,
'fixtures'
,
'banana_sample.gif'
)
...
...
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