diff options
-rwxr-xr-x | app/helpers/link_to_helper.rb | 3 | ||||
-rw-r--r-- | app/views/general/advanced_search.rhtml | 0 | ||||
-rw-r--r-- | app/views/help/_sidebar.rhtml | 2 | ||||
-rw-r--r-- | config/general.yml-example | 3 | ||||
-rw-r--r-- | config/test.yml | 4 | ||||
-rw-r--r-- | lib/configuration.rb | 2 | ||||
-rw-r--r-- | lib/tasks/stats.rake | 96 | ||||
-rw-r--r-- | lib/tasks/translation.rake | 2 | ||||
-rw-r--r-- | spec/helpers/link_to_helper_spec.rb | 25 | ||||
-rw-r--r-- | spec/models/request_mailer_spec.rb | 30 |
10 files changed, 134 insertions, 33 deletions
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index c8ad7bc30..e4e52427b 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -222,8 +222,7 @@ module LinkToHelper # Admin pages def admin_url(relative_path) admin_url_prefix = Configuration::admin_base_url - admin_url_prefix = admin_general_index_path+"/" if admin_url_prefix.empty? - return admin_url_prefix + relative_path + (admin_url_prefix.empty? ? admin_general_index_url + '/' : admin_url_prefix) + relative_path end # About page URLs diff --git a/app/views/general/advanced_search.rhtml b/app/views/general/advanced_search.rhtml deleted file mode 100644 index e69de29bb..000000000 --- a/app/views/general/advanced_search.rhtml +++ /dev/null diff --git a/app/views/help/_sidebar.rhtml b/app/views/help/_sidebar.rhtml index 21038e8df..783d35983 100644 --- a/app/views/help/_sidebar.rhtml +++ b/app/views/help/_sidebar.rhtml @@ -8,7 +8,7 @@ <li><%= link_to_unless_current "About the software", "/help/alaveteli" %></li> <li><%= link_to_unless_current "Credits", "/help/credits" %></li> <li><%= link_to_unless_current "Programmers API", "/help/api" %></li> - <li><%= link_to_unless_current "Advanced search", "/search" %></li> + <li><%= link_to_unless_current "Advanced search", "/advancedsearch" %></li> </ul> <h2 id="contact">Contact us</h2> diff --git a/config/general.yml-example b/config/general.yml-example index 97af5f61d..b457b5ed6 100644 --- a/config/general.yml-example +++ b/config/general.yml-example @@ -83,7 +83,8 @@ TRACK_SENDER_NAME: 'Alaveteli Webmaster' # this up! RAW_EMAILS_LOCATION: 'files/raw_emails' -# The base URL for admin pages. +# The base URL for admin pages, must always end with a '/' +# e.g. https://www.example.com/secure/alaveteli-admin/ # If not specified, it will default to the path to the admin controller, # which is usually what you want. It is useful in situations where admin # requests are proxied via a secure server, for example. diff --git a/config/test.yml b/config/test.yml index 5811b1785..ef270dcf2 100644 --- a/config/test.yml +++ b/config/test.yml @@ -72,7 +72,7 @@ CONTACT_NAME: 'Alaveteli Webmaster' RAW_EMAILS_LOCATION: 'files/raw_emails' # The base URL for admin pages. You probably don't want to change this. -ADMIN_BASE_URL: '/admin/' +ADMIN_BASE_URL: '' # Where /stylesheets sits under for admin pages. See asset_host in # config/environment.rb. Can be full domain or relative path (not an @@ -125,4 +125,4 @@ EXCEPTION_NOTIFICATIONS_TO: MAX_REQUESTS_PER_USER_PER_DAY: 2 VARNISH_HOST: varnish.localdomain -SKIP_ADMIN_AUTH: true
\ No newline at end of file +SKIP_ADMIN_AUTH: true diff --git a/lib/configuration.rb b/lib/configuration.rb index e52f6e956..5f761a1f6 100644 --- a/lib/configuration.rb +++ b/lib/configuration.rb @@ -4,7 +4,7 @@ module Configuration DEFAULTS = { - :ADMIN_BASE_URL => '/admin/', + :ADMIN_BASE_URL => '', :ADMIN_PASSWORD => '', :ADMIN_PUBLIC_URL => '', :ADMIN_USERNAME => '', diff --git a/lib/tasks/stats.rake b/lib/tasks/stats.rake index e1b58905d..9d7d70540 100644 --- a/lib/tasks/stats.rake +++ b/lib/tasks/stats.rake @@ -1,48 +1,94 @@ -namespace :stats do - - desc 'Produce transaction stats' - task :show => :environment do +namespace :stats do + + desc 'Produce transaction stats' + task :show => :environment do month_starts = (Date.new(2009, 1)..Date.new(2011, 8)).select { |d| d.day == 1 } headers = ['Period', - 'Requests sent', - 'Annotations added', - 'Track this request email signups', - 'Comments on own requests', + 'Requests sent', + 'Annotations added', + 'Track this request email signups', + 'Comments on own requests', 'Follow up messages sent'] puts headers.join("\t") month_starts.each do |month_start| month_end = month_start.end_of_month period = "#{month_start}-#{month_end}" - date_conditions = ['created_at >= ? - AND created_at < ?', + date_conditions = ['created_at >= ? + AND created_at < ?', month_start, month_end+1] request_count = InfoRequest.count(:conditions => date_conditions) comment_count = Comment.count(:conditions => date_conditions) - track_conditions = ['track_type = ? - AND track_medium = ? - AND created_at >= ? - AND created_at < ?', + track_conditions = ['track_type = ? + AND track_medium = ? + AND created_at >= ? + AND created_at < ?', 'request_updates', 'email_daily', month_start, month_end+1] email_request_track_count = TrackThing.count(:conditions => track_conditions) - comment_on_own_request_conditions = ['comments.user_id = info_requests.user_id - AND comments.created_at >= ? + comment_on_own_request_conditions = ['comments.user_id = info_requests.user_id + AND comments.created_at >= ? AND comments.created_at < ?', month_start, month_end+1] comment_on_own_request_count = Comment.count(:conditions => comment_on_own_request_conditions, :include => :info_request) - - followup_conditions = ['message_type = ? - AND created_at >= ? + + followup_conditions = ['message_type = ? + AND created_at >= ? AND created_at < ?', 'followup', month_start, month_end+1] follow_up_count = OutgoingMessage.count(:conditions => followup_conditions) - puts [period, - request_count, - comment_count, - email_request_track_count, - comment_on_own_request_count, + puts [period, + request_count, + comment_count, + email_request_track_count, + comment_on_own_request_count, follow_up_count].join("\t") end end - + + desc 'Produce stats on volume of requests to authorities matching a set of tags. Specify tags as TAGS=tagone,tagtwo' + task :volumes_by_authority_tag => :environment do + tags = ENV['TAGS'].split(',') + first_request_datetime = InfoRequest.minimum(:created_at) + start_year = first_request_datetime.strftime("%Y").to_i + start_month = first_request_datetime.strftime("%m").to_i + end_year = Time.now.strftime("%Y").to_i + end_month = Time.now.strftime("%m").to_i + puts "Start year: #{start_year}" + puts "Start month: #{start_month}" + puts "End year: #{end_year}" + puts "End month: #{end_month}" + public_bodies = [] + tags.each do |tag| + tag_bodies = PublicBody.find_by_tag(tag) + puts "Bodies with tag '#{tag}': #{tag_bodies.size}" + public_bodies += tag_bodies + end + public_body_ids = public_bodies.map{ |body| body.id }.uniq + public_body_condition_string = 'AND public_bodies.id in (?)' + month_starts = (Date.new(start_year, start_month)..Date.new(end_year, end_month)).select { |d| d.day == 1 } + headers = ['Period', + 'Requests sent', + 'Requests sent as % of total sent in period'] + puts headers.join("\t") + month_starts.each do |month_start| + month_end = month_start.end_of_month + period = "#{month_start}-#{month_end}" + date_condition_string = 'info_requests.created_at >= ? AND info_requests.created_at < ?' + conditions = [date_condition_string + " " + public_body_condition_string, + month_start, + month_end+1, + public_body_ids] + request_count = InfoRequest.count(:conditions => conditions, + :include => :public_body) + + total_count = InfoRequest.count(:conditions => [date_condition_string, month_start, month_end+1]) + if total_count > 0 + percent = ((request_count.to_f / total_count.to_f ) * 100).round(2) + else + percent = 0.0 + end + puts [period, request_count, percent].join("\t") + end + end + end diff --git a/lib/tasks/translation.rake b/lib/tasks/translation.rake index 0eb39f5e7..f6611cc80 100644 --- a/lib/tasks/translation.rake +++ b/lib/tasks/translation.rake @@ -156,7 +156,7 @@ namespace :translation do write_email(event_digest_email, 'Alerts on things the user is tracking', output_file) # user mailer - site_name = MySociety::Config.get('SITE_NAME', 'Alaveteli') + site_name = Configuration::site_name reasons = { :web => "", :email => _("Then you can sign in to {{site_name}}", :site_name => site_name), diff --git a/spec/helpers/link_to_helper_spec.rb b/spec/helpers/link_to_helper_spec.rb index 9ec0afce1..ef89e8bf9 100644 --- a/spec/helpers/link_to_helper_spec.rb +++ b/spec/helpers/link_to_helper_spec.rb @@ -48,4 +48,29 @@ describe LinkToHelper do end + describe 'admin_url' do + context 'with no ADMIN_BASE_URL set' do + it 'should prepend the admin general index path to a simple string' do + admin_url('unclassified').should == 'http://test.host/en/admin/unclassified' + end + + it 'should prepend the admin general index path to a deeper URL' do + admin_url('request/show/123').should == 'http://test.host/en/admin/request/show/123' + end + end + + context 'with ADMIN_BASE_URL set' do + before(:each) do + Configuration::should_receive(:admin_base_url).and_return('https://www.example.com/secure/alaveteli-admin/') + end + + it 'should prepend the admin base URL to a simple string' do + admin_url('unclassified').should == 'https://www.example.com/secure/alaveteli-admin/unclassified' + end + + it 'should prepend the admin base URL to a deeper URL' do + admin_url('request/show/123').should == 'https://www.example.com/secure/alaveteli-admin/request/show/123' + end + end + end end diff --git a/spec/models/request_mailer_spec.rb b/spec/models/request_mailer_spec.rb index 84804d4ca..906756784 100644 --- a/spec/models/request_mailer_spec.rb +++ b/spec/models/request_mailer_spec.rb @@ -327,3 +327,33 @@ describe RequestMailer, 'when sending mail when someone has updated an old uncla end +describe RequestMailer, 'requires_admin' do + before(:each) do + user = mock_model(User, :name_and_email => 'Bruce Jones', + :name => 'Bruce Jones') + @info_request = mock_model(InfoRequest, :user => user, + :described_state => 'error_message', + :title => 'Test request', + :url_title => 'test_request', + :law_used_short => 'FOI', + :id => 123) + end + + it 'body should contain the full admin URL' do + mail = RequestMailer.deliver_requires_admin(@info_request) + + mail.body.should include('http://test.host/en/admin/request/show/123') + end + + context 'has an ADMIN_BASE_URL set' do + before(:each) do + Configuration::should_receive(:admin_base_url).and_return('http://our.proxy.server/admin/alaveteli/') + end + + it 'body should contain the full admin URL' do + mail = RequestMailer.deliver_requires_admin(@info_request) + + mail.body.should include('http://our.proxy.server/admin/alaveteli/request/show/123') + end + end +end |