From 8b5ffb4c43bdf49ee26664c5b04e7b38e380f3ed Mon Sep 17 00:00:00 2001 From: evazion Date: Tue, 9 Jun 2020 03:06:07 -0500 Subject: [PATCH] uploads: allow admins to upload videos more than 2 minutes long. At some point the ability for admins to bypass the video length restriction got lost. ref: https://danbooru.donmai.us/forum_topics/14647 --- app/models/upload.rb | 2 +- test/functional/uploads_controller_test.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/models/upload.rb b/app/models/upload.rb index 6883d9ec3..e7b2651fb 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -53,7 +53,7 @@ class Upload < ApplicationRecord end def validate_video_duration(record) - if record.media_file.is_video? && record.media_file.duration > 120 + if !record.uploader.is_admin? && record.media_file.is_video? && record.media_file.duration > 120 record.errors[:base] << "video must not be longer than 2 minutes" end end diff --git a/test/functional/uploads_controller_test.rb b/test/functional/uploads_controller_test.rb index d9a663584..e0c2617f3 100644 --- a/test/functional/uploads_controller_test.rb +++ b/test/functional/uploads_controller_test.rb @@ -250,6 +250,20 @@ class UploadsControllerTest < ActionDispatch::IntegrationTest end end + context "for a 2+ minute long video" do + should "allow the upload if the user is an admin" do + @source = "https://twitter.com/7u_NABY/status/1269599527700295681" + post_auth uploads_path, create(:admin_user, created_at: 1.week.ago), params: { upload: { tag_string: "aaa", rating: "q", source: @source }} + assert_redirected_to Upload.last + + assert_equal("mp4", Upload.last.file_ext) + assert_equal("completed", Upload.last.status) + assert_equal(1280, Upload.last.image_width) + assert_equal(720, Upload.last.image_height) + assert_equal("mp4", Upload.last.post.file_ext) + end + end + context "uploading a file from your computer" do should "work for a jpeg file" do upload = assert_uploaded("test/files/test.jpg", @user, tag_string: "aaa", rating: "e", source: "aaa")