]> cat aescling's git repositories - mastodon.git/commitdiff
Add simple admin overview of PuSH subscriptions
authorEugen Rochko <eugen@zeonfederated.com>
Mon, 28 Nov 2016 17:45:13 +0000 (18:45 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Mon, 28 Nov 2016 17:45:13 +0000 (18:45 +0100)
app/assets/stylesheets/application.scss
app/assets/stylesheets/tables.scss [new file with mode: 0644]
app/controllers/admin/pubsubhubbub_controller.rb [new file with mode: 0644]
app/controllers/application_controller.rb
app/helpers/admin/pubsubhubbub_helper.rb [new file with mode: 0644]
app/views/admin/pubsubhubbub/index.html.haml [new file with mode: 0644]
config/routes.rb
spec/controllers/admin/pubsubhubbub_controller_spec.rb [new file with mode: 0644]
spec/helpers/admin/pubsubhubbub_helper_spec.rb [new file with mode: 0644]

index 05a3093652e84f203a3402c5f74cd6d0652d4088..bbbeafefe35c20f5f63d187ea44b8a1395d2af58 100644 (file)
@@ -234,3 +234,4 @@ body {
 @import 'stream_entries';
 @import 'components';
 @import 'about';
+@import 'tables';
diff --git a/app/assets/stylesheets/tables.scss b/app/assets/stylesheets/tables.scss
new file mode 100644 (file)
index 0000000..89b3589
--- /dev/null
@@ -0,0 +1,25 @@
+.table {
+  width: 100%;
+  max-width: 100%;
+  border-spacing: 0;
+  border-collapse: collapse;
+
+  th, td {
+    padding: 8px;
+    line-height: 1.42857143;
+    vertical-align: top;
+    border-top: 1px solid #ddd;
+    text-align: left;
+  }
+
+  & > thead > tr > th {
+    vertical-align: bottom;
+    border-bottom: 2px solid #ddd;
+    border-top: 0;
+    font-weight: 500;
+  }
+}
+
+samp {
+  font-family: 'Roboto Mono', monospace;
+}
diff --git a/app/controllers/admin/pubsubhubbub_controller.rb b/app/controllers/admin/pubsubhubbub_controller.rb
new file mode 100644 (file)
index 0000000..fae05bf
--- /dev/null
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+class Admin::PubsubhubbubController < ApplicationController
+  before_action :require_admin!
+
+  layout 'public'
+
+  def index
+    @subscriptions = Subscription.includes(:account).paginate(page: params[:page], per_page: 40)
+  end
+end
index 847763c65a26a0d160868cce85dda657ba2ec3f6..b03a2cdeaea7f2d6be1921fdab059682b1e8adbc 100644 (file)
@@ -31,6 +31,10 @@ class ApplicationController < ActionController::Base
     I18n.locale = I18n.default_locale
   end
 
+  def require_admin!
+    redirect_to root_path unless current_user&.admin?
+  end
+
   protected
 
   def not_found
diff --git a/app/helpers/admin/pubsubhubbub_helper.rb b/app/helpers/admin/pubsubhubbub_helper.rb
new file mode 100644 (file)
index 0000000..41c874a
--- /dev/null
@@ -0,0 +1,2 @@
+module Admin::PubsubhubbubHelper
+end
diff --git a/app/views/admin/pubsubhubbub/index.html.haml b/app/views/admin/pubsubhubbub/index.html.haml
new file mode 100644 (file)
index 0000000..bb897eb
--- /dev/null
@@ -0,0 +1,20 @@
+%table.table
+  %thead
+    %tr
+      %th Topic
+      %th Callback URL
+      %th Confirmed
+      %th Expires in
+  %tbody
+    - @subscriptions.each do |subscription|
+      %tr
+        %td
+          %samp= subscription.account.acct
+        %td
+          %samp= subscription.callback_url
+        %td
+          - if subscription.confirmed?
+            %i.fa.fa-check
+        %td= distance_of_time_in_words(Time.now, subscription.expires_at)
+
+= will_paginate @subscriptions, pagination_options
index 5c65682985aca90bd05d55412c61adcbb4cfe963..cd544a62bae5dfafd791a5eeac6f0d31a51e21bb 100644 (file)
@@ -44,6 +44,10 @@ Rails.application.routes.draw do
   resources :media, only: [:show]
   resources :tags,  only: [:show]
 
+  namespace :admin do
+    resources :pubsubhubbub, only: [:index]
+  end
+
   namespace :api do
     # PubSubHubbub outgoing subscriptions
     resources :subscriptions, only: [:show]
diff --git a/spec/controllers/admin/pubsubhubbub_controller_spec.rb b/spec/controllers/admin/pubsubhubbub_controller_spec.rb
new file mode 100644 (file)
index 0000000..4e8016b
--- /dev/null
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+require 'rails_helper'
+
+RSpec.describe Admin::PubsubhubbubController, type: :controller do
+  describe 'GET #index' do
+    before do
+      sign_in :user, Fabricate(:user, admin: true)
+    end
+
+    it 'returns http success' do
+      get :index
+      expect(response).to have_http_status(:success)
+    end
+  end
+end
diff --git a/spec/helpers/admin/pubsubhubbub_helper_spec.rb b/spec/helpers/admin/pubsubhubbub_helper_spec.rb
new file mode 100644 (file)
index 0000000..6603e6d
--- /dev/null
@@ -0,0 +1,15 @@
+require 'rails_helper'
+
+# Specs in this file have access to a helper object that includes
+# the Admin::PubsubhubbubHelper. For example:
+#
+# describe Admin::PubsubhubbubHelper do
+#   describe "string concat" do
+#     it "concats two strings with spaces" do
+#       expect(helper.concat_strings("this","that")).to eq("this that")
+#     end
+#   end
+# end
+RSpec.describe Admin::PubsubhubbubHelper, type: :helper do
+  pending "add some examples to (or delete) #{__FILE__}"
+end