]> cat aescling's git repositories - mastodon.git/commitdiff
Add ability to use remote follow function on other sites
authorEugen Rochko <eugen@zeonfederated.com>
Thu, 29 Dec 2016 15:54:54 +0000 (16:54 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Thu, 29 Dec 2016 15:54:54 +0000 (16:54 +0100)
18 files changed:
app/assets/stylesheets/accounts.scss
app/assets/stylesheets/application.scss
app/assets/stylesheets/forms.scss
app/controllers/authorize_follow_controller.rb [new file with mode: 0644]
app/helpers/authorize_follow_helper.rb [new file with mode: 0644]
app/views/accounts/_grid_card.html.haml
app/views/authorize_follow/error.html.haml [new file with mode: 0644]
app/views/authorize_follow/new.html.haml [new file with mode: 0644]
app/views/oauth/authorizations/error.html.haml
app/views/oauth/authorizations/new.html.haml
app/views/oauth/authorizations/show.html.haml
app/views/xrd/webfinger.json.rabl
app/views/xrd/webfinger.xml.ruby
config/application.rb
config/locales/en.yml
config/routes.rb
spec/controllers/authorize_follow_controller_spec.rb [new file with mode: 0644]
spec/helpers/authorize_follow_helper_spec.rb [new file with mode: 0644]

index 7f33f178dc17be0b318fceed15a1cb4816f04967..5d0963307a8ca4f548d9f41110523051b2d83fd1 100644 (file)
   padding-bottom: 25px;
   cursor: default;
 }
+
+.account-card {
+  padding: 14px 10px;
+  background: #fff;
+  border-radius: 4px;
+  text-align: left;
+  box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
+
+  .detailed-status__display-name {
+    display: block;
+    overflow: hidden;
+    margin-bottom: 15px;
+
+    & > div {
+      float: left;
+      margin-right: 10px;
+      width: 48px;
+      height: 48px;
+    }
+
+    .avatar {
+      display: block;
+      border-radius: 4px;
+    }
+
+    .display-name {
+      display: block;
+      max-width: 100%;
+      overflow: hidden;
+      white-space: nowrap;
+      text-overflow: ellipsis;
+      cursor: default;
+
+      strong {
+        font-weight: 500;
+        color: #282c37;
+      }
+
+      span {
+        font-size: 14px;
+        color: #9baec8;
+      }
+    }
+
+    &:hover {
+      .display-name {
+        strong {
+          text-decoration: none;
+        }
+      }
+    }
+  }
+
+  .account__header__content {
+    font-size: 14px;
+    color: #282c37;
+  }
+}
index d05ca37951aefce6eea2d7f9716c685b16376992..e4c550b818553ef367b329ebc1f28a50d3f4f7d4 100644 (file)
@@ -214,11 +214,13 @@ body {
 .footer {
   text-align: center;
   margin-top: 30px;
+  font-size: 12px;
+  color: darken(#d9e1e8, 25%);
 
   .domain {
-    font-size: 12px;
-    font-weight: 400;
-    font-family: 'Roboto Mono', monospace;
+    //font-size: 12px;
+    font-weight: 500;
+    //font-family: 'Roboto Mono', monospace;
 
     a {
       color: inherit;
@@ -227,13 +229,12 @@ body {
   }
 
   .powered-by {
-    font-size: 12px;
     font-weight: 400;
-    color: darken(#d9e1e8, 25%);
 
     a {
       color: inherit;
       text-decoration: underline;
+      font-weight: 500;
 
       &:hover {
         text-decoration: none;
index cf9b4fba6c543eb1a08501405ea2ec4de401cafa..e6d2e85a2f2c1916e38c32755b65996167ad16f1 100644 (file)
@@ -185,7 +185,7 @@ code {
   }
 }
 
-.oauth-prompt {
+.oauth-prompt, .follow-prompt {
   margin-bottom: 30px;
   text-align: center;
   color: #9baec8;
diff --git a/app/controllers/authorize_follow_controller.rb b/app/controllers/authorize_follow_controller.rb
new file mode 100644 (file)
index 0000000..a276250
--- /dev/null
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class AuthorizeFollowController < ApplicationController
+  layout 'public'
+
+  before_action :authenticate_user!
+
+  def new
+    @account = FollowRemoteAccountService.new.call(params[:acct])
+    render :error if @account.nil?
+  end
+
+  def create
+    @account = FollowService.new.call(current_account, params[:acct]).try(:target_account)
+
+    if @account.nil?
+      render :error
+    else
+      redirect_to web_url("accounts/#{@account.id}")
+    end
+  rescue ActiveRecord::RecordNotFound, Mastodon::NotPermitted
+    render :error
+  end
+end
diff --git a/app/helpers/authorize_follow_helper.rb b/app/helpers/authorize_follow_helper.rb
new file mode 100644 (file)
index 0000000..43659cc
--- /dev/null
@@ -0,0 +1,2 @@
+module AuthorizeFollowHelper
+end
index dfd7a9f5e47a329bf28340b98869914ca75c3a1d..dfdb231611d05a8824fb32f8ff3d17d2c6d59d8b 100644 (file)
@@ -1,6 +1,6 @@
 .account-grid-card
   .account-grid-card__header
-    .avatar= image_tag account.avatar.url( :original)
+    .avatar= image_tag account.avatar.url(:original)
     .name
       = link_to TagManager.instance.url_for(account) do
         %span.display_name= display_name(account)
diff --git a/app/views/authorize_follow/error.html.haml b/app/views/authorize_follow/error.html.haml
new file mode 100644 (file)
index 0000000..88d33b6
--- /dev/null
@@ -0,0 +1,3 @@
+.form-container
+  .flash-message#error_explanation
+    = t('authorize_follow.error')
diff --git a/app/views/authorize_follow/new.html.haml b/app/views/authorize_follow/new.html.haml
new file mode 100644 (file)
index 0000000..7368b83
--- /dev/null
@@ -0,0 +1,21 @@
+- content_for :page_title do
+  = t('authorize_follow.title', acct: @account.acct)
+
+.form-container
+  .follow-prompt
+    %h2= t('authorize_follow.prompt_html', self: current_account.username)
+
+    .account-card
+      .detailed-status__display-name
+        %div
+          = image_tag @account.avatar.url(:original), alt: '', width: 48, height: 48, class: 'avatar'
+
+        %span.display-name
+          %strong= display_name(@account)
+          %span= "@#{@account.acct}"
+
+      .account__header__content= Formatter.instance.simplified_format(@account)
+
+  = form_tag authorize_follow_path, method: :post, class: 'simple_form' do
+    = hidden_field_tag :acct, @account.acct
+    = button_tag t('authorize_follow.follow'), type: :submit
index ee72d974074a8031449d6b0273430d4cac3b44fa..408ca2b86e00d8ced6cee1b398024f59d865b5c6 100644 (file)
@@ -1,2 +1,3 @@
-.flash-message#error_explanation
-  = @pre_auth.error_response.body[:error_description]
+.form-container
+  .flash-message#error_explanation
+    = @pre_auth.error_response.body[:error_description]
index f058e2cce6527755c96a8482084a5a02e2cb5026..1f951c272dc67c04cfb902afaffbd48d2b7bf8bc 100644 (file)
@@ -1,25 +1,26 @@
 - content_for :page_title do
   = t('doorkeeper.authorizations.new.title')
 
-.oauth-prompt
-  %h2= t('doorkeeper.authorizations.new.prompt', client_name: @pre_auth.client.name)
+.form-container
+  .oauth-prompt
+    %h2= t('doorkeeper.authorizations.new.prompt', client_name: @pre_auth.client.name)
 
-  %p
-    = t('doorkeeper.authorizations.new.able_to')
-    = @pre_auth.scopes.map { |scope| t(scope, scope: [:doorkeeper, :scopes]) }.map { |s| "<strong>#{s}</strong>"}.to_sentence.html_safe
+    %p
+      = t('doorkeeper.authorizations.new.able_to')
+      = @pre_auth.scopes.map { |scope| t(scope, scope: [:doorkeeper, :scopes]) }.map { |s| "<strong>#{s}</strong>"}.to_sentence.html_safe
 
-= form_tag oauth_authorization_path, method: :post, class: 'simple_form' do
-  = hidden_field_tag :client_id, @pre_auth.client.uid
-  = hidden_field_tag :redirect_uri, @pre_auth.redirect_uri
-  = hidden_field_tag :state, @pre_auth.state
-  = hidden_field_tag :response_type, @pre_auth.response_type
-  = hidden_field_tag :scope, @pre_auth.scope
-  = button_tag t('doorkeeper.authorizations.buttons.authorize'), type: :submit
+  = form_tag oauth_authorization_path, method: :post, class: 'simple_form' do
+    = hidden_field_tag :client_id, @pre_auth.client.uid
+    = hidden_field_tag :redirect_uri, @pre_auth.redirect_uri
+    = hidden_field_tag :state, @pre_auth.state
+    = hidden_field_tag :response_type, @pre_auth.response_type
+    = hidden_field_tag :scope, @pre_auth.scope
+    = button_tag t('doorkeeper.authorizations.buttons.authorize'), type: :submit
 
-= form_tag oauth_authorization_path, method: :delete, class: 'simple_form' do
-  = hidden_field_tag :client_id, @pre_auth.client.uid
-  = hidden_field_tag :redirect_uri, @pre_auth.redirect_uri
-  = hidden_field_tag :state, @pre_auth.state
-  = hidden_field_tag :response_type, @pre_auth.response_type
-  = hidden_field_tag :scope, @pre_auth.scope
-  = button_tag t('doorkeeper.authorizations.buttons.deny'), type: :submit, class: 'negative'
+  = form_tag oauth_authorization_path, method: :delete, class: 'simple_form' do
+    = hidden_field_tag :client_id, @pre_auth.client.uid
+    = hidden_field_tag :redirect_uri, @pre_auth.redirect_uri
+    = hidden_field_tag :state, @pre_auth.state
+    = hidden_field_tag :response_type, @pre_auth.response_type
+    = hidden_field_tag :scope, @pre_auth.scope
+    = button_tag t('doorkeeper.authorizations.buttons.deny'), type: :submit, class: 'negative'
index 897a15cee5389afc6b2716774bb74c6e00b4eaaa..b56667f352eea9de937085cc8e0e4a84d49b8565 100644 (file)
@@ -1,2 +1,3 @@
-.flash-message
-  %code= params[:code]
+.form-container
+  .flash-message
+    %code= params[:code]
index 0de17ac195e2a2784e353eef0a47013036e04581..e637ed9d329b2245f6237ae322f12b407adef00d 100644 (file)
@@ -11,6 +11,7 @@ node(:links) do
     { rel: 'http://webfinger.net/rel/profile-page', type: 'text/html', href: TagManager.instance.url_for(@account) },
     { rel: 'http://schemas.google.com/g/2010#updates-from', type: 'application/atom+xml', href: account_url(@account, format: 'atom') },
     { rel: 'salmon', href: api_salmon_url(@account.id) },
-    { rel: 'magic-public-key', href: "data:application/magic-public-key,#{@magic_key}" }
+    { rel: 'magic-public-key', href: "data:application/magic-public-key,#{@magic_key}" },
+    { rel: 'http://ostatus.org/schema/1.0/subscribe', template: "#{authorize_follow_url}?acct={uri}" },
   ]
 end
index ee5b5fc9d392549b5aa60d7beee78d8878771750..80ac71d2708741b47c58b5fce70501ee676a2d1c 100644 (file)
@@ -6,5 +6,6 @@ Nokogiri::XML::Builder.new do |xml|
     xml.Link(rel: 'http://schemas.google.com/g/2010#updates-from', type: 'application/atom+xml', href: account_url(@account, format: 'atom'))
     xml.Link(rel: 'salmon', href: api_salmon_url(@account.id))
     xml.Link(rel: 'magic-public-key', href: "data:application/magic-public-key,#{@magic_key}")
+    xml.Link(rel: 'http://ostatus.org/schema/1.0/subscribe', template: "#{authorize_follow_url}?acct={uri}")
   end
 end.to_xml
index 091f9c535060cd75b4d7486b3ffa95e785a1461f..79ace8521cb724fd73ef479961aa91f69f66dae2 100644 (file)
@@ -45,7 +45,7 @@ module Mastodon
     config.browserify_rails.commandline_options = '--transform [ babelify --presets [ es2015 react ] ] --extension=".jsx"'
 
     config.to_prepare do
-      Doorkeeper::AuthorizationsController.layout 'auth'
+      Doorkeeper::AuthorizationsController.layout 'public'
     end
 
     config.action_dispatch.default_headers = {
index 760078862089848e405eec5647d3fc4b4248f7ed..f57c7202627d17856b9527b6fe037d949b6f8a3b 100644 (file)
@@ -26,6 +26,11 @@ en:
     resend_confirmation: Resend confirmation instructions
     reset_password: Reset password
     set_new_password: Set new password
+  authorize_follow:
+    error: Unfortunately, there was an error looking up the remote account
+    follow: Follow
+    prompt_html: 'You (<strong>%{self}</strong>) have requested to follow:'
+    title: Follow %{acct}
   datetime:
     distance_in_words:
       about_x_hours: "%{count}h"
index 985d6583dec302bdbd26b4388f93f53123fb569e..1468d426b531d329c0c31c6b61ed8f3fabdd4ca4 100644 (file)
@@ -48,6 +48,10 @@ Rails.application.routes.draw do
   resources :media, only: [:show]
   resources :tags,  only: [:show]
 
+  # Remote follow
+  get  :authorize_follow, to: 'authorize_follow#new'
+  post :authorize_follow, to: 'authorize_follow#create'
+
   namespace :admin do
     resources :pubsubhubbub, only: [:index]
     resources :domain_blocks, only: [:index, :create]
diff --git a/spec/controllers/authorize_follow_controller_spec.rb b/spec/controllers/authorize_follow_controller_spec.rb
new file mode 100644 (file)
index 0000000..954efd5
--- /dev/null
@@ -0,0 +1,6 @@
+require 'rails_helper'
+
+RSpec.describe AuthorizeFollowController, type: :controller do
+  describe 'GET #new'
+  describe 'POST #create'
+end
diff --git a/spec/helpers/authorize_follow_helper_spec.rb b/spec/helpers/authorize_follow_helper_spec.rb
new file mode 100644 (file)
index 0000000..ba5b0a7
--- /dev/null
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe AuthorizeFollowHelper, type: :helper do
+
+end