From 2ce86ecb8b3c104318b1e85049d0d7127eacfcac Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 21 Jun 2016 13:14:27 -0700 Subject: [PATCH] add support for post version queries --- .../stylesheets/specific/posts.css.scss | 4 +++ app/controllers/reports_controller.rb | 15 +++++++++++ app/logical/reports/post_versions_added.rb | 17 ++++++++++++ app/logical/reports/post_versions_removed.rb | 17 ++++++++++++ app/views/post_versions/_listing.html.erb | 2 +- app/views/reports/post_versions.html.erb | 27 +++++++++++++++++++ app/views/static/site_map.html.erb | 1 + config/danbooru_default_config.rb | 3 +++ config/routes.rb | 2 ++ 9 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 app/logical/reports/post_versions_added.rb create mode 100644 app/logical/reports/post_versions_removed.rb create mode 100644 app/views/reports/post_versions.html.erb diff --git a/app/assets/stylesheets/specific/posts.css.scss b/app/assets/stylesheets/specific/posts.css.scss index eddf92f4c..025adb0a3 100644 --- a/app/assets/stylesheets/specific/posts.css.scss +++ b/app/assets/stylesheets/specific/posts.css.scss @@ -478,6 +478,10 @@ div#c-post-versions, div#c-artist-versions { word-wrap: break-word } + tr.hilite { + background: $highlight_color; + } + ins, ins a { color: green; text-decoration: none; diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index b93c13161..0e28bea8e 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -1,6 +1,7 @@ class ReportsController < ApplicationController before_filter :member_only before_filter :gold_only, :only => [:similar_users] + before_filter :janitor_only, :only => [:post_versions, :post_versions_create] def user_promotions @report = Reports::UserPromotions.new @@ -22,4 +23,18 @@ class ReportsController < ApplicationController @report = Reports::UserSimilarity.new(CurrentUser.id) @presenter = UserSimilarityPresenter.new(@report) end + + def post_versions + end + + def post_versions_create + if params[:type] == "added" + @report = Reports::PostVersionsAdded.new(params[:tag]) + else + @report = Reports::PostVersionRemoved.new(params[:tag]) + end + @report.process! + flash[:notice] = "Report is being generated and will be emailed to you shortly" + redirect_to reports_post_versions_path + end end diff --git a/app/logical/reports/post_versions_added.rb b/app/logical/reports/post_versions_added.rb new file mode 100644 index 000000000..617aedca5 --- /dev/null +++ b/app/logical/reports/post_versions_added.rb @@ -0,0 +1,17 @@ +module Reports + class PostVersionsAdded + attr_reader :tag, :email + + def initialize(tag, email) + @tag = tag + @email = email + end + + def process! + if tag + json = {"type" => "post_versions_added", "tag" => tag, "email" => email}.to_json + SqsService.new(Danbooru.config.aws_sqs_post_versions_url).send_message(json) + end + end + end +end diff --git a/app/logical/reports/post_versions_removed.rb b/app/logical/reports/post_versions_removed.rb new file mode 100644 index 000000000..fcf4bd35a --- /dev/null +++ b/app/logical/reports/post_versions_removed.rb @@ -0,0 +1,17 @@ +module Reports + class PostVersionsRemoved + attr_reader :tag, :email + + def initialize(tag, email) + @tag = tag + @email = email + end + + def process! + if tag + json = {"type" => "post_versions_removed", "tag" => tag, "email" => email}.to_json + SqsService.new(Danbooru.config.aws_sqs_post_versions_url).send_message(json) + end + end + end +end diff --git a/app/views/post_versions/_listing.html.erb b/app/views/post_versions/_listing.html.erb index 9de79017f..c015da48d 100644 --- a/app/views/post_versions/_listing.html.erb +++ b/app/views/post_versions/_listing.html.erb @@ -18,7 +18,7 @@ <% post_versions.each do |post_version| %> - + class="hilite"<% end %>> <%= link_to("#{post_version.post_id}.#{post_version.id}", post_path(post_version.post_id)) %> <%= compact_time(post_version.updated_at) %> diff --git a/app/views/reports/post_versions.html.erb b/app/views/reports/post_versions.html.erb new file mode 100644 index 000000000..35922be3d --- /dev/null +++ b/app/views/reports/post_versions.html.erb @@ -0,0 +1,27 @@ +
+
+

Post Changes Report

+ +

You can search all post changes to find when and where a tag was added or removed. Because these queries can take a long time to generate the results will be emailed to you. Only the 1,000 most recent changes will be returned.

+ + <%= form_tag(reports_post_versions_create_path, :method => :post, :class => "simple_form") do %> +
+ + <%= text_field_tag "tag" %> + <%= select_tag "type", options_for_select(%w(added removed)) %> +
+ +
+ + <%= text_field_tag "email", CurrentUser.user.email %> +
+ + <%= submit_tag "Submit" %> + <% end %> + +
+
+ +<% content_for(:page_title) do %> + Post Changes Report - <%= Danbooru.config.app_name %> +<% end %> diff --git a/app/views/static/site_map.html.erb b/app/views/static/site_map.html.erb index ac3875f5a..7e3d527c6 100644 --- a/app/views/static/site_map.html.erb +++ b/app/views/static/site_map.html.erb @@ -64,6 +64,7 @@ <% if Danbooru.config.report_server %>
  • <%= link_to("Top Searches", searches_explore_posts_path) %>
  • <%= link_to("Missed Searches", missed_searches_explore_posts_path) %>
  • +
  • <%= link_to("Post Changes", reports_post_versions_path) %>
  • <% end %> diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index 1860c327b..a0acfab25 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -453,6 +453,9 @@ module Danbooru def aws_sqs_reltagcalc_url end + def aws_sqs_post_versions_url + end + def aws_sqs_region end end diff --git a/config/routes.rb b/config/routes.rb index 34690630f..efa0fea34 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -225,6 +225,8 @@ Rails.application.routes.draw do get "reports/contributors" => "reports#contributors" get "reports/uploads" => "reports#uploads" get "reports/similar_users" => "reports#similar_users" + get "reports/post_versions" => "reports#post_versions" + post "reports/post_versions_create" => "reports#post_versions_create" resources :saved_searches, :except => [:show] do collection do get :categories