Clean up internal and add admin tool for cache busting (#3166)

* remove members internal page

* add manual cache busting form

* add missing files
This commit is contained in:
Jess Lee 2019-06-14 19:52:16 -04:00 committed by Ben Halpern
parent 10674aed72
commit c81bc8e66f
5 changed files with 65 additions and 48 deletions

View file

@ -1,24 +0,0 @@
class Internal::MembersController < Internal::ApplicationController
layout "internal"
def index
# with_role and with_any_role return an array and not an ActiveRecord collection
@users = case params[:state]
when "by-scholars"
User.with_role(:workshop_pass).sort_by(&:name)
when "by-members"
User.with_any_role(:level_1_member,
:level_2_member,
:level_3_member,
:level_4_member,
:triple_unicorn_member).sort_by(&:name)
else # members and scholars
User.with_any_role(:level_1_member,
:level_2_member,
:level_3_member,
:level_4_member,
:triple_unicorn_member,
:workshop_pass).sort_by(&:name)
end
end
end

View file

@ -0,0 +1,37 @@
class Internal::ToolsController < Internal::ApplicationController
layout "internal"
def index; end
def bust_cache
handle_dead_path if params[:dead_link]
handle_user_cache if params[:bust_user]
redirect_to "/internal/tools"
end
private
def handle_dead_path
bust_link(params[:dead_link])
end
def handle_user_cache
user = User.find(params[:bust_user].to_i)
user.touch(:profile_updated_at, :last_followed_at, :last_comment_at)
bust_link(user.path)
end
def handle_article_cache
article = User.find(params[:bust_artice].to_i)
article.touch(:last_commented_at)
CacheBuster.new.bust_article(article)
end
def bust_link(link)
cb = CacheBuster.new
cb.bust(link)
cb.bust(link + "/")
cb.bust(link + "?i=i")
cb.bust(link + "/?i=i")
end
end

View file

@ -1,23 +0,0 @@
<h1>Sustaining Member/Scholars</h1>
<a href="/internal/members" style="padding:10px; <%= "background:#89ffba" if params[:state].blank? %>;">Members and Scholars</a> |
<a href="/internal/members?state=by-members" style="padding:10px; <%= " background:#89ffba" if params[:state] == "by-members" %>;">Members Only</a> |
<a href="/internal/members?state=by-scholars" style="padding:10px; <%= " background:#89ffba" if params[:state] == "by-scholars" %>;">Scholars Only</a>
<% @users.each do |user| %>
<div class="row" style="border: 2px solid <%= user.scholar ? "blue" : "orange" %>">
<h2>
<%= user.name %> <a href="/<%= user.username %>" target="_blank">@<%= user.username %></a>
| <a href="/admin/users/<%= user.id %>">Go to admin page</a>
</h2>
<hr />
<% if user.scholar %>
Scholar
| Workshop pass expires: <%= user.workshop_expiration ? user.workshop_expiration.strftime("%b %d, %Y") : "never" %>
<% else %>
Member
| $<%= user.monthly_dues / 100 %>
<% end %>
</div>
<% end %>
<br>

View file

@ -0,0 +1,23 @@
<h1>General Purpose Fastly Purge</h1>
<p>For a page that should 404:</p>
<%= form_tag "/internal/tools/bust_cache" do %>
<%= label_tag("Relative Link:") %>
<%= text_field_tag :dead_link, nil, placeholder: "/devteam/page" %>
<%= submit_tag("Clear Cache") %>
<% end %>
<hr>
<h1>Bust Cache For Specific Content</h1>
<p>This clears the rails cache & the fastly cache.</p>
<%= form_tag "/internal/tools/bust_cache" do %>
<%= label_tag("Article id: ") %>
<%= text_field_tag :bust_article, nil, placeholder: "12345" %>
<%= submit_tag("Clear Cache") %>
<% end %>
<br>
<%= form_tag "/internal/tools/bust_cache" do %>
<%= label_tag("User id: ") %>
<%= text_field_tag :bust_user, nil, placeholder: "12345" %>
<%= submit_tag("Clear Cache") %>
<% end %>

View file

@ -35,7 +35,6 @@ Rails.application.routes.draw do
resources :events, only: %i[index create update]
resources :feedback_messages, only: %i[index show]
resources :listings, only: %i[index edit update destroy], controller: "classified_listings"
resources :members, only: [:index]
resources :pages, only: %i[index new create edit update destroy]
resources :reactions, only: [:update]
resources :reports, only: %i[index show], controller: "feedback_messages" do
@ -55,6 +54,11 @@ Rails.application.routes.draw do
end
end
resources :welcome, only: %i[index create]
resources :tools, only: %i[index create] do
collection do
post "bust_cache"
end
end
end
namespace :api, defaults: { format: "json" } do