aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/censor_rule.rb9
-rw-r--r--app/models/comment.rb8
-rw-r--r--app/models/incoming_message.rb12
-rw-r--r--app/models/info_request.rb8
-rw-r--r--app/models/info_request_event.rb43
-rw-r--r--app/models/outgoing_message.rb6
-rw-r--r--app/models/public_body.rb25
-rw-r--r--app/models/user.rb12
8 files changed, 90 insertions, 33 deletions
diff --git a/app/models/censor_rule.rb b/app/models/censor_rule.rb
index 201e60746..72b92d462 100644
--- a/app/models/censor_rule.rb
+++ b/app/models/censor_rule.rb
@@ -51,7 +51,10 @@ class CensorRule < ActiveRecord::Base
errors.add("Censor must apply to an info request a user or a body; ")
end
end
-end
-
-
+ def for_admin_column
+ self.class.content_columns.each do |column|
+ yield(column.human_name, self.send(column.name), column.type.to_s, column.name)
+ end
+ end
+end
diff --git a/app/models/comment.rb b/app/models/comment.rb
index 44a1079cd..b3d5ba640 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -84,7 +84,9 @@ class Comment < ActiveRecord::Base
return Comment.find(:first, :conditions => [ "info_request_id = ? and body = ?", info_request_id, body ])
end
end
-
+ def for_admin_column
+ self.class.content_columns.each do |column|
+ yield(column.human_name, self.send(column.name), column.type.to_s, column.name)
+ end
+ end
end
-
-
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index 8de6e5ba8..9dcd8c1bc 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -674,7 +674,6 @@ class IncomingMessage < ActiveRecord::Base
end
end
-
# Fix DOS style linefeeds to Unix style ones (or other later regexps won't work)
# Needed for e.g. http://www.whatdotheyknow.com/request/60/response/98
text = text.gsub(/\r\n/, "\n")
@@ -1029,8 +1028,6 @@ class IncomingMessage < ActiveRecord::Base
return get_body_for_quoting + "\n\n" + get_attachment_text_clipped
end
-
-
# Has message arrived "recently"?
def recently_arrived
(Time.now - self.created_at) <= 3.days
@@ -1133,7 +1130,14 @@ class IncomingMessage < ActiveRecord::Base
return content_type
end
- private :normalise_content_type
+
+ def for_admin_column
+ self.class.content_columns.each do |column|
+ yield(column.human_name, self.send(column.name), column.type.to_s, column.name)
+ end
+ end
+
+ private :normalise_content_type
end
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 3b86f4cb3..1e55f92ae 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -1059,6 +1059,10 @@ public
req.save()
end
end
-end
-
+ def for_admin_column
+ self.class.content_columns.map{|c| c unless %w(title url_title).include?(c.name) }.compact.each do |column|
+ yield(column.human_name, self.send(column.name), column.type.to_s, column.name)
+ end
+ end
+end
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index 9ce191f6b..dacd3223e 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -39,25 +39,26 @@ class InfoRequestEvent < ActiveRecord::Base
def self.enumerate_event_types
[
- 'sent',
- 'resent',
- 'followup_sent',
- 'followup_resent',
-
- 'edit', # title etc. edited (in admin interface)
- 'edit_outgoing', # outgoing message edited (in admin interface)
- 'edit_comment', # comment edited (in admin interface)
- 'destroy_incoming', # deleted an incoming message (in admin interface)
- 'destroy_outgoing', # deleted an outgoing message (in admin interface)
- 'redeliver_incoming', # redelivered an incoming message elsewhere (in admin interface)
- 'move_request', # changed user or public body (in admin interface)
- 'manual', # you did something in the db by hand
-
- 'response',
- 'comment',
- 'status_update',
+ 'sent',
+ 'resent',
+ 'followup_sent',
+ 'followup_resent',
+
+ 'edit', # title etc. edited (in admin interface)
+ 'edit_outgoing', # outgoing message edited (in admin interface)
+ 'edit_comment', # comment edited (in admin interface)
+ 'destroy_incoming', # deleted an incoming message (in admin interface)
+ 'destroy_outgoing', # deleted an outgoing message (in admin interface)
+ 'redeliver_incoming', # redelivered an incoming message elsewhere (in admin interface)
+ 'move_request', # changed user or public body (in admin interface)
+ 'manual', # you did something in the db by hand
+
+ 'response',
+ 'comment',
+ 'status_update'
]
end
+
validates_inclusion_of :event_type, :in => enumerate_event_types
# user described state (also update in info_request)
@@ -440,7 +441,9 @@ class InfoRequestEvent < ActiveRecord::Base
return ret
end
-
+ def for_admin_column
+ self.class.content_columns.each do |column|
+ yield(column.human_name, self.send(column.name), column.type.to_s, column.name)
+ end
+ end
end
-
-
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb
index 29445d587..c29cbb785 100644
--- a/app/models/outgoing_message.rb
+++ b/app/models/outgoing_message.rb
@@ -271,6 +271,12 @@ class OutgoingMessage < ActiveRecord::Base
def purge_in_cache
self.info_request.purge_in_cache
end
+
+ def for_admin_column
+ self.class.content_columns.each do |column|
+ yield(column.human_name, self.send(column.name), column.type.to_s, column.name)
+ end
+ end
end
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 0e21037ef..ae902dac6 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -189,6 +189,25 @@ class PublicBody < ActiveRecord::Base
text = text.gsub(/\n/, '<br>')
return text
end
+
+ def compare(previous = nil)
+ if previous.nil?
+ yield([])
+ else
+ v = self
+ changes = self.class.content_columns.inject([]) {|memo, c|
+ unless %w(version last_edit_editor last_edit_comment updated_at).include?(c.name)
+ from = previous.send(c.name)
+ to = self.send(c.name)
+ memo << { :name => c.human_name, :from => from, :to => to } if from != to
+ end
+ memo
+ }
+ changes.each do |change|
+ yield(change)
+ end
+ end
+ end
end
acts_as_xapian :texts => [ :name, :short_name, :notes ],
@@ -552,6 +571,12 @@ class PublicBody < ActiveRecord::Base
self.info_requests.each {|x| x.purge_in_cache}
end
+ def for_admin_column
+ self.class.content_columns.map{|c| c unless %w(name last_edit_comment).include?(c.name)}.compact.each do |column|
+ yield(column.human_name, self.send(column.name), column.type.to_s, column.name)
+ end
+ end
+
end
diff --git a/app/models/user.rb b/app/models/user.rb
index cd8d3e721..4a7153b3f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -400,6 +400,17 @@ class User < ActiveRecord::Base
return self.email_confirmed
end
+ def for_admin_column(complete = false)
+ if complete
+ columns = self.class.content_columns
+ else
+ columns = self.class.content_columns.map{|c| c if %w(created_at updated_at admin_level email_confirmed).include?(c.name) }.compact
+ end
+ columns.each do |column|
+ yield(column.human_name, self.send(column.name), column.type.to_s)
+ end
+ end
+
## Private instance methods
private
@@ -430,4 +441,3 @@ class User < ActiveRecord::Base
end
end
-