Commit 4ef6ffaa authored by Douwe Maan's avatar Douwe Maan

Split up AttachmentUploader.

parent c801df81
...@@ -23,7 +23,7 @@ class Group < Namespace ...@@ -23,7 +23,7 @@ class Group < Namespace
validate :avatar_type, if: ->(user) { user.avatar_changed? } validate :avatar_type, if: ->(user) { user.avatar_changed? }
validates :avatar, file_size: { maximum: 200.kilobytes.to_i } validates :avatar, file_size: { maximum: 200.kilobytes.to_i }
mount_uploader :avatar, AttachmentUploader mount_uploader :avatar, AvatarUploader
after_create :post_create_hook after_create :post_create_hook
after_destroy :post_destroy_hook after_destroy :post_destroy_hook
......
...@@ -138,7 +138,7 @@ class Project < ActiveRecord::Base ...@@ -138,7 +138,7 @@ class Project < ActiveRecord::Base
if: ->(project) { project.avatar && project.avatar_changed? } if: ->(project) { project.avatar && project.avatar_changed? }
validates :avatar, file_size: { maximum: 200.kilobytes.to_i } validates :avatar, file_size: { maximum: 200.kilobytes.to_i }
mount_uploader :avatar, AttachmentUploader mount_uploader :avatar, AvatarUploader
# Scopes # Scopes
scope :sorted_by_activity, -> { reorder(last_activity_at: :desc) } scope :sorted_by_activity, -> { reorder(last_activity_at: :desc) }
......
...@@ -177,7 +177,7 @@ class User < ActiveRecord::Base ...@@ -177,7 +177,7 @@ class User < ActiveRecord::Base
end end
end end
mount_uploader :avatar, AttachmentUploader mount_uploader :avatar, AvatarUplaoder
# Scopes # Scopes
scope :admins, -> { where(admin: true) } scope :admins, -> { where(admin: true) }
......
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
class AttachmentUploader < CarrierWave::Uploader::Base class AttachmentUploader < CarrierWave::Uploader::Base
storage :file storage :file
after :store, :reset_events_cache
def store_dir def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end end
...@@ -22,15 +20,7 @@ class AttachmentUploader < CarrierWave::Uploader::Base ...@@ -22,15 +20,7 @@ class AttachmentUploader < CarrierWave::Uploader::Base
false false
end end
def secure_url
Gitlab.config.gitlab.relative_url_root + "/files/#{model.class.to_s.underscore}/#{model.id}/#{file.filename}"
end
def file_storage? def file_storage?
self.class.storage == CarrierWave::Storage::File self.class.storage == CarrierWave::Storage::File
end end
def reset_events_cache(file)
model.reset_events_cache if model.is_a?(User)
end
end end
# 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
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
- note = event.target - note = event.target
- if note.attachment.url - if note.attachment.url
- if note.attachment.image? - if note.attachment.image?
= link_to note.attachment.secure_url, target: '_blank' do = link_to note.attachment.url, target: '_blank' do
= image_tag note.attachment.secure_url, class: 'note-image-attach' = image_tag note.attachment.url, class: 'note-image-attach'
- else - 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 %i.fa.fa-paperclip
= note.attachment_identifier = note.attachment_identifier
...@@ -57,10 +57,10 @@ ...@@ -57,10 +57,10 @@
- if note.attachment.url - if note.attachment.url
.note-attachment .note-attachment
- if note.attachment.image? - if note.attachment.image?
= link_to note.attachment.secure_url, target: '_blank' do = link_to note.attachment.url, target: '_blank' do
= image_tag note.attachment.secure_url, class: 'note-image-attach' = image_tag note.attachment.url, class: 'note-image-attach'
.attachment .attachment
= link_to note.attachment.secure_url, target: "_blank" do = link_to note.attachment.url, target: "_blank" do
%i.fa.fa-paperclip %i.fa.fa-paperclip
= note.attachment_identifier = note.attachment_identifier
= link_to delete_attachment_project_note_path(@project, note), = link_to delete_attachment_project_note_path(@project, note),
......
...@@ -110,7 +110,7 @@ class Spinach::Features::Groups < Spinach::FeatureSteps ...@@ -110,7 +110,7 @@ class Spinach::Features::Groups < Spinach::FeatureSteps
end end
step 'I should see new group "Owned" avatar' do step 'I should see new group "Owned" avatar' do
Group.find_by(name: "Owned").avatar.should be_instance_of AttachmentUploader Group.find_by(name: "Owned").avatar.should be_instance_of AvatarUploader
Group.find_by(name: "Owned").avatar.url.should == "/uploads/group/avatar/#{ Group.find_by(name:"Owned").id }/gitlab_logo.png" Group.find_by(name: "Owned").avatar.url.should == "/uploads/group/avatar/#{ Group.find_by(name:"Owned").id }/gitlab_logo.png"
end end
......
...@@ -29,7 +29,7 @@ class Spinach::Features::Profile < Spinach::FeatureSteps ...@@ -29,7 +29,7 @@ class Spinach::Features::Profile < Spinach::FeatureSteps
end end
step 'I should see new avatar' do step 'I should see new avatar' do
@user.avatar.should be_instance_of AttachmentUploader @user.avatar.should be_instance_of AvatarUploader
@user.avatar.url.should == "/uploads/user/avatar/#{ @user.id }/gitlab_logo.png" @user.avatar.url.should == "/uploads/user/avatar/#{ @user.id }/gitlab_logo.png"
end end
......
...@@ -35,7 +35,7 @@ class Spinach::Features::Project < Spinach::FeatureSteps ...@@ -35,7 +35,7 @@ class Spinach::Features::Project < Spinach::FeatureSteps
end end
step 'I should see new project avatar' do step 'I should see new project avatar' do
@project.avatar.should be_instance_of AttachmentUploader @project.avatar.should be_instance_of AvatarUploader
url = @project.avatar.url url = @project.avatar.url
url.should == "/uploads/project/avatar/#{ @project.id }/gitlab_logo.png" url.should == "/uploads/project/avatar/#{ @project.id }/gitlab_logo.png"
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment