dchun / QuoteManager

Saas App for Managing Quotes and getting paid
https://quotemanager.boopis.com
0 stars 0 forks source link

Create Account Restrictions Based On Plan Fields #99

Closed dchun closed 9 years ago

dchun commented 9 years ago

1 user, 5 forms, 100MB Storage, 500 requests/mo 3 users, 10 forms, 1GB Storage, 1500 requests/mo 5 users, 20 forms, 5GB Storage, 5000 requests/mo

dchun commented 9 years ago

For limitations on db entries we can do something like:

  validate :limit, :on => :create

  def limit
    if self.account.forms(:reload).count > self.account.plan.forms
      errors.add(:base, "Exceeds Form Limit, Please Upgrade Your Account")
    end
  end

For limitations on storage space we would either have to calculate the size of each size in an account's folder. If this is too expensive, we may resort to adding an additional field to the requests model and store an integer value for the size of each uploaded file and calculate the size of all entries.

A library to consider for calculating folder size: https://github.com/jtrinklein/foldersize

Perhaps even add a limitation on the size of each upload and count requests with a file field that isn't nil with the max possible size and run a calculation only if the max possible storage exceeds the current plans storage.

dchun commented 9 years ago

measure the folder size every time a user logs in as follows:

    directory = Foldersize.define_folder("#{Rails.root}/uploads/files/#{current_account.id}")
    @usage = directory.size_in_bytes.to_f
    @plan = current_account.plan

and force the user to sign out every day

and when the user comes near the limit at 90%, we prompt them to update

and when the user exceeds the limit, we force them to the update page.