Browse Source

Display pending message on admin relays UI (#8494)

* Add missing specs for relay accept/reject

* Display pending message on admin relays UI
pull/4/head
Eugen Rochko 4 years ago
committed by GitHub
parent
commit
5e1767173f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 4 deletions
  1. +7
    -3
      app/views/admin/relays/_relay.html.haml
  2. +1
    -0
      config/locales/en.yml
  3. +1
    -1
      spec/fabricators/relay_fabricator.rb
  4. +26
    -0
      spec/lib/activitypub/activity/accept_spec.rb
  5. +26
    -0
      spec/lib/activitypub/activity/reject_spec.rb

+ 7
- 3
app/views/admin/relays/_relay.html.haml View File

@ -2,20 +2,24 @@
%td
%samp= relay.inbox_url
%td
- if relay.enabled?
- if relay.accepted?
%span.positive-hint
= fa_icon('check')
= ' '
= t 'admin.relays.enabled'
- elsif relay.pending?
= fa_icon('hourglass')
= ' '
= t 'admin.relays.pending'
- else
%span.negative-hint
= fa_icon('times')
= ' '
= t 'admin.relays.disabled'
%td
- if relay.enabled?
- if relay.accepted?
= table_link_to 'power-off', t('admin.relays.disable'), disable_admin_relay_path(relay), method: :post, data: { confirm: t('admin.accounts.are_you_sure') }
- else
- elsif !relay.pending?
= table_link_to 'power-off', t('admin.relays.enable'), enable_admin_relay_path(relay), method: :post, data: { confirm: t('admin.accounts.are_you_sure') }
= table_link_to 'times', t('admin.relays.delete'), admin_relay_path(relay), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') }

+ 1
- 0
config/locales/en.yml View File

@ -303,6 +303,7 @@ en:
description_html: A <strong>federation relay</strong> is an intermediary server that exchanges large volumes of public toots between servers that subscribe and publish to it. <strong>It can help small and medium servers discover content from the fediverse</strong>, which would otherwise require local users manually following other people on remote servers.
enable_hint: Once enabled, your server will subscribe to all public toots from this relay, and will begin sending this server's public toots to it.
inbox_url: Relay URL
pending: Waiting for relay's approval
setup: Setup a relay connection
status: Status
title: Relays

+ 1
- 1
spec/fabricators/relay_fabricator.rb View File

@ -1,4 +1,4 @@
Fabricator(:relay) do
inbox_url "https://example.com/inbox"
enabled true
state :idle
end

+ 26
- 0
spec/lib/activitypub/activity/accept_spec.rb View File

@ -35,4 +35,30 @@ RSpec.describe ActivityPub::Activity::Accept do
expect(recipient.requested?(sender)).to be false
end
end
context 'given a relay' do
let!(:relay) { Fabricate(:relay, state: :pending, follow_activity_id: 'https://abc-123/456') }
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: 'foo',
type: 'Accept',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: {
id: 'https://abc-123/456',
type: 'Follow',
actor: ActivityPub::TagManager.instance.uri_for(recipient),
object: ActivityPub::TagManager.instance.uri_for(sender),
},
}.with_indifferent_access
end
subject { described_class.new(json, sender) }
it 'marks the relay as accepted' do
subject.perform
expect(relay.reload.accepted?).to be true
end
end
end

+ 26
- 0
spec/lib/activitypub/activity/reject_spec.rb View File

@ -35,4 +35,30 @@ RSpec.describe ActivityPub::Activity::Reject do
expect(recipient.requested?(sender)).to be false
end
end
context 'given a relay' do
let!(:relay) { Fabricate(:relay, state: :pending, follow_activity_id: 'https://abc-123/456') }
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
id: 'foo',
type: 'Reject',
actor: ActivityPub::TagManager.instance.uri_for(sender),
object: {
id: 'https://abc-123/456',
type: 'Follow',
actor: ActivityPub::TagManager.instance.uri_for(recipient),
object: ActivityPub::TagManager.instance.uri_for(sender),
},
}.with_indifferent_access
end
subject { described_class.new(json, sender) }
it 'marks the relay as rejected' do
subject.perform
expect(relay.reload.rejected?).to be true
end
end
end

Loading…
Cancel
Save