From 7ae82024ad6c6850c0272776144499de5dae91b6 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Thu, 29 Sep 2016 21:15:13 +0200 Subject: [PATCH] Removed not used rss backend. --- .../app/controllers/_dashboard/rss.coffee | 52 ----------------- .../app/views/dashboard/rss.jst.eco | 11 ---- app/controllers/rss_controller.rb | 27 --------- config/routes/rss.rb | 7 --- lib/rss.rb | 38 ------------- lib/sessions/backend/rss.rb | 57 ------------------- lib/sessions/client.rb | 1 - test/unit/session_basic_test.rb | 16 ------ 8 files changed, 209 deletions(-) delete mode 100644 app/assets/javascripts/app/controllers/_dashboard/rss.coffee delete mode 100644 app/assets/javascripts/app/views/dashboard/rss.jst.eco delete mode 100644 app/controllers/rss_controller.rb delete mode 100644 config/routes/rss.rb delete mode 100644 lib/rss.rb delete mode 100644 lib/sessions/backend/rss.rb diff --git a/app/assets/javascripts/app/controllers/_dashboard/rss.coffee b/app/assets/javascripts/app/controllers/_dashboard/rss.coffee deleted file mode 100644 index 7a1536bd3..000000000 --- a/app/assets/javascripts/app/controllers/_dashboard/rss.coffee +++ /dev/null @@ -1,52 +0,0 @@ -class App.DashboardRss extends App.Controller - constructor: -> - super - - # bind to rebuild view event - @bind('rss_rebuild', @fetch) - - # refresh list ever 600 sec. - @fetch() - - fetch: => - - # get data from cache - cache = App.SessionStorage.get('dashboard_rss') - if cache - cache.head = 'Heise ATOM' - @render( cache ) - - # init fetch via ajax, all other updates on time via websockets - else - @ajax( - id: 'dashboard_rss' - type: 'GET' - url: @apiPath + '/rss_fetch' - data: { - limit: 8 - url: 'http://www.heise.de/newsticker/heise-atom.xml' - } - processData: true - success: (data) => - if data.message - @render( - head: 'Heise ATOM' - message: data.message - ) - else - App.SessionStorage.set('dashboard_rss', data) - data.head = 'Heise ATOM' - @render(data) - error: => - @render( - head: 'Heise ATOM' - message: 'Unable to fetch rss!' - ) - ) - - render: (data) -> - @html App.view('dashboard/rss')( - head: data.head, - items: data.items || [] - message: data.message - ) diff --git a/app/assets/javascripts/app/views/dashboard/rss.jst.eco b/app/assets/javascripts/app/views/dashboard/rss.jst.eco deleted file mode 100644 index 0d6b3b9ad..000000000 --- a/app/assets/javascripts/app/views/dashboard/rss.jst.eco +++ /dev/null @@ -1,11 +0,0 @@ -
-

<%- @T( @head ) %>

- <% if @message: %> - <%- @T(@message) %> - <% end %> - -
diff --git a/app/controllers/rss_controller.rb b/app/controllers/rss_controller.rb deleted file mode 100644 index 3ae495842..000000000 --- a/app/controllers/rss_controller.rb +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/ - -class RssController < ApplicationController - before_action :authentication_check - -=begin - -Resource: -GET /api/v1/rss_fetch - -Response: -{ - ... -} - -Test: -curl http://localhost/api/v1/rss_fetch.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X GET - -=end - - def fetch - items = Rss.fetch(params[:url], params[:limit]) - raise Exceptions::UnprocessableEntity, "failed to fetch #{params[:url]}" if items.nil? - render json: { items: items } - end - -end diff --git a/config/routes/rss.rb b/config/routes/rss.rb deleted file mode 100644 index 6476410b6..000000000 --- a/config/routes/rss.rb +++ /dev/null @@ -1,7 +0,0 @@ -Zammad::Application.routes.draw do - api_path = Rails.configuration.api_path - - # rss - match api_path + '/rss_fetch', to: 'rss#fetch', via: :get - -end diff --git a/lib/rss.rb b/lib/rss.rb deleted file mode 100644 index 34de4bb7f..000000000 --- a/lib/rss.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'simple-rss' -module Rss - def self.fetch(url, limit = 10) - cache_key = 'rss::' + url - items = Cache.get( cache_key ) - return items if items - - begin - Rails.logger.info "fetch rss... #{url}" - response = UserAgent.request(url) - if !response.success? - raise "Can't fetch '#{url}', http code: #{response.code}" - end - rss = SimpleRSS.parse response.body - items = [] - fetched = 0 - rss.items.each { |item| - record = { - id: item.id, - title: Encode.conv( 'utf8', item.title ), - summary: Encode.conv( 'utf8', item.summary ), - link: item.link, - published: item.published - } - items.push record - fetched += 1 - break item if fetched == limit.to_i - } - Cache.write( cache_key, items, expires_in: 4.hours ) - rescue => e - Rails.logger.error "can't fetch #{url}" - Rails.logger.error e.inspect - return - end - - items - end -end diff --git a/lib/sessions/backend/rss.rb b/lib/sessions/backend/rss.rb deleted file mode 100644 index 388ae733d..000000000 --- a/lib/sessions/backend/rss.rb +++ /dev/null @@ -1,57 +0,0 @@ -require 'rss' - -class Sessions::Backend::Rss < Sessions::Backend::Base - - def collection_key - "rss::load::#{self.class}::#{@user.id}" - end - - def load - - # check timeout - cache = Sessions::CacheIn.get(collection_key) - return cache if cache - - url = 'http://www.heise.de/newsticker/heise-atom.xml' - rss_items = Rss.fetch(url, 8) - - # set new timeout - Sessions::CacheIn.set(collection_key, rss_items, { expires_in: 1.hour }) - - rss_items - end - - def client_key - "rss::load::#{self.class}::#{@user.id}::#{@client_id}" - end - - def push - - # check timeout - timeout = Sessions::CacheIn.get(client_key) - return if timeout - - # set new timeout - Sessions::CacheIn.set(client_key, true, { expires_in: @ttl.seconds }) - - data = load - - return if !data || data.empty? - - if !@client - return { - event: 'rss_rebuild', - collection: 'dashboard_rss', - data: data, - } - end - - @client.log "push rss for user #{@user.id}" - @client.send( - event: 'rss_rebuild', - collection: 'dashboard_rss', - data: data, - ) - end - -end diff --git a/lib/sessions/client.rb b/lib/sessions/client.rb index 35daf84a6..ca012d931 100644 --- a/lib/sessions/client.rb +++ b/lib/sessions/client.rb @@ -12,7 +12,6 @@ class Sessions::Client backends = [ 'Sessions::Backend::TicketOverviewList', 'Sessions::Backend::Collections', - 'Sessions::Backend::Rss', 'Sessions::Backend::ActivityStream', 'Sessions::Backend::TicketCreate', ] diff --git a/test/unit/session_basic_test.rb b/test/unit/session_basic_test.rb index d267c4e25..307fe140e 100644 --- a/test/unit/session_basic_test.rb +++ b/test/unit/session_basic_test.rb @@ -186,22 +186,6 @@ class SessionBasicTest < ActiveSupport::TestCase assert_equal(result1, result2, 'check collections') end - test 'c rss' do - user = User.lookup(id: 1) - collection_client1 = Sessions::Backend::Rss.new(user, {}, false, '123-1') - - # get whole collections - result1 = collection_client1.push - #puts "RSS1: #{result1.inspect}" - assert(!result1.empty?, 'check rss') - sleep 0.5 - - # next check should be empty - result1 = collection_client1.push - #puts "R1: #{result1.inspect}" - assert(!result1, 'check rss - recall') - end - test 'c activity stream' do # create users