]> cat aescling's git repositories - mastodon.git/commitdiff
Add API for retrieving blocked accounts
authorEugen Rochko <eugen@zeonfederated.com>
Thu, 29 Dec 2016 19:12:32 +0000 (20:12 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Thu, 29 Dec 2016 19:12:32 +0000 (20:12 +0100)
15 files changed:
.rubocop.yml
app/controllers/api/v1/blocks_controller.rb [new file with mode: 0644]
app/helpers/api/oembed_helper.rb [deleted file]
app/helpers/api/v1/follow_requests_helper.rb [deleted file]
app/helpers/authorize_follow_helper.rb
app/helpers/stream_entries_helper.rb
app/models/block.rb
app/views/api/v1/blocks/index.rabl [new file with mode: 0644]
app/workers/processing_worker.rb
app/workers/salmon_worker.rb
config/routes.rb
spec/controllers/api/v1/accounts_controller_spec.rb
spec/controllers/api/v1/blocks_controller_spec.rb [new file with mode: 0644]
spec/controllers/api/v1/timelines_controller_spec.rb
spec/helpers/api/oembed_helper_spec.rb [deleted file]

index b973f01cda4499d41dd38a85411a53ffbd732e7e..28c7359130e1ff918bfaf2b4405c1c08e8ee009a 100644 (file)
@@ -86,3 +86,4 @@ AllCops:
   - 'config/**/*'
   - 'bin/*'
   - 'Rakefile'
+  - 'node_modules/**/*'
diff --git a/app/controllers/api/v1/blocks_controller.rb b/app/controllers/api/v1/blocks_controller.rb
new file mode 100644 (file)
index 0000000..8629242
--- /dev/null
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class Api::V1::BlocksController < ApiController
+  before_action -> { doorkeeper_authorize! :follow }
+  before_action :require_user!
+
+  respond_to :json
+
+  def index
+    results   = Block.where(account: current_account).paginate_by_max_id(DEFAULT_ACCOUNTS_LIMIT, params[:max_id], params[:since_id])
+    accounts  = Account.where(id: results.map(&:target_account_id)).map { |a| [a.id, a] }.to_h
+    @accounts = results.map { |f| accounts[f.target_account_id] }
+
+    set_account_counters_maps(@accounts)
+
+    next_path = api_v1_blocks_url(max_id: results.last.id)    if results.size == DEFAULT_ACCOUNTS_LIMIT
+    prev_path = api_v1_blocks_url(since_id: results.first.id) unless results.empty?
+
+    set_pagination_headers(next_path, prev_path)
+  end
+end
diff --git a/app/helpers/api/oembed_helper.rb b/app/helpers/api/oembed_helper.rb
deleted file mode 100644 (file)
index 05d5ca2..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-module Api::OembedHelper
-end
diff --git a/app/helpers/api/v1/follow_requests_helper.rb b/app/helpers/api/v1/follow_requests_helper.rb
deleted file mode 100644 (file)
index b36faf2..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-module Api::V1::FollowRequestsHelper
-end
index 43659ccfa492f19b37fbd7b25d7d13de92d942a8..99ee03c2fefedc85b35ab06c58de02a84145fcbf 100644 (file)
@@ -1,2 +1,4 @@
+# frozen_string_literal: true
+
 module AuthorizeFollowHelper
 end
index 5cd65008e32250413554803411e1de2a698f1d9a..ae2f575b511149edfdccb5475a6c6e45c144ba31 100644 (file)
@@ -10,7 +10,7 @@ module StreamEntriesHelper
   end
 
   def avatar_for_status_url(status)
-    status.reblog? ? status.reblog.account.avatar.url( :original) : status.account.avatar.url( :original)
+    status.reblog? ? status.reblog.account.avatar.url(:original) : status.account.avatar.url(:original)
   end
 
   def entry_classes(status, is_predecessor, is_successor, include_threads)
index ad225d18083edb6ad454b74a42a5e24b386ef560..c2067c5b8ff738d5e441ff068cafc68259b006d9 100644 (file)
@@ -1,6 +1,7 @@
 # frozen_string_literal: true
 
 class Block < ApplicationRecord
+  include Paginable
   include Streamable
 
   belongs_to :account
diff --git a/app/views/api/v1/blocks/index.rabl b/app/views/api/v1/blocks/index.rabl
new file mode 100644 (file)
index 0000000..9f3b13a
--- /dev/null
@@ -0,0 +1,2 @@
+collection @accounts
+extends 'api/v1/accounts/show'
index b31cd0aaf5ef57a0e50df6a8e5993a9f5c43954e..5df404bcc9b7bb3e653bbfb20d22482b9457c398 100644 (file)
@@ -2,7 +2,7 @@
 
 class ProcessingWorker
   include Sidekiq::Worker
-  
+
   sidekiq_options backtrace: true
 
   def perform(account_id, body)
index 0903ca487c5518597b54171f2507147cafb8399c..fc95ce47fff8477336571dfc4bcba205df70810a 100644 (file)
@@ -2,7 +2,7 @@
 
 class SalmonWorker
   include Sidekiq::Worker
-  
+
   sidekiq_options backtrace: true
 
   def perform(account_id, body)
index 1468d426b531d329c0c31c6b61ed8f3fabdd4ca4..7a1d38ad25b3a774bcd6c940dc0e9e8fb2f84560 100644 (file)
@@ -100,6 +100,7 @@ Rails.application.routes.draw do
       resources :follows,  only: [:create]
       resources :media,    only: [:create]
       resources :apps,     only: [:create]
+      resources :blocks,   only: [:index]
 
       resources :follow_requests, only: [:index] do
         member do
index e4532305b666b1f4eed7dac331987d604284ac5c..98b284f7a4ec320da27c5085fd9d732992aed3e7 100644 (file)
@@ -7,7 +7,6 @@ RSpec.describe Api::V1::AccountsController, type: :controller do
   let(:token) { double acceptable?: true, resource_owner_id: user.id }
 
   before do
-    stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {})
     allow(controller).to receive(:doorkeeper_token) { token }
   end
 
diff --git a/spec/controllers/api/v1/blocks_controller_spec.rb b/spec/controllers/api/v1/blocks_controller_spec.rb
new file mode 100644 (file)
index 0000000..ca20a2d
--- /dev/null
@@ -0,0 +1,19 @@
+require 'rails_helper'
+
+RSpec.describe Api::V1::BlocksController, type: :controller do
+  render_views
+
+  let(:user)  { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
+  let(:token) { double acceptable?: true, resource_owner_id: user.id }
+
+  before do
+    allow(controller).to receive(:doorkeeper_token) { token }
+  end
+
+  describe 'GET #index' do
+    it 'returns http success' do
+      get :index
+      expect(response).to have_http_status(:success)
+    end
+  end
+end
index c94519ac5c23a32318c4cb425538e94746604067..5e9954baf30d6f22052a9ebf1bcb23ca613987ee 100644 (file)
@@ -6,7 +6,6 @@ RSpec.describe Api::V1::TimelinesController, type: :controller do
   let(:user)  { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
 
   before do
-    stub_request(:post, "https://pubsubhubbub.superfeedr.com/").to_return(:status => 200, :body => "", :headers => {})
     allow(controller).to receive(:doorkeeper_token) { token }
   end
 
diff --git a/spec/helpers/api/oembed_helper_spec.rb b/spec/helpers/api/oembed_helper_spec.rb
deleted file mode 100644 (file)
index a671e2d..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-require 'rails_helper'
-
-RSpec.describe Api::OembedHelper, type: :helper do
-
-end