Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send out activity json with the right content type #73

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class DiscourseActivityPub::AP::ActivitiesController < DiscourseActivityPub::AP:
before_action :ensure_can_access_activity_object_model

def show
render json: @activity.ap.json
render_activity_json(@activity.ap.json)
end

protected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class DiscourseActivityPub::AP::ActorsController < DiscourseActivityPub::AP::Obj
before_action :ensure_actor_ready

def show
render json: @actor.ap.json
render_activity_json(@actor.ap.json)
end

protected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class DiscourseActivityPub::AP::CollectionsController < DiscourseActivityPub::AP
before_action :ensure_can_access_collection

def show
render json: @collection.ap.json
render_activity_json(@collection.ap.json)
end

protected
Expand Down
17 changes: 11 additions & 6 deletions app/controllers/discourse_activity_pub/ap/objects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DiscourseActivityPub::AP::ObjectsController < ApplicationController
before_action :set_raw_body

def show
render json: @object.ap.json
render_activity_json(@object.ap.json)
end

protected
Expand Down Expand Up @@ -90,6 +90,10 @@ def ensure_object_exists
end
end

def render_activity_json(json)
render json: json, content_type: DiscourseActivityPub::JsonLd::ACTIVITY_CONTENT_TYPE
end

def render_activity_pub_error(key, status, opts = {})
message = I18n.t("discourse_activity_pub.request.error.#{key}", opts)
log_request_error(message, status)
Expand All @@ -101,11 +105,12 @@ def render_ordered_collection(stored, collection_for)
DiscourseActivityPub::AP::Collection::OrderedCollection.new(
stored: stored.send("#{collection_for}_collection"),
)
render json:
DiscourseActivityPub::AP::Collection::OrderedCollectionSerializer.new(
collection,
root: false,
).as_json
render_activity_json(
DiscourseActivityPub::AP::Collection::OrderedCollectionSerializer.new(
collection,
root: false,
).as_json,
)
end

def set_raw_body
Expand Down
4 changes: 4 additions & 0 deletions spec/plugin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,7 @@ def teardown_logging
Rails.logger = @orig_logger
SiteSetting.activity_pub_verbose_logging = false
end

def parsed_body
JSON.parse(response.body)
end
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
it "returns activity json" do
get_object(activity)
expect(response.status).to eq(200)
expect(response.parsed_body).to eq(activity.ap.json)
expect(parsed_body).to eq(activity.ap.json)
end

context "with publishing disabled" do
Expand All @@ -81,7 +81,7 @@
it "returns activity json" do
get_object(activity)
expect(response.status).to eq(200)
expect(response.parsed_body).to eq(activity.ap.json)
expect(parsed_body).to eq(activity.ap.json)
end
end

Expand All @@ -91,7 +91,7 @@
it "returns activity json" do
get_object(activity)
expect(response.status).to eq(200)
expect(response.parsed_body).to eq(activity.ap.json)
expect(parsed_body).to eq(activity.ap.json)
end
end

Expand All @@ -101,7 +101,7 @@
it "returns activity json" do
get_object(activity)
expect(response.status).to eq(200)
expect(response.parsed_body).to eq(activity.ap.json)
expect(parsed_body).to eq(activity.ap.json)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@
it "returns actor json" do
get_object(group)
expect(response.status).to eq(200)
expect(response.parsed_body).to eq(group.ap.json)
expect(parsed_body).to eq(group.ap.json)
end
end

context "with an application actor" do
it "returns actor json" do
get_object(application)
expect(response.status).to eq(200)
expect(response.parsed_body).to eq(application.ap.json)
expect(parsed_body).to eq(application.ap.json)
end
end

Expand All @@ -79,7 +79,7 @@
it "returns actor json" do
get_object(group)
expect(response.status).to eq(200)
expect(response.parsed_body).to eq(group.ap.json)
expect(parsed_body).to eq(group.ap.json)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
it "returns collection json" do
get_object(collection)
expect(response.status).to eq(200)
expect(response.parsed_body).to eq(collection.ap.json)
expect(parsed_body).to eq(collection.ap.json)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
it "returns an ordered collection of the actors followers" do
get_followers(actor)
expect(response.status).to eq(200)
expect(response.parsed_body["totalItems"]).to eq(3)
expect(response.parsed_body["orderedItems"][0]["id"]).to eq(follower3.ap_id)
expect(response.parsed_body["orderedItems"][1]["id"]).to eq(follower1.ap_id)
expect(response.parsed_body["orderedItems"][2]["id"]).to eq(follower2.ap_id)
expect(parsed_body["totalItems"]).to eq(3)
expect(parsed_body["orderedItems"][0]["id"]).to eq(follower3.ap_id)
expect(parsed_body["orderedItems"][1]["id"]).to eq(follower1.ap_id)
expect(parsed_body["orderedItems"][2]["id"]).to eq(follower2.ap_id)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
it "returns a object json" do
get_object(object)
expect(response.status).to eq(200)
expect(response.parsed_body).to eq(object.ap.json)
expect(parsed_body).to eq(object.ap.json)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
it "returns an ordered collection of the actors activities" do
get_from_outbox(actor)
expect(response.status).to eq(200)
expect(response.parsed_body["totalItems"]).to eq(3)
expect(response.parsed_body["orderedItems"][0]["id"]).to eq(activity3.ap_id)
expect(response.parsed_body["orderedItems"][1]["id"]).to eq(activity1.ap_id)
expect(response.parsed_body["orderedItems"][2]["id"]).to eq(activity2.ap_id)
expect(parsed_body["totalItems"]).to eq(3)
expect(parsed_body["orderedItems"][0]["id"]).to eq(activity3.ap_id)
expect(parsed_body["orderedItems"][1]["id"]).to eq(activity1.ap_id)
expect(parsed_body["orderedItems"][2]["id"]).to eq(activity2.ap_id)
end
end
end