| 
									
										
										
										
											2016-12-29 16:54:54 +01:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class AuthorizeFollowController < ApplicationController | 
					
						
							|  |  |  |   layout 'public' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   before_action :authenticate_user! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def new | 
					
						
							| 
									
										
										
										
											2017-01-02 22:31:10 +01:00
										 |  |  |     uri = Addressable::URI.parse(acct_param) | 
					
						
							| 
									
										
										
										
											2016-12-29 17:23:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if uri.path && %w(http https).include?(uri.scheme) | 
					
						
							|  |  |  |       set_account_from_url | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       set_account_from_acct | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-29 16:54:54 +01:00
										 |  |  |     render :error if @account.nil? | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def create | 
					
						
							| 
									
										
										
										
											2017-01-02 22:31:10 +01:00
										 |  |  |     @account = FollowService.new.call(current_account, acct_param).try(:target_account) | 
					
						
							| 
									
										
										
										
											2016-12-29 16:54:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if @account.nil? | 
					
						
							|  |  |  |       render :error | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       redirect_to web_url("accounts/#{@account.id}") | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-02-26 23:23:06 +01:00
										 |  |  |   rescue ActiveRecord::RecordNotFound, Mastodon::NotPermittedError | 
					
						
							| 
									
										
										
										
											2016-12-29 16:54:54 +01:00
										 |  |  |     render :error | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-12-29 17:23:27 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def set_account_from_url | 
					
						
							| 
									
										
										
										
											2017-01-02 22:31:10 +01:00
										 |  |  |     @account = FetchRemoteAccountService.new.call(acct_param) | 
					
						
							| 
									
										
										
										
											2016-12-29 17:23:27 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def set_account_from_acct | 
					
						
							| 
									
										
										
										
											2017-01-02 22:31:10 +01:00
										 |  |  |     @account = FollowRemoteAccountService.new.call(acct_param) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def acct_param | 
					
						
							|  |  |  |     params[:acct].gsub(/\Aacct:/, '') | 
					
						
							| 
									
										
										
										
											2016-12-29 17:23:27 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-12-29 16:54:54 +01:00
										 |  |  | end |