From 27fc49d74546d689307e1e712e0b46ccce98867b Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 28 Nov 2016 18:45:13 +0100 Subject: [PATCH] Add simple admin overview of PuSH subscriptions --- app/assets/stylesheets/application.scss | 1 + app/assets/stylesheets/tables.scss | 25 +++++++++++++++++++ .../admin/pubsubhubbub_controller.rb | 11 ++++++++ app/controllers/application_controller.rb | 4 +++ app/helpers/admin/pubsubhubbub_helper.rb | 2 ++ app/views/admin/pubsubhubbub/index.html.haml | 20 +++++++++++++++ config/routes.rb | 4 +++ .../admin/pubsubhubbub_controller_spec.rb | 15 +++++++++++ .../helpers/admin/pubsubhubbub_helper_spec.rb | 15 +++++++++++ 9 files changed, 97 insertions(+) create mode 100644 app/assets/stylesheets/tables.scss create mode 100644 app/controllers/admin/pubsubhubbub_controller.rb create mode 100644 app/helpers/admin/pubsubhubbub_helper.rb create mode 100644 app/views/admin/pubsubhubbub/index.html.haml create mode 100644 spec/controllers/admin/pubsubhubbub_controller_spec.rb create mode 100644 spec/helpers/admin/pubsubhubbub_helper_spec.rb diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 05a3093652..bbbeafefe3 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -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 index 0000000000..89b35891da --- /dev/null +++ b/app/assets/stylesheets/tables.scss @@ -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 index 0000000000..fae05bf9d6 --- /dev/null +++ b/app/controllers/admin/pubsubhubbub_controller.rb @@ -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 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 847763c65a..b03a2cdeae 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 index 0000000000..41c874a62f --- /dev/null +++ b/app/helpers/admin/pubsubhubbub_helper.rb @@ -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 index 0000000000..bb897eb895 --- /dev/null +++ b/app/views/admin/pubsubhubbub/index.html.haml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 5c65682985..cd544a62ba 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 index 0000000000..4e8016b700 --- /dev/null +++ b/spec/controllers/admin/pubsubhubbub_controller_spec.rb @@ -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 index 0000000000..6603e6dc0e --- /dev/null +++ b/spec/helpers/admin/pubsubhubbub_helper_spec.rb @@ -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