From 513e695894ef81d38d5b4926fbfbe63ffcbc87f9 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 29 Sep 2015 10:23:13 +0200 Subject: [PATCH] Fixed time zone naming. Also set default calendars on init setup based on browsers location. Ignore private ip ranges of browsers. --- app/assets/javascripts/app/models/calendar.coffee | 2 +- app/assets/javascripts/app/views/calendar/index.jst.eco | 2 +- app/controllers/getting_started_controller.rb | 4 +--- app/models/calendar.rb | 5 +++++ lib/service/geo_calendar/zammad.rb | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/models/calendar.coffee b/app/assets/javascripts/app/models/calendar.coffee index add3b4131..a50aa51a4 100644 --- a/app/assets/javascripts/app/models/calendar.coffee +++ b/app/assets/javascripts/app/models/calendar.coffee @@ -5,7 +5,7 @@ class App.Calendar extends App.Model @configure_attributes = [ { name: 'name', display: 'Name', tag: 'input', type: 'text', limit: 100, null: false }, - { name: 'timezone', display: 'Timezone', tag: 'timezone', null: false } + { name: 'timezone', display: 'Time zone', tag: 'timezone', null: false } { name: 'business_hours', display: 'Business Hours', tag: 'business_hours', null: true } { name: 'ical_url', display: 'Holidays iCalendar Feed', tag: 'ical_feed', placeholder: 'http://example.com/public_holidays.ical', null: true } { name: 'public_holidays',display: 'Holidays', tag: 'holiday_selector', null: true } diff --git a/app/assets/javascripts/app/views/calendar/index.jst.eco b/app/assets/javascripts/app/views/calendar/index.jst.eco index a22aa2311..949981e74 100644 --- a/app/assets/javascripts/app/views/calendar/index.jst.eco +++ b/app/assets/javascripts/app/views/calendar/index.jst.eco @@ -33,7 +33,7 @@ <% if calendar.last_log: %>
<%= calendar.last_log %>
<% end %>
-
<%- @T('Timezone') %>
<%= calendar.timezone %> +
<%- @T('Time zone') %>
<%= calendar.timezone %>
<%- @T('Business Hours') %>
diff --git a/app/controllers/getting_started_controller.rb b/app/controllers/getting_started_controller.rb index 48b30a26b..8b61226dd 100644 --- a/app/controllers/getting_started_controller.rb +++ b/app/controllers/getting_started_controller.rb @@ -43,6 +43,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} end # return result + Calendar.init_setup(request.remote_ip) render json: { setup_done: setup_done, import_mode: Setting.get('import_mode'), @@ -212,10 +213,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password} def setup_done_response return false if !setup_done - # get all groups groups = Group.where( active: true ) - - # get email addresses addresses = EmailAddress.where( active: true ) render json: { diff --git a/app/models/calendar.rb b/app/models/calendar.rb index d91064d99..ffe2aa068 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -22,6 +22,11 @@ returns calendar object def self.init_setup(ip = nil) + # ignore client ip if not public ip + if ip && ip =~ /^(::1|127\.|10\.|172\.1[6-9]\.|172\.2[0-9]\.|172\.3[0-1]\.|192\.168\.)/ + ip = nil + end + # call for calendar suggestion calendar_details = Service::GeoCalendar.location(ip) return if !calendar_details diff --git a/lib/service/geo_calendar/zammad.rb b/lib/service/geo_calendar/zammad.rb index d4ce1d4ef..602203e9b 100644 --- a/lib/service/geo_calendar/zammad.rb +++ b/lib/service/geo_calendar/zammad.rb @@ -34,7 +34,7 @@ class Service::GeoCalendar::Zammad data = response.data - Cache.write( cache_key, data, { expires_in: 1.day } ) + Cache.write( cache_key, data, { expires_in: 30.minutes } ) rescue => e Rails.logger.error "#{host}#{url}: #{e.inspect}" Cache.write( cache_key, data, { expires_in: 1.minutes } )