diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ddbd755c1..4a04fa270 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -84,6 +84,13 @@ class ApplicationController < ActionController::Base elsif exception.is_a?(::ActiveRecord::RecordNotFound) @error_message = "That record was not found" render :template => "static/error", :status => 404 + elsif exception.is_a?(NotImplementedError) + flash[:notice] = "This feature isn't available: #{@exception.message}" + respond_to do |fmt| + fmt.html { redirect_to :back } + fmt.json { render template: "static/error", status: 501 } + fmt.xml { render template: "static/error", status: 501 } + end else render :template => "static/error", :status => 500 end diff --git a/app/controllers/concerns/saved_searches/check_availability.rb b/app/controllers/concerns/saved_searches/check_availability.rb deleted file mode 100644 index 0a1690438..000000000 --- a/app/controllers/concerns/saved_searches/check_availability.rb +++ /dev/null @@ -1,25 +0,0 @@ -module SavedSearches - module CheckAvailability - extend ActiveSupport::Concern - - included do - before_filter :check_availability - end - - def check_availability - if !SavedSearch.enabled? - respond_to do |format| - format.html do - flash[:notice] = "Listbooru service is not configured. Saved searches are not available." - redirect_to :back - end - format.json do - render json: {success: false, reason: "Listbooru service is not configured"}.to_json, status: 501 - end - end - - return false - end - end - end -end diff --git a/app/controllers/iqdb_queries_controller.rb b/app/controllers/iqdb_queries_controller.rb index 3b0a5e334..8f1393ed2 100644 --- a/app/controllers/iqdb_queries_controller.rb +++ b/app/controllers/iqdb_queries_controller.rb @@ -4,8 +4,7 @@ class IqdbQueriesController < ApplicationController def create if !Danbooru.config.iqdbs_server - render :nothing => true - return + raise NotImplementedError.new("the IQDBs service isn't configured. Similarity searches are not available.") end if params[:url] @@ -32,4 +31,4 @@ protected @results = @download.matches render :layout => false, :action => "create_by_post" end -end \ No newline at end of file +end diff --git a/app/controllers/pool_versions_controller.rb b/app/controllers/pool_versions_controller.rb index ca5d44dd4..69966ddb6 100644 --- a/app/controllers/pool_versions_controller.rb +++ b/app/controllers/pool_versions_controller.rb @@ -29,17 +29,7 @@ private def check_availabililty if !PoolArchive.enabled? - respond_to do |format| - format.html do - flash[:notice] = "Archive service is not configured. Pool versions are not saved." - redirect_to :back - end - format.json do - render json: {success: false, reason: "Archive service is not configured"}.to_json, status: 501 - end - end - - return false + raise NotImplementedError.new("Archive service is not configured. Pool versions are not saved.") end end end diff --git a/app/controllers/post_versions_controller.rb b/app/controllers/post_versions_controller.rb index 53af253d2..a7799af52 100644 --- a/app/controllers/post_versions_controller.rb +++ b/app/controllers/post_versions_controller.rb @@ -1,5 +1,6 @@ class PostVersionsController < ApplicationController before_filter :member_only + before_filter :check_availabililty respond_to :html, :xml, :json def index @@ -25,4 +26,12 @@ class PostVersionsController < ApplicationController format.js end end + + private + + def check_availabililty + if !PostArchive.enabled? + raise NotImplementedError.new("Archive service is not configured. Post versions are not saved.") + end + end end diff --git a/app/controllers/saved_searches_controller.rb b/app/controllers/saved_searches_controller.rb index 6e9cfc039..83d02d062 100644 --- a/app/controllers/saved_searches_controller.rb +++ b/app/controllers/saved_searches_controller.rb @@ -1,7 +1,6 @@ class SavedSearchesController < ApplicationController - include SavedSearches::CheckAvailability - before_filter :member_only + before_filter :check_availability respond_to :html, :xml, :json, :js def index @@ -56,4 +55,10 @@ private def saved_searches CurrentUser.user.saved_searches end + + def check_availability + if !SavedSearch.enabled? + raise NotImplementedError.new("Listbooru service is not configured. Saved searches are not available.") + end + end end diff --git a/app/logical/google_big_query/base.rb b/app/logical/google_big_query/base.rb index e15413325..59ea23fd6 100644 --- a/app/logical/google_big_query/base.rb +++ b/app/logical/google_big_query/base.rb @@ -2,6 +2,14 @@ require "big_query" module GoogleBigQuery class Base + def self.enabled? + File.exists?(Danbooru.config.google_api_json_key_path) + end + + def initialize + raise NotImplementedError.new("Google Big Query is not configured.") unless GoogleBigQuery::Base.enabled? + end + def query(q) client.query(q) end diff --git a/app/logical/missed_search_service.rb b/app/logical/missed_search_service.rb index e2f4ae5ba..6f8608787 100644 --- a/app/logical/missed_search_service.rb +++ b/app/logical/missed_search_service.rb @@ -1,5 +1,15 @@ # queries reportbooru to find missed post searches class MissedSearchService + def self.enabled? + Danbooru.config.reportbooru_server.present? + end + + def initialize + if !MissedSearchService.enabled? + raise NotImplementedError.new("the Reportbooru service isn't configured. Missed searches are not available.") + end + end + def each_search(&block) fetch_data.scan(/(.+?) (\d+)\.0\n/).each(&block) end diff --git a/app/logical/popular_search_service.rb b/app/logical/popular_search_service.rb index ac7e0c88c..cb1b84b53 100644 --- a/app/logical/popular_search_service.rb +++ b/app/logical/popular_search_service.rb @@ -2,7 +2,15 @@ class PopularSearchService attr_reader :date, :scale + def self.enabled? + Danbooru.config.reportbooru_server.present? + end + def initialize(date, scale) + if !PopularSearchService.enabled? + raise NotImplementedError.new("the Reportbooru service isn't configured. Popular searches are not available.") + end + @date = date @scale = scale end diff --git a/app/logical/reports/user_similarity.rb b/app/logical/reports/user_similarity.rb index 4560b1070..b2c6bfc45 100644 --- a/app/logical/reports/user_similarity.rb +++ b/app/logical/reports/user_similarity.rb @@ -24,7 +24,7 @@ module Reports end def fetch_similar_user_ids(endpoint = "user_similarity") - return NotImplementedError unless Danbooru.config.reportbooru_server + raise NotImplementedError.new("the Reportbooru service isn't configured. User similarity is not available.") unless Danbooru.config.reportbooru_server params = { "key" => Danbooru.config.reportbooru_key, diff --git a/app/models/pool_archive.rb b/app/models/pool_archive.rb index e050e097d..4bd8ad3ef 100644 --- a/app/models/pool_archive.rb +++ b/app/models/pool_archive.rb @@ -43,7 +43,7 @@ class PoolArchive < ActiveRecord::Base def self.queue(pool) # queue updates to sqs so that if archives goes down for whatever reason it won't # block pool updates - raise "Archive service is not configured" if !enabled? + raise NotImplementedError.new("Archive service is not configured.") if !enabled? json = { pool_id: pool.id, diff --git a/app/models/pool_version.rb b/app/models/pool_version.rb index 753eec2fc..d66eed0ea 100644 --- a/app/models/pool_version.rb +++ b/app/models/pool_version.rb @@ -35,7 +35,7 @@ class PoolVersion < ActiveRecord::Base extend SearchMethods def self.export_to_archives(starting_version_id = 0) - raise "SQS URL not setup" if Danbooru.config.aws_sqs_archives_url.nil? + raise NotImplementedError.new("SQS URL not setup") if Danbooru.config.aws_sqs_archives_url.nil? credentials = Aws::Credentials.new( Danbooru.config.aws_access_key_id, diff --git a/app/models/post_archive.rb b/app/models/post_archive.rb index 8b2d3ccb3..5430a2509 100644 --- a/app/models/post_archive.rb +++ b/app/models/post_archive.rb @@ -60,7 +60,7 @@ class PostArchive < ActiveRecord::Base def queue(post) # queue updates to sqs so that if archives goes down for whatever reason it won't # block post updates - raise "Archive service is not configured" if !enabled? + raise NotImplementedError.new("Archive service is not configured") if !enabled? json = { "post_id" => post.id, diff --git a/app/views/posts/partials/common/_secondary_links.html.erb b/app/views/posts/partials/common/_secondary_links.html.erb index 97ddb9002..3eff9ecc7 100644 --- a/app/views/posts/partials/common/_secondary_links.html.erb +++ b/app/views/posts/partials/common/_secondary_links.html.erb @@ -4,7 +4,7 @@