Skip to content

Commit

Permalink
implement rubocoop recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
mortbauer committed Mar 5, 2024
1 parent cd9461f commit 5203f1b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
11 changes: 4 additions & 7 deletions plugins/documents/app/controllers/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ def create
@document = Document.new name: params[:document][:name]
@document.parent = Document.find_by_id(params[:document][:parent_id])
@document.attachment = params[:document][:attachment]
if !@document.attachment.nil?
if @document.name.empty?
name = File.basename(@document.attachment.filename.to_s)
@document.name = name.gsub(/[^\w.-]/, '_')
end
if !@document.attachment.nil? and @document.name.empty?
name = File.basename(@document.attachment.filename.to_s)
@document.name = name.gsub(/[^\w.-]/, '_')
end
@document.created_by = current_user
@document.folder = !params[:document].has_key?(:attachment)
@document.folder = !params[:document].key?(:attachment)
@document.save!
redirect_to @document.parent || documents_path, notice: t('.notice')
rescue StandardError => e
Expand Down Expand Up @@ -75,5 +73,4 @@ def show
def move
@document = Document.find(params[:document_id])
end

end
3 changes: 1 addition & 2 deletions plugins/documents/app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def file?
end

def valid_attachment
errors.add(:attachment, I18n.t('documents.create.not_allowed_mime', mime: attachment.content_type)) unless !attachment.attached? or allowed_mime? attachment.content_type
errors.add(:attachment, I18n.t('documents.create.not_allowed_mime', mime: attachment.content_type)) unless !attachment.attached? || allowed_mime?(attachment.content_type)
end

def filename
Expand Down Expand Up @@ -43,5 +43,4 @@ def allowed_mime?(mime)
def delete_attachment
attachment.purge_later
end

end

0 comments on commit 5203f1b

Please sign in to comment.