Browse Source

Drop remaining OStatus and PuSH code, as well as related database items.

pull/3/head
multiple creatures 2 months ago
parent
commit
0782dc3905

+ 0
- 20
app/controllers/admin/subscriptions_controller.rb View File

@@ -1,20 +0,0 @@
1
-# frozen_string_literal: true
2
-
3
-module Admin
4
-  class SubscriptionsController < BaseController
5
-    def index
6
-      authorize :subscription, :index?
7
-      @subscriptions = ordered_subscriptions.page(requested_page)
8
-    end
9
-
10
-    private
11
-
12
-    def ordered_subscriptions
13
-      Subscription.order(id: :desc).includes(:account)
14
-    end
15
-
16
-    def requested_page
17
-      params[:page].to_i
18
-    end
19
-  end
20
-end

+ 2
- 8
app/models/account.rb View File

@@ -10,8 +10,6 @@
10 10
 #  private_key             :text
11 11
 #  public_key              :text             default(""), not null
12 12
 #  remote_url              :string           default(""), not null
13
-#  salmon_url              :string           default(""), not null
14
-#  hub_url                 :string           default(""), not null
15 13
 #  created_at              :datetime         not null
16 14
 #  updated_at              :datetime         not null
17 15
 #  note                    :text             default(""), not null
@@ -27,7 +25,8 @@
27 25
 #  header_file_size        :integer
28 26
 #  header_updated_at       :datetime
29 27
 #  avatar_remote_url       :string
30
-#  subscription_expires_at :datetime
28
+#  silenced                :boolean          default(FALSE), not null
29
+#  suspended               :boolean          default(FALSE), not null
31 30
 #  locked                  :boolean          default(FALSE), not null
32 31
 #  header_remote_url       :string           default(""), not null
33 32
 #  last_webfingered_at     :datetime
@@ -90,7 +89,6 @@ class Account < ApplicationRecord
90 89
 
91 90
   scope :remote, -> { where.not(domain: nil) }
92 91
   scope :local, -> { where(domain: nil) }
93
-  scope :expiring, ->(time) { remote.where.not(subscription_expires_at: nil).where('subscription_expires_at < ?', time) }
94 92
   scope :partitioned, -> { order(Arel.sql('row_number() over (partition by domain)')) }
95 93
   scope :silenced, -> { where.not(silenced_at: nil) }
96 94
   scope :suspended, -> { where.not(suspended_at: nil) }
@@ -171,10 +169,6 @@ class Account < ApplicationRecord
171 169
     "acct:#{local_username_and_domain}"
172 170
   end
173 171
 
174
-  def subscribed?
175
-    subscription_expires_at.present?
176
-  end
177
-
178 172
   def possibly_stale?
179 173
     last_webfingered_at.nil? || last_webfingered_at <= 1.day.ago
180 174
   end

+ 0
- 3
app/models/concerns/account_associations.rb View File

@@ -32,9 +32,6 @@ module AccountAssociations
32 32
     has_many :media_attachments, dependent: :destroy
33 33
     has_many :polls, dependent: :destroy
34 34
 
35
-    # PuSH subscriptions
36
-    has_many :subscriptions, dependent: :destroy
37
-
38 35
     # Report relationships
39 36
     has_many :reports, dependent: :destroy, inverse_of: :account
40 37
     has_many :targeted_reports, class_name: 'Report', foreign_key: :target_account_id, dependent: :destroy, inverse_of: :target_account

+ 0
- 62
app/models/subscription.rb View File

@@ -1,62 +0,0 @@
1
-# frozen_string_literal: true
2
-# == Schema Information
3
-#
4
-# Table name: subscriptions
5
-#
6
-#  id                          :bigint(8)        not null, primary key
7
-#  callback_url                :string           default(""), not null
8
-#  secret                      :string
9
-#  expires_at                  :datetime
10
-#  confirmed                   :boolean          default(FALSE), not null
11
-#  created_at                  :datetime         not null
12
-#  updated_at                  :datetime         not null
13
-#  last_successful_delivery_at :datetime
14
-#  domain                      :string
15
-#  account_id                  :bigint(8)        not null
16
-#
17
-
18
-class Subscription < ApplicationRecord
19
-  MIN_EXPIRATION = 1.day.to_i
20
-  MAX_EXPIRATION = 30.days.to_i
21
-
22
-  belongs_to :account
23
-
24
-  validates :callback_url, presence: true
25
-  validates :callback_url, uniqueness: { scope: :account_id }
26
-
27
-  scope :confirmed, -> { where(confirmed: true) }
28
-  scope :future_expiration, -> { where(arel_table[:expires_at].gt(Time.now.utc)) }
29
-  scope :expired, -> { where(arel_table[:expires_at].lt(Time.now.utc)) }
30
-  scope :active, -> { confirmed.future_expiration }
31
-
32
-  def lease_seconds=(value)
33
-    self.expires_at = future_expiration(value)
34
-  end
35
-
36
-  def lease_seconds
37
-    (expires_at - Time.now.utc).to_i
38
-  end
39
-
40
-  def expired?
41
-    Time.now.utc > expires_at
42
-  end
43
-
44
-  before_validation :set_min_expiration
45
-
46
-  private
47
-
48
-  def future_expiration(value)
49
-    Time.now.utc + future_offset(value).seconds
50
-  end
51
-
52
-  def future_offset(seconds)
53
-    [
54
-      [MIN_EXPIRATION, seconds.to_i].max,
55
-      MAX_EXPIRATION,
56
-    ].min
57
-  end
58
-
59
-  def set_min_expiration
60
-    self.lease_seconds = 0 unless expires_at
61
-  end
62
-end

+ 0
- 7
app/policies/subscription_policy.rb View File

@@ -1,7 +0,0 @@
1
-# frozen_string_literal: true
2
-
3
-class SubscriptionPolicy < ApplicationPolicy
4
-  def index?
5
-    admin?
6
-  end
7
-end

+ 0
- 1
app/services/suspend_account_service.rb View File

@@ -23,7 +23,6 @@ class SuspendAccountService < BaseService
23 23
     scheduled_statuses
24 24
     status_pins
25 25
     stream_entries
26
-    subscriptions
27 26
   ).freeze
28 27
 
29 28
   ASSOCIATIONS_ON_DESTROY = %w(

+ 0
- 18
app/views/admin/subscriptions/_subscription.html.haml View File

@@ -1,18 +0,0 @@
1
-%tr
2
-  %td
3
-    %samp= subscription.account.acct
4
-  %td
5
-    %samp= subscription.callback_url
6
-  %td
7
-    - if subscription.confirmed?
8
-      %i.fa.fa-check
9
-  %td{ style: "color: #{subscription.expired? ? 'red' : 'inherit'};" }
10
-    %time.time-ago{ datetime: subscription.expires_at.iso8601, title: l(subscription.expires_at) }
11
-      = precede subscription.expired? ? '-' : '' do
12
-        = time_ago_in_words(subscription.expires_at)
13
-  %td
14
-    - if subscription.last_successful_delivery_at?
15
-      %time.formatted{ datetime: subscription.last_successful_delivery_at.iso8601, title: l(subscription.last_successful_delivery_at) }
16
-        = l subscription.last_successful_delivery_at
17
-    - else
18
-      %i.fa.fa-times

+ 0
- 16
app/views/admin/subscriptions/index.html.haml View File

@@ -1,16 +0,0 @@
1
-- content_for :page_title do
2
-  = t('admin.subscriptions.title')
3
-
4
-.table-wrapper
5
-  %table.table
6
-    %thead
7
-      %tr
8
-        %th= t('admin.subscriptions.topic')
9
-        %th= t('admin.subscriptions.callback_url')
10
-        %th= t('admin.subscriptions.confirmed')
11
-        %th= t('admin.subscriptions.expires_in')
12
-        %th= t('admin.subscriptions.last_delivery')
13
-    %tbody
14
-      = render @subscriptions
15
-
16
-= paginate @subscriptions

+ 0
- 11
app/workers/scheduler/subscriptions_cleanup_scheduler.rb View File

@@ -1,11 +0,0 @@
1
-# frozen_string_literal: true
2
-
3
-class Scheduler::SubscriptionsCleanupScheduler
4
-  include Sidekiq::Worker
5
-
6
-  sidekiq_options unique: :until_executed, retry: 0
7
-
8
-  def perform
9
-    Subscription.expired.in_batches.delete_all
10
-  end
11
-end

+ 0
- 1
config/navigation.rb View File

@@ -51,7 +51,6 @@ SimpleNavigation::Configuration.run do |navigation|
51 51
       s.item :dashboard, safe_join([fa_icon('tachometer fw'), t('admin.dashboard.title')]), admin_dashboard_url
52 52
       s.item :settings, safe_join([fa_icon('cogs fw'), t('admin.settings.title')]), edit_admin_settings_url, if: -> { current_user.admin? }, highlights_on: %r{/admin/settings}
53 53
       s.item :relays, safe_join([fa_icon('exchange fw'), t('admin.relays.title')]), admin_relays_url, if: -> { current_user.admin? }, highlights_on: %r{/admin/relays}
54
-      s.item :subscriptions, safe_join([fa_icon('paper-plane-o fw'), t('admin.subscriptions.title')]), admin_subscriptions_url, if: -> { current_user.admin? }
55 54
       s.item :sidekiq, safe_join([fa_icon('diamond fw'), 'Sidekiq']), sidekiq_url, link_html: { target: 'sidekiq' }, if: -> { current_user.admin? }
56 55
       s.item :pghero, safe_join([fa_icon('database fw'), 'PgHero']), pghero_url, link_html: { target: 'pghero' }, if: -> { current_user.admin? }
57 56
     end

+ 9
- 0
db/migrate/20190509163236_drop_ostatus.rb View File

@@ -0,0 +1,9 @@
1
+class DropOStatus < ActiveRecord::Migration[5.2]
2
+  def change
3
+    safety_assured {
4
+      remove_column :accounts, :salmon_url
5
+      remove_column :accounts, :hub_url
6
+      remove_column :accounts, :subscription_expires_at
7
+    }
8
+  end
9
+end

+ 7
- 0
db/migrate/20190509164727_drop_subscriptions.rb View File

@@ -0,0 +1,7 @@
1
+class DropSubscriptions < ActiveRecord::Migration[5.2]
2
+  def change
3
+    safety_assured {
4
+      drop_table :subscriptions
5
+    }
6
+  end
7
+end

+ 2
- 17
db/schema.rb View File

@@ -113,8 +113,6 @@ ActiveRecord::Schema.define(version: 2019_05_19_130537) do
113 113
     t.text "private_key"
114 114
     t.text "public_key", default: "", null: false
115 115
     t.string "remote_url", default: "", null: false
116
-    t.string "salmon_url", default: "", null: false
117
-    t.string "hub_url", default: "", null: false
118 116
     t.datetime "created_at", null: false
119 117
     t.datetime "updated_at", null: false
120 118
     t.text "note", default: "", null: false
@@ -130,7 +128,8 @@ ActiveRecord::Schema.define(version: 2019_05_19_130537) do
130 128
     t.integer "header_file_size"
131 129
     t.datetime "header_updated_at"
132 130
     t.string "avatar_remote_url"
133
-    t.datetime "subscription_expires_at"
131
+    t.boolean "silenced", default: false, null: false
132
+    t.boolean "suspended", default: false, null: false
134 133
     t.boolean "locked", default: false, null: false
135 134
     t.string "header_remote_url", default: "", null: false
136 135
     t.datetime "last_webfingered_at"
@@ -675,19 +674,6 @@ ActiveRecord::Schema.define(version: 2019_05_19_130537) do
675 674
     t.index ["activity_id", "activity_type"], name: "index_stream_entries_on_activity_id_and_activity_type"
676 675
   end
677 676
 
678
-  create_table "subscriptions", force: :cascade do |t|
679
-    t.string "callback_url", default: "", null: false
680
-    t.string "secret"
681
-    t.datetime "expires_at"
682
-    t.boolean "confirmed", default: false, null: false
683
-    t.datetime "created_at", null: false
684
-    t.datetime "updated_at", null: false
685
-    t.datetime "last_successful_delivery_at"
686
-    t.string "domain"
687
-    t.bigint "account_id", null: false
688
-    t.index ["account_id", "callback_url"], name: "index_subscriptions_on_account_id_and_callback_url", unique: true
689
-  end
690
-
691 677
   create_table "tags", force: :cascade do |t|
692 678
     t.string "name", default: "", null: false
693 679
     t.datetime "created_at", null: false
@@ -853,7 +839,6 @@ ActiveRecord::Schema.define(version: 2019_05_19_130537) do
853 839
   add_foreign_key "statuses_tags", "statuses", on_delete: :cascade
854 840
   add_foreign_key "statuses_tags", "tags", name: "fk_3081861e21", on_delete: :cascade
855 841
   add_foreign_key "stream_entries", "accounts", name: "fk_5659b17554", on_delete: :cascade
856
-  add_foreign_key "subscriptions", "accounts", name: "fk_9847d1cbb5", on_delete: :cascade
857 842
   add_foreign_key "tombstones", "accounts", on_delete: :cascade
858 843
   add_foreign_key "user_invite_requests", "users", on_delete: :cascade
859 844
   add_foreign_key "users", "accounts", name: "fk_50500f500d", on_delete: :cascade

+ 0
- 32
spec/controllers/admin/subscriptions_controller_spec.rb View File

@@ -1,32 +0,0 @@
1
-# frozen_string_literal: true
2
-require 'rails_helper'
3
-
4
-RSpec.describe Admin::SubscriptionsController, type: :controller do
5
-  render_views
6
-
7
-  describe 'GET #index' do
8
-    around do |example|
9
-      default_per_page = Subscription.default_per_page
10
-      Subscription.paginates_per 1
11
-      example.run
12
-      Subscription.paginates_per default_per_page
13
-    end
14
-
15
-    before do
16
-      sign_in Fabricate(:user, admin: true), scope: :user
17
-    end
18
-
19
-    it 'renders subscriptions' do
20
-      Fabricate(:subscription)
21
-      specified = Fabricate(:subscription)
22
-
23
-      get :index
24
-
25
-      subscriptions = assigns(:subscriptions)
26
-      expect(subscriptions.count).to eq 1
27
-      expect(subscriptions[0]).to eq specified
28
-
29
-      expect(response).to have_http_status(200)
30
-    end
31
-  end
32
-end

+ 0
- 27
spec/models/account_spec.rb View File

@@ -134,18 +134,6 @@ RSpec.describe Account, type: :model do
134 134
     end
135 135
   end
136 136
 
137
-  describe '#subscribed?' do
138
-    it 'returns false when no subscription expiration information is present' do
139
-      account = Fabricate(:account, subscription_expires_at: nil)
140
-      expect(account.subscribed?).to be false
141
-    end
142
-
143
-    it 'returns true when subscription expiration has been set' do
144
-      account = Fabricate(:account, subscription_expires_at: 30.days.from_now)
145
-      expect(account.subscribed?).to be true
146
-    end
147
-  end
148
-
149 137
   describe '#possibly_stale?' do
150 138
     let(:account) { Fabricate(:account, last_webfingered_at: last_webfingered_at) }
151 139
 
@@ -680,21 +668,6 @@ RSpec.describe Account, type: :model do
680 668
       end
681 669
     end
682 670
 
683
-    describe 'expiring' do
684
-      it 'returns remote accounts with followers whose subscription expiration date is past or not given' do
685
-        local = Fabricate(:account, domain: nil)
686
-        matches = [
687
-          { domain: 'remote', subscription_expires_at: '2000-01-01T00:00:00Z' },
688
-        ].map(&method(:Fabricate).curry(2).call(:account))
689
-        matches.each(&local.method(:follow!))
690
-        Fabricate(:account, domain: 'remote', subscription_expires_at: nil)
691
-        local.follow!(Fabricate(:account, domain: 'remote', subscription_expires_at: '2000-01-03T00:00:00Z'))
692
-        local.follow!(Fabricate(:account, domain: nil, subscription_expires_at: nil))
693
-
694
-        expect(Account.expiring('2000-01-02T00:00:00Z').recent).to eq matches.reverse
695
-      end
696
-    end
697
-
698 671
     describe 'remote' do
699 672
       it 'returns an array of accounts who have a domain' do
700 673
         account_1 = Fabricate(:account, domain: nil)

+ 0
- 67
spec/models/subscription_spec.rb View File

@@ -1,67 +0,0 @@
1
-require 'rails_helper'
2
-
3
-RSpec.describe Subscription, type: :model do
4
-  let(:alice) { Fabricate(:account, username: 'alice') }
5
-
6
-  subject { Fabricate(:subscription, account: alice) }
7
-
8
-  describe '#expired?' do
9
-    it 'return true when expires_at is past' do
10
-      subject.expires_at = 2.days.ago
11
-      expect(subject.expired?).to be true
12
-    end
13
-
14
-    it 'return false when expires_at is future' do
15
-      subject.expires_at = 2.days.from_now
16
-      expect(subject.expired?).to be false
17
-    end
18
-  end
19
-
20
-  describe 'lease_seconds' do
21
-    it 'returns the time remaining until expiration' do
22
-      datetime = 1.day.from_now
23
-      subscription = Subscription.new(expires_at: datetime)
24
-      travel_to(datetime - 12.hours) do
25
-        expect(subscription.lease_seconds).to eq(12.hours)
26
-      end
27
-    end
28
-  end
29
-
30
-  describe 'lease_seconds=' do
31
-    it 'sets expires_at to min expiration when small value is provided' do
32
-      subscription = Subscription.new
33
-      datetime = 1.day.from_now
34
-      too_low = Subscription::MIN_EXPIRATION - 1000
35
-      travel_to(datetime) do
36
-        subscription.lease_seconds = too_low
37
-      end
38
-
39
-      expected = datetime + Subscription::MIN_EXPIRATION.seconds
40
-      expect(subscription.expires_at).to be_within(1.0).of(expected)
41
-    end
42
-
43
-    it 'sets expires_at to value when valid value is provided' do
44
-      subscription = Subscription.new
45
-      datetime = 1.day.from_now
46
-      valid = Subscription::MIN_EXPIRATION + 1000
47
-      travel_to(datetime) do
48
-        subscription.lease_seconds = valid
49
-      end
50
-
51
-      expected = datetime + valid.seconds
52
-      expect(subscription.expires_at).to be_within(1.0).of(expected)
53
-    end
54
-
55
-    it 'sets expires_at to max expiration when large value is provided' do
56
-      subscription = Subscription.new
57
-      datetime = 1.day.from_now
58
-      too_high = Subscription::MAX_EXPIRATION + 1000
59
-      travel_to(datetime) do
60
-        subscription.lease_seconds = too_high
61
-      end
62
-
63
-      expected = datetime + Subscription::MAX_EXPIRATION.seconds
64
-      expect(subscription.expires_at).to be_within(1.0).of(expected)
65
-    end
66
-  end
67
-end

+ 0
- 24
spec/policies/subscription_policy_spec.rb View File

@@ -1,24 +0,0 @@
1
-# frozen_string_literal: true
2
-
3
-require 'rails_helper'
4
-require 'pundit/rspec'
5
-
6
-RSpec.describe SubscriptionPolicy do
7
-  let(:subject) { described_class }
8
-  let(:admin)   { Fabricate(:user, admin: true).account }
9
-  let(:john)    { Fabricate(:user).account }
10
-
11
-  permissions :index? do
12
-    context 'admin?' do
13
-      it 'permits' do
14
-        expect(subject).to permit(admin, Subscription)
15
-      end
16
-    end
17
-
18
-    context '!admin?' do
19
-      it 'denies' do
20
-        expect(subject).to_not permit(john, Subscription)
21
-      end
22
-    end
23
-  end
24
-end

+ 1
- 2
spec/services/remove_status_service_spec.rb View File

@@ -4,7 +4,6 @@ RSpec.describe RemoveStatusService, type: :service do
4 4
   subject { RemoveStatusService.new }
5 5
 
6 6
   let!(:alice)  { Fabricate(:account) }
7
-  let!(:bob)    { Fabricate(:account, username: 'bob', domain: 'example.com', salmon_url: 'http://example.com/salmon') }
8 7
   let!(:jeff)   { Fabricate(:account) }
9 8
   let!(:hank)   { Fabricate(:account, username: 'hank', domain: 'example.com', inbox_url: 'http://example.com/inbox') }
10 9
   let!(:bill)   { Fabricate(:account, username: 'bill', domain: 'example2.com', inbox_url: 'http://example2.com/inbox') }
@@ -16,7 +15,7 @@ RSpec.describe RemoveStatusService, type: :service do
16 15
     jeff.follow!(alice)
17 16
     hank.follow!(alice)
18 17
 
19
-    @status = PostStatusService.new.call(alice, text: 'Hello @bob@example.com')
18
+    @status = PostStatusService.new.call(alice, text: 'Hello!')
20 19
     Fabricate(:status, account: bill, reblog: @status, uri: 'hoge')
21 20
     subject.call(@status)
22 21
   end

+ 2
- 6
spec/services/suspend_account_service_spec.rb View File

@@ -18,7 +18,6 @@ RSpec.describe SuspendAccountService, type: :service do
18 18
     let!(:favourite) { Fabricate(:favourite, account: account) }
19 19
     let!(:active_relationship) { Fabricate(:follow, account: account) }
20 20
     let!(:passive_relationship) { Fabricate(:follow, target_account: account) }
21
-    let!(:subscription) { Fabricate(:subscription, account: account) }
22 21
     let!(:remote_alice) { Fabricate(:account, inbox_url: 'https://alice.com/inbox') }
23 22
     let!(:remote_bob) { Fabricate(:account, inbox_url: 'https://bob.com/inbox') }
24 23
 
@@ -32,9 +31,8 @@ RSpec.describe SuspendAccountService, type: :service do
32 31
           account.favourites,
33 32
           account.active_relationships,
34 33
           account.passive_relationships,
35
-          account.subscriptions
36 34
         ].map(&:count)
37
-      }.from([1, 1, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0, 0])
35
+      }.from([1, 1, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0])
38 36
     end
39 37
 
40 38
     it 'sends a delete actor activity to all known inboxes' do
@@ -63,7 +61,6 @@ RSpec.describe SuspendAccountService, type: :service do
63 61
     let!(:favourite) { Fabricate(:favourite, account: remote_bob) }
64 62
     let!(:active_relationship) { Fabricate(:follow, account: remote_bob, target_account: account) }
65 63
     let!(:passive_relationship) { Fabricate(:follow, target_account: remote_bob) }
66
-    let!(:subscription) { Fabricate(:subscription, account: remote_bob) }
67 64
 
68 65
     it 'deletes associated records' do
69 66
       is_expected.to change {
@@ -75,9 +72,8 @@ RSpec.describe SuspendAccountService, type: :service do
75 72
           remote_bob.favourites,
76 73
           remote_bob.active_relationships,
77 74
           remote_bob.passive_relationships,
78
-          remote_bob.subscriptions
79 75
         ].map(&:count)
80
-      }.from([1, 1, 0, 1, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0, 0])
76
+      }.from([1, 1, 0, 1, 1, 1, 1]).to([0, 0, 0, 0, 0, 0, 0])
81 77
     end
82 78
 
83 79
     it 'sends a reject follow to follwer inboxes' do

Loading…
Cancel
Save