From 018e04dd94503dec29fe13c8f1044a0fda887698 Mon Sep 17 00:00:00 2001 From: Faton Selishta Date: Thu, 2 Jun 2011 14:32:00 +0000 Subject: Specific code for our requirements (kosovo law, our request etc..) --- app/models/info_request.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 3441a73f7..5ce2be2df 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -57,6 +57,8 @@ class InfoRequest < ActiveRecord::Base 'waiting_response', 'waiting_clarification', 'gone_postal', + 'deadline_extended', + 'wrong_response', 'not_held', 'rejected', # this is called 'refused' in UK FOI law and the user interface, but 'rejected' internally for historic reasons 'successful', @@ -511,6 +513,9 @@ public # waiting_response_very_overdue def calculate_status return 'waiting_classification' if self.awaiting_description + # if deadline_extended expired do waiting_response_overdue + return 'waiting_response_overdue' if + self.described_state == "deadline_extended" && Time.now.strftime("%Y-%m-%d") > self.date_deadline_extended.strftime("%Y-%m-%d") return described_state unless self.described_state == "waiting_response" # Compare by date, so only overdue on next day, not if 1 second late return 'waiting_response_very_overdue' if @@ -608,7 +613,7 @@ public # last_event_forming_initial_request. There may be more obscure # things, e.g. fees, not properly covered. def date_response_required_by - return Holiday.due_date_from(self.date_initial_request_last_sent_at, 20) + return Holiday.due_date_from(self.date_initial_request_last_sent_at, 7) end # This is a long stop - even with UK public interest test extensions, 40 # days is a very long time. @@ -622,7 +627,10 @@ public return Holiday.due_date_from(self.date_initial_request_last_sent_at, 40) end end - + # deadline_extended + def date_deadline_extended + return Holiday.due_date_from(self.date_initial_request_last_sent_at, 15) + end # Where the initial request is sent to def recipient_email return self.public_body.request_email @@ -761,6 +769,10 @@ public "Waiting clarification." elsif status == 'gone_postal' "Handled by post." + elsif status == 'deadline_extended' + "Deadline extended." + elsif status == 'wrong_response' + "Wrong Response." elsif status == 'internal_review' "Awaiting internal review." elsif status == 'error_message' -- cgit v1.2.3 From 60ec0354c3385054f4224112fbbdb2cc0371820f Mon Sep 17 00:00:00 2001 From: Faton Selishta Date: Thu, 30 Jun 2011 16:17:42 +0200 Subject: I18n string for models --- app/models/info_request.rb | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 5ce2be2df..4e669e5cd 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -750,39 +750,39 @@ public def display_status status = self.calculate_status if status == 'waiting_classification' - "Awaiting classification." + _("Awaiting classification.") elsif status == 'waiting_response' - "Awaiting response." + _("Awaiting response.") elsif status == 'waiting_response_overdue' - "Delayed." + _("Delayed.") elsif status == 'waiting_response_very_overdue' - "Long overdue." + _("Long overdue.") elsif status == 'not_held' - "Information not held." + _("Information not held.") elsif status == 'rejected' - "Refused." + _("Refused.") elsif status == 'partially_successful' - "Partially successful." + _("Partially successful.") elsif status == 'successful' - "Successful." + _("Successful.") elsif status == 'waiting_clarification' - "Waiting clarification." + _("Waiting clarification.") elsif status == 'gone_postal' - "Handled by post." + _("Handled by post.") elsif status == 'deadline_extended' - "Deadline extended." + _("Deadline extended.") elsif status == 'wrong_response' - "Wrong Response." + _("Wrong Response.") elsif status == 'internal_review' - "Awaiting internal review." + _("Awaiting internal review.") elsif status == 'error_message' - "Delivery error" + _("Delivery error") elsif status == 'requires_admin' - "Unusual response." + _("Unusual response.") elsif status == 'user_withdrawn' - "Withdrawn by the requester." + _("Withdrawn by the requester.") else - raise "unknown status " + status + raise _("unknown status ") + status end end -- cgit v1.2.3 From b172995023ea90bac0bb534f8f185fa435f8aefd Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Wed, 6 Jul 2011 13:22:45 +0100 Subject: Changes required to get selishta (Kosovo) fork merges to pass tests. Includes new "REPLY_LATE_AFTER_DAYS" config option. --- app/models/info_request.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index a36b140b8..b9c39e89d 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -612,7 +612,8 @@ public # last_event_forming_initial_request. There may be more obscure # things, e.g. fees, not properly covered. def date_response_required_by - return Holiday.due_date_from(self.date_initial_request_last_sent_at, 7) + days_later = MySociety::Config.get('REPLY_LATE_AFTER_DAYS', 20) + return Holiday.due_date_from(self.date_initial_request_last_sent_at, days_later) end # This is a long stop - even with UK public interest test extensions, 40 # days is a very long time. -- cgit v1.2.3 From 35e4ffd67a383b36364c287b6e96e78aec3c4e15 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Thu, 7 Jul 2011 16:39:25 +0100 Subject: As a first attempt, in a dumb way, factor out jurisdiction-specific states to themes --- app/models/info_request.rb | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index b9c39e89d..07245bdfd 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -51,14 +51,12 @@ class InfoRequest < ActiveRecord::Base has_many :exim_logs, :order => 'exim_log_done_id' has_tag_string - - # user described state (also update in info_request_event, admin_request/edit.rhtml) - validates_inclusion_of :described_state, :in => [ + + def self.enumerate_states + states = [ 'waiting_response', 'waiting_clarification', 'gone_postal', - 'deadline_extended', - 'wrong_response', 'not_held', 'rejected', # this is called 'refused' in UK FOI law and the user interface, but 'rejected' internally for historic reasons 'successful', @@ -67,7 +65,16 @@ class InfoRequest < ActiveRecord::Base 'error_message', 'requires_admin', 'user_withdrawn' - ] + ] + begin + states += theme_extra_states + rescue NoMethodError + states + end + end + + # user described state (also update in info_request_event, admin_request/edit.rhtml) + validates_inclusion_of :described_state, :in => InfoRequest.enumerate_states validates_inclusion_of :prominence, :in => [ 'normal', @@ -94,6 +101,7 @@ class InfoRequest < ActiveRecord::Base 'blackhole' # just dump them ] + # only check on create, so existing models with mixed case are allowed def validate_on_create if !self.title.nil? && !MySociety::Validate.uses_mixed_capitals(self.title, 10) -- cgit v1.2.3 From 438367a13ae31fb7ebcc30bf4a9e82ec7e9f78a7 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Tue, 12 Jul 2011 10:51:30 +0100 Subject: Improve factoring out of custom states code (refactor a little, add tests) --- app/models/info_request.rb | 85 +++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 34 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 07245bdfd..16e66c44a 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -51,30 +51,9 @@ class InfoRequest < ActiveRecord::Base has_many :exim_logs, :order => 'exim_log_done_id' has_tag_string - - def self.enumerate_states - states = [ - 'waiting_response', - 'waiting_clarification', - 'gone_postal', - 'not_held', - 'rejected', # this is called 'refused' in UK FOI law and the user interface, but 'rejected' internally for historic reasons - 'successful', - 'partially_successful', - 'internal_review', - 'error_message', - 'requires_admin', - 'user_withdrawn' - ] - begin - states += theme_extra_states - rescue NoMethodError - states - end - end # user described state (also update in info_request_event, admin_request/edit.rhtml) - validates_inclusion_of :described_state, :in => InfoRequest.enumerate_states + validate :must_be_valid_state validates_inclusion_of :prominence, :in => [ 'normal', @@ -101,7 +80,31 @@ class InfoRequest < ActiveRecord::Base 'blackhole' # just dump them ] + def enumerate_states + states = [ + 'waiting_response', + 'waiting_clarification', + 'gone_postal', + 'not_held', + 'rejected', # this is called 'refused' in UK FOI law and the user interface, but 'rejected' internally for historic reasons + 'successful', + 'partially_successful', + 'internal_review', + 'error_message', + 'requires_admin', + 'user_withdrawn' + ] + + if @@custom_states_loaded + states += self.theme_extra_states + end + states + end + def must_be_valid_state + errors.add(:described_state, "is not a valid state") if + !self.enumerate_states.include? described_state + end # only check on create, so existing models with mixed case are allowed def validate_on_create if !self.title.nil? && !MySociety::Validate.uses_mixed_capitals(self.title, 10) @@ -118,6 +121,7 @@ class InfoRequest < ActiveRecord::Base OLD_AGE_IN_DAYS = 21.days def after_initialize + self.load_custom_states if self.described_state.nil? self.described_state = 'waiting_response' end @@ -127,6 +131,17 @@ class InfoRequest < ActiveRecord::Base end end + def load_custom_states + begin + # InfoRequestCustomStates may be `require`d in a theme + # plugin, or by a test + InfoRequest.send(:include, InfoRequestCustomStates) + @@custom_states_loaded = true + rescue NameError + @@custom_states_loaded = false + end + end + def visible_comments self.comments.find(:all, :conditions => 'visible') end @@ -520,10 +535,15 @@ public # waiting_response_overdue # waiting_response_very_overdue def calculate_status + if @@custom_states_loaded + return self.theme_calculate_status + else + self.base_calculate_status + end + end + + def base_calculate_status return 'waiting_classification' if self.awaiting_description - # if deadline_extended expired do waiting_response_overdue - return 'waiting_response_overdue' if - self.described_state == "deadline_extended" && Time.now.strftime("%Y-%m-%d") > self.date_deadline_extended.strftime("%Y-%m-%d") return described_state unless self.described_state == "waiting_response" # Compare by date, so only overdue on next day, not if 1 second late return 'waiting_response_very_overdue' if @@ -635,10 +655,7 @@ public return Holiday.due_date_from(self.date_initial_request_last_sent_at, 40) end end - # deadline_extended - def date_deadline_extended - return Holiday.due_date_from(self.date_initial_request_last_sent_at, 15) - end + # Where the initial request is sent to def recipient_email return self.public_body.request_email @@ -777,10 +794,6 @@ public _("Waiting clarification.") elsif status == 'gone_postal' _("Handled by post.") - elsif status == 'deadline_extended' - _("Deadline extended.") - elsif status == 'wrong_response' - _("Wrong Response.") elsif status == 'internal_review' _("Awaiting internal review.") elsif status == 'error_message' @@ -790,7 +803,11 @@ public elsif status == 'user_withdrawn' _("Withdrawn by the requester.") else - raise _("unknown status ") + status + begin + return self.theme_display_status(status) + rescue NoMethodError + raise _("unknown status ") + status + end end end -- cgit v1.2.3