Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#330] Deleting draft state for accounts #327

Closed
wants to merge 9 commits into from
13 changes: 9 additions & 4 deletions core/app/lib/uffizzi_core/concerns/models/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,26 @@ module UffizziCore::Concerns::Models::Account
has_many :payments, dependent: :destroy

aasm(:state) do
state :active, initial: true
state :trial, initial: true
state :trial_quota_exceeded
state :active
state :payment_issue
state :disabled
state :draft

event :activate do
transitions from: [:payment_issue, :disabled, :draft], to: :active
transitions from: [:payment_issue, :disabled, :trial_quota_exceeded, :trial], to: :active
end

event :disable_trial do
transitions from: [:trial], to: :trial_quota_exceeded
end

event :raise_payment_issue, before_success: :update_payment_issue_date do
transitions from: [:active, :disabled], to: :payment_issue
end

event :disable, after: :disable_projects do
transitions from: [:active, :payment_issue], to: :disabled
transitions from: [:active, :payment_issue, :trial, :trial_quota_exceeded], to: :disabled
end
end

Expand Down
9 changes: 9 additions & 0 deletions core/app/services/uffizzi_core/migrations/account_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class UffizziCore::Migrations::AccountService
class << self
def remove_draft_accounts
UffizziCore::Account.where(state: 'draft').destroy_all
end
end
end
9 changes: 9 additions & 0 deletions core/lib/tasks/migration/accounts.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

namespace :migration do
desc 'destroy all draft accounts'
task migrate_draft_accounts: :environment do
UffizziCore::Migrations::AccountService.remove_draft_accounts
puts 'Success'
end
end
4 changes: 0 additions & 4 deletions core/test/factories/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@
state { :payment_issue }
end

trait :draft do
state { UffizziCore::Account::STATE_DRAFT }
end

trait :sso_connection_active do
sso_state { UffizziCore::Account::STATE_CONNECTION_ACTIVE }
end
Expand Down