Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
ac04ab5b16ac
Commit
ac04ab5b
authored
Feb 20, 2015
by
Douwe Maan
Browse files
Split up AttachmentUploader.
parent
b9a468c988d8
Changes
10
Hide whitespace changes
Inline
Side-by-side
app/models/group.rb
View file @
ac04ab5b
...
...
@@ -23,7 +23,7 @@
validate
:avatar_type
,
if:
->
(
user
)
{
user
.
avatar_changed?
}
validates
:avatar
,
file_size:
{
maximum:
200
.
kilobytes
.
to_i
}
mount_uploader
:avatar
,
A
ttachment
Uploader
mount_uploader
:avatar
,
A
vatar
Uploader
after_create
:post_create_hook
after_destroy
:post_destroy_hook
...
...
app/models/project.rb
View file @
ac04ab5b
...
...
@@ -138,7 +138,7 @@
if:
->
(
project
)
{
project
.
avatar
&&
project
.
avatar_changed?
}
validates
:avatar
,
file_size:
{
maximum:
200
.
kilobytes
.
to_i
}
mount_uploader
:avatar
,
A
ttachment
Uploader
mount_uploader
:avatar
,
A
vatar
Uploader
# Scopes
scope
:sorted_by_activity
,
->
{
reorder
(
last_activity_at: :desc
)
}
...
...
app/models/user.rb
View file @
ac04ab5b
...
...
@@ -177,7 +177,7 @@
end
end
mount_uploader
:avatar
,
A
ttachment
Upl
o
ader
mount_uploader
:avatar
,
A
vatar
Upla
o
der
# Scopes
scope
:admins
,
->
{
where
(
admin:
true
)
}
...
...
app/uploaders/attachment_uploader.rb
View file @
ac04ab5b
...
...
@@ -3,8 +3,6 @@
class
AttachmentUploader
<
CarrierWave
::
Uploader
::
Base
storage
:file
after
:store
,
:reset_events_cache
def
store_dir
"uploads/
#{
model
.
class
.
to_s
.
underscore
}
/
#{
mounted_as
}
/
#{
model
.
id
}
"
end
...
...
@@ -22,10 +20,6 @@
false
end
def
secure_url
Gitlab
.
config
.
gitlab
.
relative_url_root
+
"/files/
#{
model
.
class
.
to_s
.
underscore
}
/
#{
model
.
id
}
/
#{
file
.
filename
}
"
end
def
file_storage?
self
.
class
.
storage
==
CarrierWave
::
Storage
::
File
end
...
...
@@ -29,8 +23,4 @@
def
file_storage?
self
.
class
.
storage
==
CarrierWave
::
Storage
::
File
end
def
reset_events_cache
(
file
)
model
.
reset_events_cache
if
model
.
is_a?
(
User
)
end
end
app/uploaders/avatar_uploader.rb
0 → 100644
View file @
ac04ab5b
# encoding: utf-8
class
AvatarUploader
<
CarrierWave
::
Uploader
::
Base
storage
:file
after
:store
,
:reset_events_cache
def
store_dir
"uploads/
#{
model
.
class
.
to_s
.
underscore
}
/
#{
mounted_as
}
/
#{
model
.
id
}
"
end
def
image?
img_ext
=
%w(png jpg jpeg gif bmp tiff)
if
file
.
respond_to?
(
:extension
)
img_ext
.
include?
(
file
.
extension
.
downcase
)
else
# Not all CarrierWave storages respond to :extension
ext
=
file
.
path
.
split
(
'.'
).
last
.
downcase
img_ext
.
include?
(
ext
)
end
rescue
false
end
def
file_storage?
self
.
class
.
storage
==
CarrierWave
::
Storage
::
File
end
def
reset_events_cache
(
file
)
model
.
reset_events_cache
if
model
.
is_a?
(
User
)
end
end
app/views/events/event/_note.html.haml
View file @
ac04ab5b
...
...
@@ -18,6 +18,6 @@
-
note
=
event
.
target
-
if
note
.
attachment
.
url
-
if
note
.
attachment
.
image?
=
link_to
note
.
attachment
.
secure_
url
,
target:
'_blank'
do
=
image_tag
note
.
attachment
.
secure_
url
,
class:
'note-image-attach'
=
link_to
note
.
attachment
.
url
,
target:
'_blank'
do
=
image_tag
note
.
attachment
.
url
,
class:
'note-image-attach'
-
else
...
...
@@ -23,4 +23,4 @@
-
else
=
link_to
note
.
attachment
.
secure_
url
,
target:
"_blank"
,
class:
'note-file-attach'
do
=
link_to
note
.
attachment
.
url
,
target:
"_blank"
,
class:
'note-file-attach'
do
%i
.fa.fa-paperclip
=
note
.
attachment_identifier
app/views/projects/notes/_note.html.haml
View file @
ac04ab5b
...
...
@@ -57,6 +57,6 @@
-
if
note
.
attachment
.
url
.note-attachment
-
if
note
.
attachment
.
image?
=
link_to
note
.
attachment
.
secure_
url
,
target:
'_blank'
do
=
image_tag
note
.
attachment
.
secure_
url
,
class:
'note-image-attach'
=
link_to
note
.
attachment
.
url
,
target:
'_blank'
do
=
image_tag
note
.
attachment
.
url
,
class:
'note-image-attach'
.attachment
...
...
@@ -62,5 +62,5 @@
.attachment
=
link_to
note
.
attachment
.
secure_
url
,
target:
"_blank"
do
=
link_to
note
.
attachment
.
url
,
target:
"_blank"
do
%i
.fa.fa-paperclip
=
note
.
attachment_identifier
=
link_to
delete_attachment_project_note_path
(
@project
,
note
),
...
...
features/steps/groups.rb
View file @
ac04ab5b
...
...
@@ -110,7 +110,7 @@
end
step
'I should see new group "Owned" avatar'
do
Group
.
find_by
(
name:
"Owned"
).
avatar
.
should
be_instance_of
A
ttachment
Uploader
Group
.
find_by
(
name:
"Owned"
).
avatar
.
should
be_instance_of
A
vatar
Uploader
Group
.
find_by
(
name:
"Owned"
).
avatar
.
url
.
should
==
"/uploads/group/avatar/
#{
Group
.
find_by
(
name
:"Owned"
).
id
}
/gitlab_logo.png"
end
...
...
features/steps/profile/profile.rb
View file @
ac04ab5b
...
...
@@ -29,7 +29,7 @@
end
step
'I should see new avatar'
do
@user
.
avatar
.
should
be_instance_of
A
ttachment
Uploader
@user
.
avatar
.
should
be_instance_of
A
vatar
Uploader
@user
.
avatar
.
url
.
should
==
"/uploads/user/avatar/
#{
@user
.
id
}
/gitlab_logo.png"
end
...
...
features/steps/project/project.rb
View file @
ac04ab5b
...
...
@@ -35,7 +35,7 @@
end
step
'I should see new project avatar'
do
@project
.
avatar
.
should
be_instance_of
A
ttachment
Uploader
@project
.
avatar
.
should
be_instance_of
A
vatar
Uploader
url
=
@project
.
avatar
.
url
url
.
should
==
"/uploads/project/avatar/
#{
@project
.
id
}
/gitlab_logo.png"
end
...
...
Write
Preview
Supports
Markdown
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