mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-10 17:36:33 +08:00
adds relation to team, adds rake task to delete obsolete images [fixes SCI-1203]
This commit is contained in:
parent
1fefeee3d1
commit
ed24448817
5 changed files with 24 additions and 11 deletions
|
@ -164,10 +164,12 @@ class StepsController < ApplicationController
|
|||
table.last_modified_by = current_user unless table.new_record?
|
||||
table.team = current_team
|
||||
end
|
||||
|
||||
# gerate a tag that replaces img tag in database
|
||||
@step.description = parse_tiny_mce_asset_to_token(@step.description,
|
||||
@step)
|
||||
|
||||
# gerate a tag that replaces img tag in databases
|
||||
@step.description = parse_tiny_mce_asset_to_token(
|
||||
params[:step][:description],
|
||||
@step
|
||||
)
|
||||
|
||||
if @step.save
|
||||
@step.reload
|
||||
|
|
|
@ -24,7 +24,7 @@ class Team < ActiveRecord::Base
|
|||
has_many :custom_fields, inverse_of: :team
|
||||
has_many :protocols, inverse_of: :team, dependent: :destroy
|
||||
has_many :protocol_keywords, inverse_of: :team, dependent: :destroy
|
||||
|
||||
has_many :tiny_mce_assets, inverse_of: :team, dependent: :destroy
|
||||
# Based on file's extension opens file (used for importing)
|
||||
def self.open_spreadsheet(file)
|
||||
filename = file.original_filename
|
||||
|
|
|
@ -4,6 +4,7 @@ class TinyMceAsset < ActiveRecord::Base
|
|||
after_create :update_estimated_size
|
||||
after_destroy :release_team_space
|
||||
|
||||
belongs_to :team, inverse_of: :tiny_mce_assets
|
||||
belongs_to :step, inverse_of: :tiny_mce_assets
|
||||
belongs_to :result_text, inverse_of: :tiny_mce_assets
|
||||
has_attached_file :image,
|
||||
|
@ -57,19 +58,17 @@ class TinyMceAsset < ActiveRecord::Base
|
|||
|
||||
def update_estimated_size
|
||||
return if image_file_size.blank?
|
||||
team = Team.find_by_id(team_id)
|
||||
es = image_file_size * Constants::ASSET_ESTIMATED_SIZE_FACTOR
|
||||
update(estimated_size: es)
|
||||
Rails.logger.info "Asset #{id}: Estimated size successfully calculated"
|
||||
# update team space taken
|
||||
team.take_space(es)
|
||||
team.save
|
||||
self.team.take_space(es)
|
||||
self.team.save
|
||||
end
|
||||
|
||||
def release_team_space
|
||||
team = Team.find_by_id(team_id)
|
||||
team.release_space(estimated_size)
|
||||
team.save
|
||||
self.team.release_space(estimated_size)
|
||||
self.team.save
|
||||
end
|
||||
|
||||
def set_reference
|
||||
|
|
|
@ -567,6 +567,7 @@ ActiveRecord::Schema.define(version: 20170420075905) do
|
|||
t.datetime "image_updated_at"
|
||||
t.integer "estimated_size", default: 0, null: false
|
||||
t.integer "step_id"
|
||||
t.integer "team_id"
|
||||
t.integer "result_text_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
|
@ -574,6 +575,7 @@ ActiveRecord::Schema.define(version: 20170420075905) do
|
|||
|
||||
add_index "tiny_mce_assets", ["result_text_id"], name: "index_tiny_mce_assets_on_result_text_id", using: :btree
|
||||
add_index "tiny_mce_assets", ["step_id"], name: "index_tiny_mce_assets_on_step_id", using: :btree
|
||||
add_index "tiny_mce_assets", ["team_id"], name: "index_tiny_mce_assets_on_team_id", using: :btree
|
||||
|
||||
create_table "tokens", force: :cascade do |t|
|
||||
t.string "token", null: false
|
||||
|
|
10
lib/tasks/tiny_mce_asset.rake
Normal file
10
lib/tasks/tiny_mce_asset.rake
Normal file
|
@ -0,0 +1,10 @@
|
|||
namespace :tiny_mce_asset do
|
||||
desc 'Remove obsolete images that were created on new steps or '\
|
||||
'results and the step/result didn\'t get saved.'
|
||||
task remote_obsolete_images: :environment do
|
||||
TinyMceAsset.where('step_id IS ? AND ' \
|
||||
'result_text_id IS ? AND created_at < ?',
|
||||
nil, nil, 7.days.ago)
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue