diff --git a/CHANGELOG.md b/CHANGELOG.md index 5394d6ec..7c847f1e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Added - Added foundation for upcoming authentication from iOS app. +- [Dawarich Cloud] Trial users can now create up to 5 imports. After that, they will be prompted to subscribe to a paid plan. # [0.32.0] - 2025-09-13 diff --git a/app/javascript/controllers/direct_upload_controller.js b/app/javascript/controllers/direct_upload_controller.js index cc58436e..269595b4 100644 --- a/app/javascript/controllers/direct_upload_controller.js +++ b/app/javascript/controllers/direct_upload_controller.js @@ -6,7 +6,8 @@ export default class extends Controller { static targets = ["input", "progress", "progressBar", "submit", "form"] static values = { url: String, - userTrial: Boolean + userTrial: Boolean, + currentImportsCount: Number } connect() { @@ -51,6 +52,16 @@ export default class extends Controller { const files = this.inputTarget.files if (files.length === 0) return + // Check import count limits for trial users + if (this.userTrialValue && this.currentImportsCountValue >= 5) { + const message = 'Import limit reached. Trial users can only create up to 5 imports. Please subscribe to import more files.' + showFlashMessage('error', message) + + // Clear the file input + this.inputTarget.value = '' + return + } + // Check file size limits for trial users if (this.userTrialValue) { const MAX_FILE_SIZE = 11 * 1024 * 1024 // 11MB in bytes diff --git a/app/models/import.rb b/app/models/import.rb index b1abde92..4544819e 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -15,6 +15,7 @@ class Import < ApplicationRecord validates :name, presence: true, uniqueness: { scope: :user_id } validate :file_size_within_limit, if: -> { user.trial? } + validate :import_count_within_limit, if: -> { user.trial? } enum :status, { created: 0, processing: 1, completed: 2, failed: 3 } @@ -69,6 +70,15 @@ class Import < ApplicationRecord errors.add(:file, 'is too large. Trial users can only upload files up to 10MB.') end + def import_count_within_limit + return unless new_record? + + existing_imports_count = user.imports.count + return unless existing_imports_count >= 5 + + errors.add(:base, 'Trial users can only create up to 5 imports. Please subscribe to import more files.') + end + def recalculate_stats years_and_months_tracked.each do |year, month| Stats::CalculatingJob.perform_later(user.id, year, month) diff --git a/app/views/imports/_form.html.erb b/app/views/imports/_form.html.erb index 95d16411..16fd3cd5 100644 --- a/app/views/imports/_form.html.erb +++ b/app/views/imports/_form.html.erb @@ -11,6 +11,13 @@
File format is automatically detected during upload.
+ <% if current_user.trial? %> +
+ Trial limitations: Max 5 imports, 10MB per file. +
+ Current imports: <%= current_user.imports.count %>/5 +
+ <% end %> @@ -18,6 +25,7 @@ controller: "direct-upload", direct_upload_url_value: rails_direct_uploads_url, direct_upload_user_trial_value: current_user.trial?, + direct_upload_current_imports_count_value: current_user.imports.count, direct_upload_target: "form" } do |form| %>