diff options
author | jessib <jessib@riseup.net> | 2013-11-11 13:15:26 -0800 |
---|---|---|
committer | jessib <jessib@riseup.net> | 2013-11-11 13:15:26 -0800 |
commit | d4d970095d0370d7d5744fdc0ebc7b8d9bbd1a4c (patch) | |
tree | b035b29ccb465a75bfd019d46f037dc5de6fbc78 /help/app/models | |
parent | 8c19b447dec3982107f93ea1ae2626f844045249 (diff) | |
parent | 69a41bee2548fa8743dd3188b0ebfc84dac17062 (diff) |
Merge pull request #109 from azul/feature/clear-all-data-of-deleted-user
Feature/clear data of deleted user
Diffstat (limited to 'help/app/models')
-rw-r--r-- | help/app/models/account_extension/tickets.rb | 13 | ||||
-rw-r--r-- | help/app/models/ticket.rb | 7 |
2 files changed, 20 insertions, 0 deletions
diff --git a/help/app/models/account_extension/tickets.rb b/help/app/models/account_extension/tickets.rb new file mode 100644 index 0000000..f898b56 --- /dev/null +++ b/help/app/models/account_extension/tickets.rb @@ -0,0 +1,13 @@ +module AccountExtension::Tickets + extend ActiveSupport::Concern + + def destroy_with_tickets + Ticket.destroy_all_from(self.user) + destroy_without_tickets + end + + included do + alias_method_chain :destroy, :tickets + end + +end diff --git a/help/app/models/ticket.rb b/help/app/models/ticket.rb index 8066d0d..74f2050 100644 --- a/help/app/models/ticket.rb +++ b/help/app/models/ticket.rb @@ -24,6 +24,7 @@ class Ticket < CouchRest::Model::Base design do view :by_updated_at view :by_created_at + view :by_created_by view :by_is_open_and_created_at view :by_is_open_and_updated_at @@ -40,6 +41,12 @@ class Ticket < CouchRest::Model::Base @selection.tickets end + def self.destroy_all_from(user) + self.by_created_by.key(user.id).each do |ticket| + ticket.destroy + end + end + def is_creator_validated? !!created_by end |