mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-15 17:33:31 +08:00
Merge pull request #2475 from okriuchykhin/ok_SCI_4459
Add used space calculation method to the team model [SCI-4459]
This commit is contained in:
commit
749c1dda69
2 changed files with 14 additions and 2 deletions
|
@ -19,7 +19,6 @@ class Team < ApplicationRecord
|
||||||
length: { minimum: Constants::NAME_MIN_LENGTH,
|
length: { minimum: Constants::NAME_MIN_LENGTH,
|
||||||
maximum: Constants::NAME_MAX_LENGTH }
|
maximum: Constants::NAME_MAX_LENGTH }
|
||||||
validates :description, length: { maximum: Constants::TEXT_MAX_LENGTH }
|
validates :description, length: { maximum: Constants::TEXT_MAX_LENGTH }
|
||||||
validates :space_taken, presence: true
|
|
||||||
|
|
||||||
belongs_to :created_by,
|
belongs_to :created_by,
|
||||||
foreign_key: 'created_by_id',
|
foreign_key: 'created_by_id',
|
||||||
|
@ -153,6 +152,20 @@ class Team < ApplicationRecord
|
||||||
fields
|
fields
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def storage_used
|
||||||
|
by_assets = Asset.joins(:file_blob)
|
||||||
|
.where(assets: { team_id: id })
|
||||||
|
.select('active_storage_blobs.byte_size')
|
||||||
|
|
||||||
|
by_tiny_mce_assets = TinyMceAsset.joins(:image_blob)
|
||||||
|
.where(tiny_mce_assets: { team_id: id })
|
||||||
|
.select('active_storage_blobs.byte_size')
|
||||||
|
|
||||||
|
ActiveStorage::Blob
|
||||||
|
.from("((#{by_assets.to_sql}) UNION ALL (#{by_tiny_mce_assets.to_sql})) AS active_storage_blobs")
|
||||||
|
.sum(:byte_size)
|
||||||
|
end
|
||||||
|
|
||||||
# (re)calculate the space taken by this team
|
# (re)calculate the space taken by this team
|
||||||
def calculate_space_taken
|
def calculate_space_taken
|
||||||
st = 0
|
st = 0
|
||||||
|
|
|
@ -44,7 +44,6 @@ describe Team, type: :model do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'Validations' do
|
describe 'Validations' do
|
||||||
it { should validate_presence_of :space_taken }
|
|
||||||
it do
|
it do
|
||||||
should validate_length_of(:name)
|
should validate_length_of(:name)
|
||||||
.is_at_least(Constants::NAME_MIN_LENGTH)
|
.is_at_least(Constants::NAME_MIN_LENGTH)
|
||||||
|
|
Loading…
Reference in a new issue