Add 1GB storage cap with staff bypass (#2729)

Re-applies the storage limit from #2713 (reverted in #2715) with an
exception for staff identities so our own account isn't blocked.
This commit is contained in:
Jorge Manrubia
2026-03-19 12:38:39 +01:00
committed by GitHub
parent 11df9c3589
commit cf10dbd91e
22 changed files with 374 additions and 2 deletions
@@ -0,0 +1,44 @@
require "test_helper"
class Card::StorageLimited::CommentingTest < ActionDispatch::IntegrationTest
test "cannot create comments when storage limit exceeded" do
sign_in_as :david
Account.any_instance.stubs(:bytes_used).returns(1.gigabyte + 1)
Identity.any_instance.stubs(:staff?).returns(false)
assert_no_difference -> { Comment.count } do
post card_comments_path(cards(:logo), script_name: accounts(:"37s").slug),
params: { comment: { body: "Blocked comment" } },
as: :turbo_stream
end
assert_response :forbidden
end
test "can create comments when under storage limit" do
sign_in_as :david
assert_difference -> { Comment.count } do
post card_comments_path(cards(:logo), script_name: accounts(:"37s").slug),
params: { comment: { body: "Allowed comment" } },
as: :turbo_stream
end
assert_response :success
end
test "staff can create comments even when storage limit exceeded" do
sign_in_as :david
Account.any_instance.stubs(:bytes_used).returns(1.gigabyte + 1)
assert_difference -> { Comment.count } do
post card_comments_path(cards(:logo), script_name: accounts(:"37s").slug),
params: { comment: { body: "Staff comment" } },
as: :turbo_stream
end
assert_response :success
end
end
@@ -0,0 +1,63 @@
require "test_helper"
class Card::StorageLimited::CreationTest < ActionDispatch::IntegrationTest
test "cannot create cards via JSON when storage limit exceeded" do
sign_in_as :mike
Account.any_instance.stubs(:bytes_used).returns(1.gigabyte + 1)
assert_no_difference -> { Card.count } do
post board_cards_path(boards(:miltons_wish_list), script_name: accounts(:initech).slug),
params: { card: { title: "Blocked card" } },
as: :json
end
assert_response :forbidden
end
test "can create cards via HTML when storage limit exceeded since they become drafts" do
sign_in_as :mike
Account.any_instance.stubs(:bytes_used).returns(1.gigabyte + 1)
accounts(:initech).update_column(:cards_count, 100)
boards(:miltons_wish_list).cards.drafted.where(creator: users(:mike)).destroy_all
assert_difference -> { Card.count } do
post board_cards_path(boards(:miltons_wish_list), script_name: accounts(:initech).slug)
end
assert_response :redirect
assert Card.last.drafted?
end
test "can create cards via JSON when under storage limit" do
sign_in_as :mike
Account.any_instance.stubs(:bytes_used).returns(500.megabytes)
accounts(:initech).update_column(:cards_count, 100)
assert_difference -> { Card.count } do
post board_cards_path(boards(:miltons_wish_list), script_name: accounts(:initech).slug),
params: { card: { title: "Allowed card" } },
as: :json
end
assert_response :created
end
test "staff can create cards via JSON even when storage limit exceeded" do
sign_in_as :mike
Account.any_instance.stubs(:bytes_used).returns(1.gigabyte + 1)
Identity.any_instance.stubs(:staff?).returns(true)
accounts(:initech).update_column(:cards_count, 100)
assert_difference -> { Card.count } do
post board_cards_path(boards(:miltons_wish_list), script_name: accounts(:initech).slug),
params: { card: { title: "Staff card" } },
as: :json
end
assert_response :created
end
end
@@ -0,0 +1,35 @@
require "test_helper"
class Card::StorageLimited::PublishingTest < ActionDispatch::IntegrationTest
test "cannot publish cards when storage limit exceeded" do
sign_in_as :mike
Account.any_instance.stubs(:bytes_used).returns(1.gigabyte + 1)
post card_publish_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
assert_response :forbidden
assert cards(:unfinished_thoughts).reload.drafted?
end
test "can publish cards when under storage limit" do
sign_in_as :mike
post card_publish_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
assert_response :redirect
assert cards(:unfinished_thoughts).reload.published?
end
test "staff can publish cards even when storage limit exceeded" do
sign_in_as :mike
Account.any_instance.stubs(:bytes_used).returns(1.gigabyte + 1)
Identity.any_instance.stubs(:staff?).returns(true)
post card_publish_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
assert_response :redirect
assert cards(:unfinished_thoughts).reload.published?
end
end
@@ -0,0 +1,39 @@
require "test_helper"
class Card::StorageLimitedTest < ActionDispatch::IntegrationTest
test "draft card shows storage limit notice instead of create buttons when limit exceeded" do
sign_in_as :mike
Account.any_instance.stubs(:bytes_used).returns(1.gigabyte + 1)
get card_draft_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
assert_response :success
assert_select ".card-perma__notch" do
assert_select "strong", text: /used all/
assert_select "a[href='https://github.com/basecamp/fizzy']", text: "Self-host Fizzy"
end
assert_select ".card-perma__notch-new-card-buttons", count: 0
end
test "draft card shows create buttons when under storage limit" do
sign_in_as :mike
get card_draft_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
assert_response :success
assert_select ".card-perma__notch-new-card-buttons"
end
test "staff sees create buttons even when storage limit exceeded" do
sign_in_as :mike
Account.any_instance.stubs(:bytes_used).returns(1.gigabyte + 1)
Identity.any_instance.stubs(:staff?).returns(true)
get card_draft_path(cards(:unfinished_thoughts), script_name: accounts(:initech).slug)
assert_response :success
assert_select ".card-perma__notch-new-card-buttons"
end
end
@@ -0,0 +1,37 @@
require "test_helper"
class Comment::StorageLimitedTest < ActionDispatch::IntegrationTest
test "published card shows storage limit notice instead of comment form when limit exceeded" do
sign_in_as :david
Account.any_instance.stubs(:bytes_used).returns(1.gigabyte + 1)
Identity.any_instance.stubs(:staff?).returns(false)
get card_path(cards(:logo), script_name: accounts(:"37s").slug)
assert_response :success
assert_select "strong", text: /used all/
assert_select "a[href='https://github.com/basecamp/fizzy']", text: "Self-host Fizzy"
assert_select "##{dom_id(cards(:logo), :new_comment)}", count: 0
end
test "published card shows comment form when under storage limit" do
sign_in_as :david
get card_path(cards(:logo), script_name: accounts(:"37s").slug)
assert_response :success
assert_select "##{dom_id(cards(:logo), :new_comment)}"
end
test "staff sees comment form even when storage limit exceeded" do
sign_in_as :david
Account.any_instance.stubs(:bytes_used).returns(1.gigabyte + 1)
get card_path(cards(:logo), script_name: accounts(:"37s").slug)
assert_response :success
assert_select "##{dom_id(cards(:logo), :new_comment)}"
end
end
@@ -0,0 +1,39 @@
require "test_helper"
class Account::StorageLimitedTest < ActiveSupport::TestCase
test "exceeding storage limit when bytes used exceeds 1 GB" do
Account.any_instance.stubs(:bytes_used).returns(1.gigabyte + 1)
assert accounts(:initech).exceeding_storage_limit?
end
test "not exceeding storage limit when bytes used equals 1 GB" do
Account.any_instance.stubs(:bytes_used).returns(1.gigabyte)
assert_not accounts(:initech).exceeding_storage_limit?
end
test "not exceeding storage limit when under 1 GB" do
Account.any_instance.stubs(:bytes_used).returns(500.megabytes)
assert_not accounts(:initech).exceeding_storage_limit?
end
test "nearing storage limit when within 500 MB of the limit" do
Account.any_instance.stubs(:bytes_used).returns(600.megabytes)
assert accounts(:initech).nearing_storage_limit?
end
test "not nearing storage limit when well under the threshold" do
Account.any_instance.stubs(:bytes_used).returns(400.megabytes)
assert_not accounts(:initech).nearing_storage_limit?
end
test "not nearing storage limit when already exceeding it" do
Account.any_instance.stubs(:bytes_used).returns(1.gigabyte + 1)
assert_not accounts(:initech).nearing_storage_limit?
end
end