Commit 2294e59e authored by Benjamin Neff's avatar Benjamin Neff Committed by Jonne Haß
Browse files

change public_url to atom_url and profile_url

parent c6523747
......@@ -32,7 +32,8 @@ module LayoutHelper
def current_user_atom_tag
return unless @person.present?
content_tag(:link, '', :rel => 'alternate', :href => "#{@person.public_url}.atom", :type => "application/atom+xml", :title => t('.public_feed', :name => @person.name))
content_tag(:link, "", rel: "alternate", href: @person.atom_url, type: "application/atom+xml",
title: t(".public_feed", name: @person.name))
end
def translation_missing_warnings
......
......@@ -195,33 +195,34 @@ class Person < ActiveRecord::Base
end
end
def username
@username ||= owner ? owner.username : diaspora_handle.split("@")[0]
end
def owns?(obj)
self.id == obj.author_id
end
def url
begin
uri = URI.parse(self[:url])
url = "#{uri.scheme}://#{uri.host}"
url += ":#{uri.port}" unless ["80", "443"].include?(uri.port.to_s)
url += "/"
rescue => e
url = self[:url]
end
uri = URI.parse(self[:url])
url = "#{uri.scheme}://#{uri.host}"
url += ":#{uri.port}" unless %w(80 443).include?(uri.port.to_s)
url += "/"
url
rescue
self[:url]
end
def receive_url
"#{url}receive/users/#{self.guid}/"
def profile_url
"#{url}u/#{username}"
end
def public_url
if self.owner
username = self.owner.username
else
username = self.diaspora_handle.split("@")[0]
end
"#{url}public/#{username}"
def atom_url
"#{url}public/#{username}.atom"
end
def receive_url
"#{url}receive/users/#{guid}"
end
def public_key_hash
......
......@@ -41,7 +41,7 @@ class User < ActiveRecord::Base
has_one :profile, through: :person
delegate :guid, :public_key, :posts, :photos, :owns?, :image_url,
:diaspora_handle, :name, :public_url, :profile, :url,
:diaspora_handle, :name, :atom_url, :profile_url, :profile, :url,
:first_name, :last_name, :gender, :participations, to: :person
delegate :id, :guid, to: :person, prefix: true
......
......@@ -7,7 +7,7 @@
<Link rel="http://joindiaspora.com/guid" type = 'text/html' href="<%=@person.guid%>"/>
<Link rel='http://webfinger.net/rel/profile-page' type='text/html' <%=person_href(@person, :absolute => true)%>/>
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="<%=@person.public_url%>.atom"/>
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="<%=@person.atom_url%>"/>
<Link rel="salmon" href="<%= @person.receive_url %>"/>
<Link rel="diaspora-public-key" type = 'RSA' href="<%=Base64.strict_encode64(@person.exported_key)%>"/>
......
......@@ -9,7 +9,7 @@
=t('.outside')
%br
%br
= link_to t('.atom_feed'), "#{current_user.public_url}.atom"
= link_to t('.atom_feed'), current_user.atom_url
%br
- if current_user.services
- for service in current_user.services
......
atom_feed({'xmlns:thr' => 'http://purl.org/syndication/thread/1.0',
'xmlns:georss' => 'http://www.georss.org/georss',
'xmlns:activity' => 'http://activitystrea.ms/spec/1.0/',
'xmlns:media' => 'http://purl.org/syndication/atommedia',
'xmlns:poco' => 'http://portablecontacts.net/spec/1.0',
'xmlns:ostatus' => 'http://ostatus.org/schema/1.0',
'xmlns:statusnet' => 'http://status.net/schema/api/1/',
:id => "#{@user.public_url}.atom",
:root_url => "#{@user.public_url}"}) do |feed|
atom_feed("xmlns:thr" => "http://purl.org/syndication/thread/1.0",
"xmlns:georss" => "http://www.georss.org/georss",
"xmlns:activity" => "http://activitystrea.ms/spec/1.0/",
"xmlns:media" => "http://purl.org/syndication/atommedia",
"xmlns:poco" => "http://portablecontacts.net/spec/1.0",
"xmlns:ostatus" => "http://ostatus.org/schema/1.0",
"xmlns:statusnet" => "http://status.net/schema/api/1/",
:id => @user.atom_url,
:root_url => @user.profile_url) do |feed|
feed.tag! :generator, 'Diaspora', :uri => "#{AppConfig.pod_uri.to_s}"
feed.title "#{@user.name}'s Public Feed"
......
......@@ -6,9 +6,8 @@ module Workers
class PublishToHub < Base
sidekiq_options queue: :http_service
def perform(sender_public_url)
atom_url = sender_public_url + '.atom'
Pubsubhubbub.new(AppConfig.environment.pubsub_server.get).publish(atom_url)
def perform(sender_atom_url)
Pubsubhubbub.new(AppConfig.environment.pubsub_server.get).publish(sender_atom_url)
end
end
end
......@@ -4,7 +4,7 @@
module Workers
class PublishToHub < Base
def perform(sender_public_url)
def perform(sender_atom_url)
# don't publish to pubsubhubbub in cucumber
end
end
......
......@@ -143,7 +143,7 @@ class Postzord::Dispatcher
def deliver_to_hub
logger.debug "event=post_to_service type=pubsub sender_handle=#{@sender.diaspora_handle}"
Workers::PublishToHub.perform_async(@sender.public_url)
Workers::PublishToHub.perform_async(@sender.atom_url)
end
# @param url [String]
......
......@@ -278,7 +278,7 @@ describe Postzord::Dispatcher do
it 'queues a job to notify the hub' do
allow(Workers::PostToService).to receive(:perform_async).with(anything, anything, anything)
expect(Workers::PublishToHub).to receive(:perform_async).with(alice.public_url)
expect(Workers::PublishToHub).to receive(:perform_async).with(alice.atom_url)
@zord.send(:deliver_to_services, nil, [])
end
......
......@@ -108,20 +108,55 @@ describe Person, :type => :model do
end
describe "valid url" do
it 'should allow for https urls' do
person = FactoryGirl.build(:person, :url => "https://example.com")
expect(person).to be_valid
context "https urls" do
let(:person) { FactoryGirl.build(:person, url: "https://example.com") }
it "should add trailing slash" do
expect(person.url).to eq("https://example.com/")
end
it "should return the receive url" do
expect(person.receive_url).to eq("https://example.com/receive/users/#{person.guid}")
end
it "should return the atom url" do
expect(person.atom_url).to eq("https://example.com/public/#{person.username}.atom")
end
it "should return the profile url" do
expect(person.profile_url).to eq("https://example.com/u/#{person.username}")
end
end
it 'should always return the correct receive url' do
person = FactoryGirl.build(:person, :url => "https://example.com/a/bit/messed/up")
expect(person.receive_url).to eq("https://example.com/receive/users/#{person.guid}/")
context "messed up urls" do
let(:person) { FactoryGirl.build(:person, url: "https://example.com/a/bit/messed/up") }
it "should return the correct url" do
expect(person.url).to eq("https://example.com/")
end
it "should return the correct receive url" do
expect(person.receive_url).to eq("https://example.com/receive/users/#{person.guid}")
end
it "should return the correct atom url" do
expect(person.atom_url).to eq("https://example.com/public/#{person.username}.atom")
end
it "should return the correct profile url" do
expect(person.profile_url).to eq("https://example.com/u/#{person.username}")
end
end
it 'should allow ports in the url' do
person = FactoryGirl.build(:person, :url => "https://example.com:3000/")
it "should allow ports in the url" do
person = FactoryGirl.build(:person, url: "https://example.com:3000/")
expect(person.url).to eq("https://example.com:3000/")
end
it "should remove https port in the url" do
person = FactoryGirl.build(:person, url: "https://example.com:443/")
expect(person.url).to eq("https://example.com/")
end
end
describe '#diaspora_handle' do
......
......@@ -2,15 +2,15 @@
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
require "spec_helper"
describe Workers::PublishToHub do
describe '.perform' do
it 'calls pubsubhubbub' do
url = "http://publiczone.com/"
m = double()
describe ".perform" do
it "calls pubsubhubbub" do
url = "http://example.com/public/username.atom"
m = double
expect(m).to receive(:publish).with(url+'.atom')
expect(m).to receive(:publish).with(url)
expect(Pubsubhubbub).to receive(:new).with(AppConfig.environment.pubsub_server).and_return(m)
Workers::PublishToHub.new.perform(url)
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment