adds team space related methods

This commit is contained in:
zmagod 2017-04-25 13:44:31 +02:00
parent 86c6ae3b03
commit 1fefeee3d1
4 changed files with 16 additions and 2 deletions

View file

@ -3,7 +3,9 @@ class TinyMceAssetsController < ApplicationController
def create
image = params.fetch(:file) { render_404 }
tiny_img = TinyMceAsset.new(image: image, reference: @obj)
tiny_img = TinyMceAsset.new(image: image,
reference: @obj,
team_id: current_team.id)
if tiny_img.save
render json: {
image: {

View file

@ -103,7 +103,7 @@ module ApplicationHelper
end
def smart_annotation_parser(text, team = nil)
team = nil unless team.kind_of? Team
team = nil unless team.is_a? Team
new_text = smart_annotation_filter_resources(text)
new_text = smart_annotation_filter_users(new_text, team)
new_text

View file

@ -2,6 +2,7 @@ class TinyMceAsset < ActiveRecord::Base
attr_accessor :reference
before_create :set_reference
after_create :update_estimated_size
after_destroy :release_team_space
belongs_to :step, inverse_of: :tiny_mce_assets
belongs_to :result_text, inverse_of: :tiny_mce_assets
@ -56,9 +57,19 @@ 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
end
def release_team_space
team = Team.find_by_id(team_id)
team.release_space(estimated_size)
team.save
end
def set_reference

View file

@ -4,6 +4,7 @@ class AddAttachmentImageToTinyMceAssets < ActiveRecord::Migration
t.attachment :image
t.integer :estimated_size, default: 0, null: false
t.references :step, index: true
t.references :team, index: true
t.references :result_text, index: true
t.timestamps null: false
end