From db29673a4cd84f90f59ca8315a21b12a862cd78a Mon Sep 17 00:00:00 2001 From: Du Peng Date: Wed, 15 Jan 2020 12:34:51 +0100 Subject: [PATCH] remove twitter api for get latest tweet --- app/assets/javascripts/controllers/home.js | 11 ++--------- app/assets/javascripts/services/twitter.js | 5 ----- app/controllers/api/feeds_controller.rb | 23 ---------------------- app/models/feed.rb | 10 ---------- config/application.yml.default | 7 +------ config/initializers/twitter.rb | 6 ------ config/routes.rb | 1 - doc/environment.md | 13 +++--------- setup/env.example | 4 ---- setup/setup.sh | 5 ++--- 10 files changed, 8 insertions(+), 77 deletions(-) delete mode 100644 app/assets/javascripts/services/twitter.js delete mode 100644 app/controllers/api/feeds_controller.rb delete mode 100644 app/models/feed.rb delete mode 100644 config/initializers/twitter.rb diff --git a/app/assets/javascripts/controllers/home.js b/app/assets/javascripts/controllers/home.js index 48163226b..a4110c975 100644 --- a/app/assets/javascripts/controllers/home.js +++ b/app/assets/javascripts/controllers/home.js @@ -10,16 +10,13 @@ */ 'use strict'; -Application.Controllers.controller('HomeController', ['$scope', '$stateParams', 'Twitter', 'lastMembersPromise', 'lastProjectsPromise', 'upcomingEventsPromise', 'homeBlogpostPromise', 'twitterNamePromise', - function ($scope, $stateParams, Twitter, lastMembersPromise, lastProjectsPromise, upcomingEventsPromise, homeBlogpostPromise, twitterNamePromise) { +Application.Controllers.controller('HomeController', ['$scope', '$stateParams', 'lastMembersPromise', 'lastProjectsPromise', 'upcomingEventsPromise', 'homeBlogpostPromise', 'twitterNamePromise', + function ($scope, $stateParams, lastMembersPromise, lastProjectsPromise, upcomingEventsPromise, homeBlogpostPromise, twitterNamePromise) { /* PUBLIC SCOPE */ // The last registered members who confirmed their addresses $scope.lastMembers = lastMembersPromise; - // The last tweets from the Fablab official twitter account - $scope.lastTweets = []; - // The last projects published/documented on the plateform $scope.lastProjects = lastProjectsPromise; @@ -45,10 +42,6 @@ Application.Controllers.controller('HomeController', ['$scope', '$stateParams', * Kind of constructor: these actions will be realized first when the controller is loaded */ const initialize = function () { - // we retrieve tweets from here instead of ui-router's promise because, if adblock stop the API request, - // this prevent the whole home page to be blocked - $scope.lastTweets = Twitter.query({ limit: 1 }); - // if we recieve a token to reset the password as GET parameter, trigger the // changePassword modal from the parent controller if ($stateParams.reset_password_token) { diff --git a/app/assets/javascripts/services/twitter.js b/app/assets/javascripts/services/twitter.js deleted file mode 100644 index 45b2ae3d4..000000000 --- a/app/assets/javascripts/services/twitter.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -Application.Services.factory('Twitter', ['$resource', function ($resource) { - return $resource('/api/feeds/twitter_timelines'); -}]); diff --git a/app/controllers/api/feeds_controller.rb b/app/controllers/api/feeds_controller.rb deleted file mode 100644 index f98154408..000000000 --- a/app/controllers/api/feeds_controller.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -# API Controller to wrap social networks public feeds -class API::FeedsController < API::ApiController - - respond_to :json - - def twitter_timelines - limit = if params - params[:limit] - else - 3 - end - from_account = Setting.find_by(name: 'twitter_name').try(:value) || ENV['TWITTER_NAME'] - begin - @tweet_news = Feed.twitter.user_timeline(from_account, count: limit) - rescue Twitter::Error::BadRequest => e - STDERR.puts "[WARNING] Unable to retrieve the twitter feed, please check your ENV configuration. Details: #{e.message}" - render status: :no_content - end - end - -end diff --git a/app/models/feed.rb b/app/models/feed.rb deleted file mode 100644 index 52f190d32..000000000 --- a/app/models/feed.rb +++ /dev/null @@ -1,10 +0,0 @@ -class Feed - mattr_accessor :twitter do - Twitter::REST::Client.new do |config| - config.consumer_key = ENV['TWITTER_CONSUMER_KEY'] - config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET'] - config.access_token = ENV['TWITTER_ACCESS_TOKEN'] - config.access_token_secret = ENV['TWITTER_ACCESS_TOKEN_SECRET'] - end - end -end diff --git a/config/application.yml.default b/config/application.yml.default index 19d994944..790a7ee6d 100644 --- a/config/application.yml.default +++ b/config/application.yml.default @@ -54,12 +54,8 @@ RECAPTCHA_SECRET_KEY: '' # Projects comments DISQUS_SHORTNAME: -# Twitter sharing & last tweet on home page +# Twitter sharing TWITTER_NAME: 'FablabGrenoble' -TWITTER_CONSUMER_KEY: '' -TWITTER_CONSUMER_SECRET: '' -TWITTER_ACCESS_TOKEN: '' -TWITTER_ACCESS_TOKEN_SECRET: '' # Facebook sharing FACEBOOK_APP_ID: '' @@ -102,4 +98,3 @@ MAX_IMPORT_SIZE: '5242880' MAX_IMAGE_SIZE: '10485760' # 20971520 = 20 megabytes MAX_CAO_SIZE: '20971520' - diff --git a/config/initializers/twitter.rb b/config/initializers/twitter.rb deleted file mode 100644 index 6f9a4e93e..000000000 --- a/config/initializers/twitter.rb +++ /dev/null @@ -1,6 +0,0 @@ -Feed.twitter = Twitter::REST::Client.new do |config| - config.consumer_key = ENV['TWITTER_CONSUMER_KEY'] - config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET'] - config.access_token = ENV['TWITTER_ACCESS_TOKEN'] - config.access_token_secret = ENV['TWITTER_ACCESS_TOKEN_SECRET'] -end diff --git a/config/routes.rb b/config/routes.rb index 8894a62a3..5d4647f34 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -72,7 +72,6 @@ Rails.application.routes.draw do # for homepage get '/last_subscribed/:last' => 'members#last_subscribed' - get '/feeds/twitter_timelines' => 'feeds#twitter_timelines' get 'pricing' => 'pricing#index' put 'pricing' => 'pricing#update' diff --git a/doc/environment.md b/doc/environment.md index 07252f308..400780ab0 100644 --- a/doc/environment.md +++ b/doc/environment.md @@ -99,7 +99,7 @@ Valid stripe API keys are still required, even if you don't require online payme FABLAB_WITHOUT_INVOICES -If set to 'true', the invoices will be disabled. +If set to 'true', the invoices will be disabled. This is useful if you have your own invoicing system and you want to prevent Fab-manager from generating and sending invoices to members. **Very important**: if you disable invoices, you still have to configure VAT in the interface to prevent errors in accounting and prices. @@ -167,15 +167,8 @@ See https://help.disqus.com/customer/portal/articles/466208-what-s-a-shortname- TWITTER_NAME -Identifier of the Twitter account, from witch the last tweet will be fetched and displayed on the home page. -This value can be graphically overridden during the application's lifecycle in Admin/Customization/Home page/Twitter Feed. +Identifier of the Twitter account for Twitter share project, event or training It will also be used for [Twitter Card analytics](https://dev.twitter.com/cards/analytics). - - - TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET, TWITTER_ACCESS_TOKEN & TWITTER_ACCESS_TOKEN_SECRET - -Keys and secrets to access the twitter API. -Retrieve them from https://apps.twitter.co. FACEBOOK_APP_ID @@ -358,7 +351,7 @@ Accordingly, `RAILS_LOCALE` and `APP_LOCALE` must be configured to `ach`. OPENLAB_APP_ID, OPENLAB_APP_SECRET -This configuration is optional and can only work in production mode. +This configuration is optional and can only work in production mode. It allows you to display a shared projects gallery and to share your projects with other fablabs. Send an email to **contact@fab-manager.com** to get your OpenLab client's credentials. diff --git a/setup/env.example b/setup/env.example index 6db0127c9..7591de428 100644 --- a/setup/env.example +++ b/setup/env.example @@ -40,10 +40,6 @@ RECAPTCHA_SECRET_KEY= DISQUS_SHORTNAME= TWITTER_NAME=FablabGrenoble -TWITTER_CONSUMER_KEY= -TWITTER_CONSUMER_SECRET= -TWITTER_ACCESS_TOKEN= -TWITTER_ACCESS_TOKEN_SECRET= FACEBOOK_APP_ID= diff --git a/setup/setup.sh b/setup/setup.sh index b43076403..159b4c44d 100755 --- a/setup/setup.sh +++ b/setup/setup.sh @@ -212,8 +212,8 @@ configure_env_file() doc=$(\curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/doc/environment.md) variables=(STRIPE_API_KEY STRIPE_PUBLISHABLE_KEY STRIPE_CURRENCY INVOICE_PREFIX FABLAB_WITHOUT_PLANS FABLAB_WITHOUT_SPACES FABLAB_WITHOUT_ONLINE_PAYMENT FABLAB_WITHOUT_INVOICES \ PHONE_REQUIRED USER_CONFIRMATION_NEEDED_TO_SIGN_IN EVENTS_IN_CALENDAR SLOT_DURATION DEFAULT_MAIL_FROM DELIVERY_METHOD DEFAULT_HOST DEFAULT_PROTOCOL SMTP_ADDRESS SMTP_PORT SMTP_USER_NAME SMTP_PASSWORD SMTP_AUTHENTICATION \ - SMTP_ENABLE_STARTTLS_AUTO SMTP_OPENSSL_VERIFY_MODE SMTP_TLS GA_ID RECAPTCHA_SITE_KEY RECAPTCHA_SECRET_KEY DISQUS_SHORTNAME TWITTER_NAME TWITTER_CONSUMER_KEY TWITTER_CONSUMER_SECRET \ - TWITTER_ACCESS_TOKEN TWITTER_ACCESS_TOKEN_SECRET FACEBOOK_APP_ID LOG_LEVEL ALLOWED_EXTENSIONS ALLOWED_MIME_TYPES MAX_IMAGE_SIZE MAX_CAO_SIZE MAX_IMPORT_SIZE DISK_SPACE_MB_ALERT \ + SMTP_ENABLE_STARTTLS_AUTO SMTP_OPENSSL_VERIFY_MODE SMTP_TLS GA_ID RECAPTCHA_SITE_KEY RECAPTCHA_SECRET_KEY DISQUS_SHORTNAME TWITTER_NAME \ + FACEBOOK_APP_ID LOG_LEVEL ALLOWED_EXTENSIONS ALLOWED_MIME_TYPES MAX_IMAGE_SIZE MAX_CAO_SIZE MAX_IMPORT_SIZE DISK_SPACE_MB_ALERT \ SUPERADMIN_EMAIL APP_LOCALE RAILS_LOCALE MOMENT_LOCALE SUMMERNOTE_LOCALE ANGULAR_LOCALE MESSAGEFORMAT_LOCALE FULLCALENDAR_LOCALE ELASTICSEARCH_LANGUAGE_ANALYZER TIME_ZONE \ WEEK_STARTING_DAY D3_DATE_FORMAT UIB_DATE_FORMAT EXCEL_DATE_FORMAT OPENLAB_APP_ID OPENLAB_APP_SECRET OPENLAB_DEFAULT) for variable in "${variables[@]}"; do @@ -331,4 +331,3 @@ setup() } setup "$@" -