summaryrefslogtreecommitdiff
path: root/help/app/models
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2013-11-15 11:53:21 +0100
committerAzul <azul@leap.se>2013-11-15 11:53:21 +0100
commit8b49ee15466b728213ec7f8bd4c8462876625acf (patch)
treec301a8033650a1067c9caf012669d1a47d6f2a0c /help/app/models
parent7e93258f552d6fd1114626561e6393aa483228fe (diff)
parent7a107e0d38271e7103d3494e06d52f3434022f22 (diff)
Merge branch 'develop'
Diffstat (limited to 'help/app/models')
-rw-r--r--help/app/models/account_extension/tickets.rb13
-rw-r--r--help/app/models/ticket.rb7
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