From 8308f4e115fcf51ec5d528e55af7e454963ce7aa Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 22 Mar 2013 10:03:20 +1100 Subject: Remove apparently unused action for showing random request --- app/models/info_request.rb | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 156399b99..666cc642f 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1070,25 +1070,6 @@ public InfoRequest.update_all "allow_new_responses_from = 'nobody' where updated_at < (now() - interval '1 year') and allow_new_responses_from in ('anybody', 'authority_only') and url_title <> 'holding_pen'" end - # Returns a random FOI request - def InfoRequest.random - max_id = InfoRequest.connection.select_value('select max(id) as a from info_requests').to_i - info_request = nil - count = 0 - while info_request.nil? - if count > 100 - return nil - end - id = rand(max_id) + 1 - begin - count += 1 - info_request = find(id, :conditions => ["prominence = 'normal'"]) - rescue ActiveRecord::RecordNotFound - end - end - return info_request - end - def json_for_api(deep) ret = { :id => self.id, -- cgit v1.2.3 From ca4ae410e70ab490ae4c8cad8839f41783c89ef7 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 22 Mar 2013 15:02:30 +1100 Subject: Extract method --- app/models/info_request.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 156399b99..83a57b4b2 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -555,6 +555,13 @@ public ['requires_admin', 'error_message', 'attention_requested'].include?(described_state) end + # Report this request for administrator attention + def report!(reason, message, user) + set_described_state('attention_requested', user, "Reason: #{reason}\n\n#{message}") + self.attention_requested = true # tells us if attention has ever been requested + save! + end + # change status, including for last event for later historical purposes def set_described_state(new_state, set_by = nil, message = "") old_described_state = described_state -- cgit v1.2.3 From 0078c3d4eacb3107766a057a42644b9066f15c4a Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 22 Mar 2013 15:06:24 +1100 Subject: Wrap in a transaction --- app/models/info_request.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 83a57b4b2..f63c10e0a 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -557,9 +557,11 @@ public # Report this request for administrator attention def report!(reason, message, user) - set_described_state('attention_requested', user, "Reason: #{reason}\n\n#{message}") - self.attention_requested = true # tells us if attention has ever been requested - save! + ActiveRecord::Base.transaction do + set_described_state('attention_requested', user, "Reason: #{reason}\n\n#{message}") + self.attention_requested = true # tells us if attention has ever been requested + save! + end end # change status, including for last event for later historical purposes -- cgit v1.2.3 From 57ed2c6f014e07d242ae7ffe147c1bd215764669 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 22 Mar 2013 17:24:40 +1100 Subject: Reasons that request can be reported now stored in model --- app/models/info_request.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index f63c10e0a..68b837c7d 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -108,6 +108,12 @@ class InfoRequest < ActiveRecord::Base states end + # Possible reasons that a request could be reported for administrator attention + def report_reasons + ["Contains defamatory material", "Not a valid request", "Request for personal information", + "Contains personal information", "Vexatious", "Other"] + end + def must_be_valid_state errors.add(:described_state, "is not a valid state") if !InfoRequest.enumerate_states.include? described_state -- cgit v1.2.3 From 060d9fe70a1de0ba9aa592d25d6e7352114aa431 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 25 Mar 2013 16:17:03 +1100 Subject: Inline method InfoRequest.full_search --- app/models/info_request.rb | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 156399b99..4db4dadb0 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -189,21 +189,6 @@ class InfoRequest < ActiveRecord::Base self.comments.find(:all, :conditions => 'visible') end - # Central function to do all searches - # (Not really the right place to put it, but everything can get it here, and it - # does *mainly* find info requests, via their events, so hey) - def InfoRequest.full_search(models, query, order, ascending, collapse, per_page, page) - offset = (page - 1) * per_page - - return ::ActsAsXapian::Search.new( - models, query, - :offset => offset, :limit => per_page, - :sort_by_prefix => order, - :sort_by_ascending => ascending, - :collapse_by_prefix => collapse - ) - end - # If the URL name has changed, then all request: queries will break unless # we update index for every event. Also reindex if prominence changes. after_update :reindex_some_request_events -- cgit v1.2.3 From b340c98efcdf41a3c189631e4af5042d507ecf4d Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Mon, 25 Mar 2013 16:21:46 +1100 Subject: Remove unused method --- app/models/info_request.rb | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 4db4dadb0..499fb20a9 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -217,17 +217,6 @@ class InfoRequest < ActiveRecord::Base end end - # For debugging - def InfoRequest.profile_search(query) - t = Time.now.usec - for i in (1..10) - t = Time.now.usec - t - secs = t / 1000000.0 - STDOUT.write secs.to_s + " query " + i.to_s + "\n" - results = InfoRequest.full_search([InfoRequestEvent], query, "created_at", true, nil, 25, 1).results - end - end - public # When name is changed, also change the url name def title=(title) -- cgit v1.2.3 From 3f306d3126e32cd64c2a691accd1af0a91c9aa48 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 29 Mar 2013 11:15:29 +1100 Subject: Inline method and simplify logic --- app/models/info_request.rb | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 156399b99..033bff036 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -351,7 +351,10 @@ public # copying an email, and that doesn't matter) def InfoRequest.find_by_incoming_email(incoming_email) id, hash = InfoRequest._extract_id_hash_from_email(incoming_email) - return self.find_by_magic_email(id, hash) + if hash_from_id(id) == hash + # Not using find(id) because we don't exception raised if nothing found + find_by_id(id) + end end # Return list of info requests which *might* be right given email address @@ -902,24 +905,6 @@ public return Digest::SHA1.hexdigest(id.to_s + AlaveteliConfiguration::incoming_email_secret)[0,8] end - # Called by find_by_incoming_email - and used to be called by separate - # function for envelope from address, until we abandoned it. - def InfoRequest.find_by_magic_email(id, hash) - expected_hash = InfoRequest.hash_from_id(id) - #print "expected: " + expected_hash + "\nhash: " + hash + "\n" - if hash != expected_hash - return nil - else - begin - return self.find(id) - rescue ActiveRecord::RecordNotFound - # so error email is sent to admin, rather than the exception sending weird - # error to the public body. - return nil - end - end - end - # Used to find when event last changed def InfoRequest.last_event_time_clause(event_type=nil) event_type_clause = '' -- cgit v1.2.3 From eaac2442efad02556d219c205aa27c52c2d68cbf Mon Sep 17 00:00:00 2001 From: Louise Crow Date: Fri, 7 Jun 2013 10:38:13 +0100 Subject: Handle request for json for an external request. Closes #973. --- app/models/info_request.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index aaf171c4c..a7d482930 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -156,6 +156,10 @@ class InfoRequest < ActiveRecord::Base end end + def user_json_for_api + is_external? ? { :name => user_name || _("Anonymous user") } : user.json_for_api + end + @@custom_states_loaded = false begin if !Rails.env.test? -- cgit v1.2.3