diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/info_request.rb | 45 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 8 | ||||
-rw-r--r-- | app/models/post_redirect.rb | 6 | ||||
-rw-r--r-- | app/models/public_body.rb | 36 | ||||
-rw-r--r-- | app/models/user.rb | 1 | ||||
-rw-r--r-- | app/models/widget_vote.rb | 19 |
6 files changed, 81 insertions, 34 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 245de1e15..0ca3a1279 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -50,6 +50,7 @@ class InfoRequest < ActiveRecord::Base has_many :info_request_events, :order => 'created_at' has_many :user_info_request_sent_alerts has_many :track_things, :order => 'created_at desc' + has_many :widget_votes has_many :comments, :order => 'created_at' has_many :censor_rules, :order => 'created_at desc' has_many :mail_server_logs, :order => 'mail_server_log_done_id' @@ -901,21 +902,24 @@ public # Completely delete this request and all objects depending on it def fully_destroy - self.track_things.each do |track_thing| + track_things.each do |track_thing| track_thing.track_things_sent_emails.each { |a| a.destroy } track_thing.destroy end - self.user_info_request_sent_alerts.each { |a| a.destroy } - self.info_request_events.each do |info_request_event| + user_info_request_sent_alerts.each { |a| a.destroy } + info_request_events.each do |info_request_event| info_request_event.track_things_sent_emails.each { |a| a.destroy } info_request_event.destroy end - self.mail_server_logs.each do |mail_server_log| + mail_server_logs.each do |mail_server_log| mail_server_log.destroy end - self.outgoing_messages.each { |a| a.destroy } - self.incoming_messages.each { |a| a.destroy } - self.destroy + outgoing_messages.each { |a| a.destroy } + incoming_messages.each { |a| a.destroy } + comments.each { |comment| comment.destroy } + censor_rules.each{ |censor_rule| censor_rule.destroy } + + destroy end # Called by incoming_email - and used to be called to generate separate @@ -1355,6 +1359,30 @@ public order('last_event_time') end + def move_to_public_body(destination_public_body, opts = {}) + old_body = public_body + editor = opts.fetch(:editor) + + attrs = { :public_body => destination_public_body } + + if destination_public_body + attrs.merge!({ + :law_used => destination_public_body.law_only_short.downcase + }) + end + + if update_attributes(attrs) + log_event('move_request', + :editor => editor, + :public_body_url_name => public_body.url_name, + :old_public_body_url_name => old_body.url_name) + + reindex_request_events + + public_body + end + end + private def set_defaults @@ -1366,8 +1394,9 @@ public # this should only happen on Model.exists?() call. It can be safely ignored. # See http://www.tatvartha.com/2011/03/activerecordmissingattributeerror-missing-attribute-a-bug-or-a-features/ end + # FOI or EIR? - if !self.public_body.nil? && self.public_body.eir_only? + if new_record? && public_body && public_body.eir_only? self.law_used = 'eir' end end diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 635ba8f58..0ee82d30c 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -278,9 +278,15 @@ class InfoRequestEvent < ActiveRecord::Base end self.params_yaml = params.to_yaml end + def params - YAML.load(self.params_yaml) + param_hash = YAML.load(params_yaml) + param_hash.each do |key, value| + param_hash[key] = value.force_encoding('UTF-8') if value.respond_to?(:force_encoding) + end + param_hash end + def params_yaml_as_html ret = '' # split out parameters into old/new diffs, and other ones diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index 8049349d0..59160381c 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -71,7 +71,11 @@ class PostRedirect < ActiveRecord::Base end def reason_params - YAML.load(reason_params_yaml) + param_hash = YAML.load(reason_params_yaml) + param_hash.each do |key, value| + param_hash[key] = value.force_encoding('UTF-8') if value.respond_to?(:force_encoding) + end + param_hash end # Extract just local path part, without domain or # diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 232c0ffa1..dac77d4c5 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -339,19 +339,20 @@ class PublicBody < ActiveRecord::Base # Are all requests to this body under the Environmental Information Regulations? def eir_only? - return self.has_tag?('eir_only') + has_tag?('eir_only') end + def law_only_short - if self.eir_only? - return "EIR" - else - return "FOI" - end + eir_only? ? 'EIR' : 'FOI' end # Schools are allowed more time in holidays, so we change some wordings def is_school? - return self.has_tag?('school') + has_tag?('school') + end + + def site_administration? + has_tag?('site_administration') end # The "internal admin" is a special body for internal use. @@ -379,10 +380,6 @@ class PublicBody < ActiveRecord::Base end end - def site_administration? - has_tag?('site_administration') - end - class ImportCSVDryRun < StandardError end @@ -577,17 +574,11 @@ class PublicBody < ActiveRecord::Base return self.request_email_domain end - # Returns nil if configuration variable not set - def override_request_email - e = AlaveteliConfiguration::override_all_public_body_request_emails - e if e != "" - end - def request_email - if override_request_email - override_request_email - else + if AlaveteliConfiguration::override_all_public_body_request_emails.blank? || read_attribute(:request_email).blank? read_attribute(:request_email) + else + AlaveteliConfiguration::override_all_public_body_request_emails end end @@ -774,10 +765,7 @@ class PublicBody < ActiveRecord::Base end def empty_translation_in_params?(attributes) - attrs_with_values = attributes.select do |key, value| - value != '' and key.to_s != 'locale' - end - attrs_with_values.empty? + attributes.select { |k, v| !v.blank? && k.to_s != 'locale' }.empty? end def request_email_if_requestable diff --git a/app/models/user.rb b/app/models/user.rb index 920c0da46..1fb5d9139 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -38,6 +38,7 @@ class User < ActiveRecord::Base has_one :profile_photo has_many :censor_rules, :order => 'created_at desc' has_many :info_request_batches, :order => 'created_at desc' + has_many :request_classifications validates_presence_of :email, :message => _("Please enter your email address") validates_presence_of :name, :message => _("Please enter your name") diff --git a/app/models/widget_vote.rb b/app/models/widget_vote.rb new file mode 100644 index 000000000..021c38b30 --- /dev/null +++ b/app/models/widget_vote.rb @@ -0,0 +1,19 @@ +# == Schema Information +# +# Table name: widget_votes +# +# id :integer not null, primary key +# cookie :string(255) +# info_request_id :integer not null +# created_at :datetime not null +# updated_at :datetime not null +# + +class WidgetVote < ActiveRecord::Base + belongs_to :info_request + validates :info_request, :presence => true + + attr_accessible :cookie + validates :cookie, :length => { :is => 20 } + validates_uniqueness_of :cookie, :scope => :info_request_id +end |