fedipub 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/app/controllers/concerns/fedipub/rails/server/render_collections.rb +21 -0
- data/app/controllers/fedipub/rails/client/activities_controller.rb +29 -0
- data/app/controllers/fedipub/rails/client/actors_controller.rb +56 -0
- data/app/controllers/fedipub/rails/client/followings_controller.rb +105 -0
- data/app/controllers/fedipub/rails/client_controller.rb +11 -0
- data/app/controllers/fedipub/rails/server/activities_controller.rb +80 -0
- data/app/controllers/fedipub/rails/server/actors_controller.rb +52 -0
- data/app/controllers/fedipub/rails/server/approval_stamps_controller.rb +15 -0
- data/app/controllers/fedipub/rails/server/followings_controller.rb +21 -0
- data/app/controllers/fedipub/rails/server/nodeinfo_controller.rb +30 -0
- data/app/controllers/fedipub/rails/server/published_controller.rb +32 -0
- data/app/controllers/fedipub/rails/server/web_finger_controller.rb +46 -0
- data/app/controllers/fedipub/rails/server_controller.rb +48 -0
- data/app/helpers/fedipub/rails/server_helper.rb +16 -0
- data/app/jobs/fedipub/application_job.rb +1 -1
- data/app/models/concerns/fedipub/actor_entity.rb +1 -125
- data/app/models/concerns/fedipub/data_entity.rb +5 -105
- data/app/models/fedipub/activity.rb +1 -0
- data/app/models/fedipub/actor.rb +28 -22
- data/app/models/fedipub/approval_stamp.rb +38 -0
- data/app/models/fedipub/host.rb +2 -2
- data/app/policies/fedipub/server/approval_stamp_policy.rb +9 -0
- data/app/views/fedipub/rails/client/activities/_index.json.jbuilder +1 -0
- data/app/views/fedipub/rails/client/activities/feed.json.jbuilder +1 -0
- data/app/views/fedipub/rails/client/activities/index.json.jbuilder +1 -0
- data/app/views/fedipub/{client → rails/client}/actors/_actor.json.jbuilder +1 -0
- data/app/views/fedipub/rails/client/actors/index.json.jbuilder +1 -0
- data/app/views/fedipub/{client → rails/client}/actors/show.html.erb +10 -5
- data/app/views/fedipub/rails/client/actors/show.json.jbuilder +1 -0
- data/app/views/fedipub/rails/client/followings/index.json.jbuilder +1 -0
- data/app/views/fedipub/rails/client/followings/show.json.jbuilder +1 -0
- data/app/views/fedipub/{server → rails/server}/activities/_activity.activitypub.jbuilder +2 -2
- data/app/views/fedipub/rails/server/activities/show.activitypub.jbuilder +1 -0
- data/app/views/fedipub/{server → rails/server}/actors/_actor.activitypub.jbuilder +14 -7
- data/app/views/fedipub/{server → rails/server}/actors/_tombstone.activitypub.jbuilder +1 -1
- data/app/views/fedipub/rails/server/actors/show.activitypub.jbuilder +5 -0
- data/app/views/fedipub/rails/server/approval_stamps/show.activitypub.jbuilder +8 -0
- data/app/views/fedipub/{server → rails/server}/followings/_following.activitypub.jbuilder +1 -1
- data/app/views/fedipub/rails/server/followings/show.activitypub.jbuilder +1 -0
- data/app/views/fedipub/rails/server/nodeinfo/index.nodeinfo.jbuilder +10 -0
- data/app/views/fedipub/rails/server/published/_publishable.activitypub.jbuilder +20 -0
- data/app/views/fedipub/{server → rails/server}/published/_tombstone.activitypub.jbuilder +1 -1
- data/app/views/fedipub/rails/server/published/show.activitypub.jbuilder +5 -0
- data/app/views/fedipub/{server → rails/server}/shared/ordered_collection.activitypub.jbuilder +1 -1
- data/app/views/fedipub/{server → rails/server}/shared/ordered_collection_page.activitypub.jbuilder +1 -1
- data/app/views/fedipub/{server → rails/server}/web_finger/find.jrd.jbuilder +11 -3
- data/config/initializers/logger.rb +2 -0
- data/config/initializers/miscellany.rb +21 -0
- data/config/initializers/security_vocab.rb +1 -0
- data/config/routes.rb +8 -7
- data/db/migrate/20260922155524_create_fedipub_approval_stamps.rb +12 -0
- data/db/migrate/20260924090802_add_shared_inbox_url_to_fedipub_actors.rb +5 -0
- data/lib/fedipub/activity_handlers/accept_follow_handler.rb +17 -0
- data/lib/fedipub/activity_handlers/delete_handler.rb +13 -0
- data/lib/fedipub/activity_handlers/follow_handler.rb +13 -0
- data/lib/fedipub/activity_handlers/quote_request_handler.rb +33 -0
- data/lib/fedipub/activity_handlers/undo_delete_handler.rb +15 -0
- data/lib/fedipub/activity_handlers/undo_follow_handler.rb +16 -0
- data/lib/fedipub/concerns/announceable.rb +23 -0
- data/lib/fedipub/concerns/application_actor.rb +30 -0
- data/lib/fedipub/concerns/generic_actor_entity.rb +135 -0
- data/lib/fedipub/concerns/generic_data_entity.rb +112 -0
- data/lib/fedipub/concerns/handles_delete_requests.rb +42 -0
- data/lib/fedipub/concerns/has_interaction_policy.rb +85 -0
- data/lib/fedipub/concerns/likeable.rb +34 -0
- data/lib/fedipub/concerns/quote_request.rb +42 -0
- data/lib/fedipub/data_transformer/note.rb +3 -2
- data/lib/fedipub/errors.rb +10 -0
- data/lib/fedipub/features.rb +13 -0
- data/lib/fedipub/logger.rb +42 -0
- data/lib/fedipub/utils/context.rb +30 -5
- data/lib/fedipub/utils/host.rb +1 -1
- data/lib/fedipub/utils/json_request.rb +63 -17
- data/lib/fedipub/utils/object.rb +1 -1
- data/lib/fedipub/version.rb +1 -1
- data/lib/fedipub.rb +14 -1
- data/lib/fediverse/collection.rb +1 -5
- data/lib/fediverse/inbox.rb +16 -51
- data/lib/fediverse/node_info.rb +2 -5
- data/lib/fediverse/notifier.rb +12 -39
- data/lib/fediverse/signature/draft_cavage12.rb +109 -0
- data/lib/fediverse/signature/rfc9421.rb +69 -0
- data/lib/fediverse/signature.rb +14 -39
- data/lib/fediverse/webfinger.rb +19 -18
- data/lib/generators/fedipub/copy_client_policies/USAGE +1 -1
- data/lib/generators/fedipub/copy_client_policies/copy_client_policies_generator.rb +2 -2
- data/lib/generators/fedipub/copy_client_views/USAGE +1 -1
- data/lib/generators/fedipub/copy_client_views/copy_client_views_generator.rb +2 -2
- data/lib/generators/fedipub/copy_factories/copy_factories_generator.rb +2 -2
- data/lib/generators/fedipub/install/install_generator.rb +3 -3
- metadata +109 -61
- data/app/assets/config/fedipub_manifest.js +0 -1
- data/app/assets/stylesheets/fedipub/application.css +0 -15
- data/app/controllers/concerns/fedipub/server/render_collections.rb +0 -19
- data/app/controllers/fedipub/client/activities_controller.rb +0 -27
- data/app/controllers/fedipub/client/actors_controller.rb +0 -54
- data/app/controllers/fedipub/client/followings_controller.rb +0 -103
- data/app/controllers/fedipub/client_controller.rb +0 -9
- data/app/controllers/fedipub/server/activities_controller.rb +0 -78
- data/app/controllers/fedipub/server/actors_controller.rb +0 -50
- data/app/controllers/fedipub/server/followings_controller.rb +0 -19
- data/app/controllers/fedipub/server/nodeinfo_controller.rb +0 -28
- data/app/controllers/fedipub/server/published_controller.rb +0 -30
- data/app/controllers/fedipub/server/web_finger_controller.rb +0 -45
- data/app/controllers/fedipub/server_controller.rb +0 -37
- data/app/helpers/fedipub/server_helper.rb +0 -18
- data/app/mailers/fedipub/application_mailer.rb +0 -6
- data/app/models/concerns/fedipub/announceable.rb +0 -18
- data/app/models/concerns/fedipub/handles_delete_requests.rb +0 -36
- data/app/models/concerns/fedipub/likeable.rb +0 -29
- data/app/views/fedipub/client/activities/_index.json.jbuilder +0 -1
- data/app/views/fedipub/client/activities/feed.json.jbuilder +0 -1
- data/app/views/fedipub/client/activities/index.json.jbuilder +0 -1
- data/app/views/fedipub/client/actors/index.json.jbuilder +0 -1
- data/app/views/fedipub/client/actors/show.json.jbuilder +0 -1
- data/app/views/fedipub/client/followings/index.json.jbuilder +0 -1
- data/app/views/fedipub/client/followings/show.json.jbuilder +0 -1
- data/app/views/fedipub/server/activities/show.activitypub.jbuilder +0 -1
- data/app/views/fedipub/server/actors/show.activitypub.jbuilder +0 -5
- data/app/views/fedipub/server/followings/show.activitypub.jbuilder +0 -1
- data/app/views/fedipub/server/nodeinfo/index.nodeinfo.jbuilder +0 -6
- data/app/views/fedipub/server/published/_publishable.activitypub.jbuilder +0 -11
- data/app/views/fedipub/server/published/show.activitypub.jbuilder +0 -5
- data/app/views/users/show.html.erb +0 -4
- /data/app/views/fedipub/{client → rails/client}/activities/_activity.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/activities/_activity.json.jbuilder +0 -0
- /data/app/views/fedipub/{client → rails/client}/activities/feed.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/activities/index.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/actors/_lookup_form.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/actors/gone.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/actors/index.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/common/_client_links.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/followings/_follow.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/followings/_follow_actions.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/followings/_follower.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/followings/_following.json.jbuilder +0 -0
- /data/app/views/fedipub/{client → rails/client}/followings/_form.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/followings/index.html.erb +0 -0
- /data/app/views/fedipub/{client → rails/client}/followings/show.html.erb +0 -0
- /data/app/views/fedipub/{server → rails/server}/nodeinfo/show.nodeinfo.jbuilder +0 -0
- /data/app/views/fedipub/{server → rails/server}/web_finger/host_meta.xrd.erb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 30ac03c529c45d0fa0799f86ed75ff67f5879d6b9e63cb10f0edd81cb83e8f0d
|
|
4
|
+
data.tar.gz: 1c65e596d9e53af5893be7400ced66340f872e17df75e7be39f8fd5d605ba6c7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2f92a8c93f5640160d405aa35c8614f186dfc75c74c298c72d8cbd2685e3fc629094af399eed6ae6a424e6b55b3b559a678ca2fdc05c15f7872b1df5554213f1
|
|
7
|
+
data.tar.gz: 105fb399bbe8ebd0169fe173879d02ff8f48ae30107a2227b22eeecede65f8b079c260088ae149e373fee9f1edccfd562417f52060fab87fa67306fc55b11835
|
data/README.md
CHANGED
|
@@ -48,9 +48,14 @@ It _may_ work on other versions, but we won't provide support.
|
|
|
48
48
|
|
|
49
49
|
Extensions add extra features to Fedipub:
|
|
50
50
|
|
|
51
|
-
- [Fedipub Moderation](https://
|
|
51
|
+
- [Fedipub Moderation](https://gitlab.com/fedipub/fedipub-moderation/)
|
|
52
52
|
> A gem that provides trust & safety for Fedipub
|
|
53
53
|
|
|
54
|
+
## Projects using Fedipub
|
|
55
|
+
|
|
56
|
+
- [Manyfold](https://github.com/manyfold3d/manyfold)
|
|
57
|
+
- [Prismo](https://github.com/mbajur/prismo)
|
|
58
|
+
|
|
54
59
|
## License
|
|
55
60
|
|
|
56
61
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -62,6 +67,7 @@ See [CONTRIBUTING](CONTRIBUTING.md) to have an overview of the process and the t
|
|
|
62
67
|
### Contributors
|
|
63
68
|
|
|
64
69
|
- [echarp](https://gitlab.com/echarp)
|
|
70
|
+
- [Francesco Urdih](https://gitlab.com/francesco.urdih)
|
|
65
71
|
- [James Smith](https://gitlab.com/floppy.uk)
|
|
66
72
|
- [Manuel Tancoigne](https://gitlab.com/mtancoigne)
|
|
67
73
|
- [pessi-v](https://github.com/pessi-v)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Fedipub
|
|
2
|
+
module Rails
|
|
3
|
+
module Server
|
|
4
|
+
module RenderCollections
|
|
5
|
+
extend ActiveSupport::Concern
|
|
6
|
+
|
|
7
|
+
def render_collection(actor:, collection:, url_helper:, &items_block)
|
|
8
|
+
if params[:page].present?
|
|
9
|
+
render_collection_page(actor: actor, collection: collection, url_helper: url_helper, items_block: items_block)
|
|
10
|
+
else
|
|
11
|
+
render 'fedipub/rails/server/shared/ordered_collection', locals: { collection: collection, url_helper: url_helper, actor: actor }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def render_collection_page(collection:, actor:, url_helper:, items_block:)
|
|
16
|
+
render 'fedipub/rails/server/shared/ordered_collection_page', locals: { collection: collection, url_helper: url_helper, actor: actor, items_block: items_block }
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Fedipub
|
|
2
|
+
module Rails
|
|
3
|
+
module Client
|
|
4
|
+
class ActivitiesController < Fedipub::Rails::ClientController
|
|
5
|
+
before_action :authenticate_user!, only: [:feed]
|
|
6
|
+
before_action :authorize_action!
|
|
7
|
+
|
|
8
|
+
# GET /app/activities
|
|
9
|
+
# GET /app/activities.json
|
|
10
|
+
def index
|
|
11
|
+
@activities = policy_scope(Fedipub::Activity, policy_scope_class: Fedipub::Client::ActivityPolicy::Scope).all
|
|
12
|
+
@activities = @activities.where actor: Actor.find_param(params[:actor_id]) if params[:actor_id]
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# GET /app/feed
|
|
16
|
+
# GET /app/feed.json
|
|
17
|
+
def feed
|
|
18
|
+
@activities = Activity.feed_for(current_user.fedipub_actor)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def authorize_action!
|
|
24
|
+
authorize(Fedipub::Activity, policy_class: Fedipub::Client::ActivityPolicy)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module Fedipub
|
|
2
|
+
module Rails
|
|
3
|
+
module Client
|
|
4
|
+
class ActorsController < Fedipub::Rails::ClientController
|
|
5
|
+
before_action :set_actor, only: [:show]
|
|
6
|
+
|
|
7
|
+
# GET /app/actors
|
|
8
|
+
# GET /app/actors.json
|
|
9
|
+
def index
|
|
10
|
+
authorize Fedipub::Actor, policy_class: Fedipub::Client::ActorPolicy
|
|
11
|
+
|
|
12
|
+
@actors = policy_scope(Fedipub::Actor, policy_scope_class: Fedipub::Client::ActorPolicy::Scope).all
|
|
13
|
+
@actors = @actors.local if params[:local_only]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# GET /app/actors/1
|
|
17
|
+
# GET /app/actors/1.json
|
|
18
|
+
def show
|
|
19
|
+
render_show
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# GET /app/actors/lookup
|
|
23
|
+
# GET /app/actors/lookup.json
|
|
24
|
+
def lookup
|
|
25
|
+
@actor = Fedipub::Actor.find_by_account account_param
|
|
26
|
+
authorize @actor, policy_class: Fedipub::Client::ActorPolicy
|
|
27
|
+
render_show
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
33
|
+
def set_actor
|
|
34
|
+
@actor = Fedipub::Actor.find_param(params[:id])
|
|
35
|
+
authorize @actor, policy_class: Fedipub::Client::ActorPolicy
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def account_param
|
|
39
|
+
params.require('account').strip
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def render_show
|
|
43
|
+
respond_to do |format|
|
|
44
|
+
if @actor.tombstoned?
|
|
45
|
+
format.html { render :gone, status: :gone }
|
|
46
|
+
format.json { render json: { error: I18n.t('controller.actors.gone') }, status: :gone }
|
|
47
|
+
else
|
|
48
|
+
format.html { render :show }
|
|
49
|
+
format.json { render :show }
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
module Fedipub
|
|
2
|
+
module Rails
|
|
3
|
+
module Client
|
|
4
|
+
class FollowingsController < Fedipub::Rails::ClientController
|
|
5
|
+
before_action :authenticate_user!
|
|
6
|
+
before_action :skip_authorization, only: [:new, :create]
|
|
7
|
+
before_action :set_following, only: [:accept, :destroy]
|
|
8
|
+
|
|
9
|
+
# GET /app/followings/new?uri={uri}
|
|
10
|
+
def new
|
|
11
|
+
# Find actor (and fetch if necessary)
|
|
12
|
+
actor = Actor.find_or_create_by_federation_url(params.require(:uri))
|
|
13
|
+
# Redirect to local profile page which will have a follow button on it
|
|
14
|
+
redirect_to fedipub.client_actor_url(actor)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# PUT /app/followings/:id/accept
|
|
18
|
+
# PUT /app/followings/:id/accept.json
|
|
19
|
+
def accept
|
|
20
|
+
respond_to do |format|
|
|
21
|
+
url = fedipub.client_actor_url @following.actor
|
|
22
|
+
if @following.accept!
|
|
23
|
+
format.html { redirect_to url, notice: I18n.t('controller.followings.accept.success') }
|
|
24
|
+
format.json { render :show, status: :ok, location: @following }
|
|
25
|
+
else
|
|
26
|
+
format.html { redirect_to url, alert: I18n.t('controller.followings.accept.error') }
|
|
27
|
+
format.json { render json: @following.errors, status: Fedipub::Utils::ResponseCodes::UNPROCESSABLE_CONTENT }
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# POST /app/followings
|
|
33
|
+
# POST /app/followings.json
|
|
34
|
+
def create
|
|
35
|
+
@following = Following.new(following_params)
|
|
36
|
+
@following.actor = current_user.fedipub_actor
|
|
37
|
+
authorize @following, policy_class: Fedipub::Client::FollowingPolicy
|
|
38
|
+
|
|
39
|
+
save_and_render
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# POST /app/followings/follow
|
|
43
|
+
# POST /app/followings/follow.json
|
|
44
|
+
def follow
|
|
45
|
+
authorize Fedipub::Following, policy_class: Fedipub::Client::FollowingPolicy
|
|
46
|
+
|
|
47
|
+
begin
|
|
48
|
+
@following = Following.new_from_account following_account_params, actor: current_user.fedipub_actor
|
|
49
|
+
rescue ::ActiveRecord::RecordNotFound
|
|
50
|
+
# Renders a 422 instead of a 404
|
|
51
|
+
respond_to do |format|
|
|
52
|
+
format.html { redirect_to fedipub.client_actors_url, alert: I18n.t('controller.followings.follow.error') }
|
|
53
|
+
format.json { render json: { target_actor: ['does not exist'] }, status: Fedipub::Utils::ResponseCodes::UNPROCESSABLE_CONTENT }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
return
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
save_and_render
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# DELETE /app/followings/1
|
|
63
|
+
# DELETE /app/followings/1.json
|
|
64
|
+
def destroy
|
|
65
|
+
@following.destroy
|
|
66
|
+
respond_to do |format|
|
|
67
|
+
format.html { redirect_to fedipub.client_actor_url(@following.actor), notice: I18n.t('controller.followings.destroy.success') }
|
|
68
|
+
format.json { head :no_content }
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
private
|
|
73
|
+
|
|
74
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
75
|
+
def set_following
|
|
76
|
+
@following = Following.find_param(params[:id])
|
|
77
|
+
authorize @following, policy_class: Fedipub::Client::FollowingPolicy
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Only allow a list of trusted parameters through.
|
|
81
|
+
def following_params
|
|
82
|
+
params.require(:following).permit(:target_actor_id)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def following_account_params
|
|
86
|
+
params.require(:account)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def save_and_render # rubocop:disable Metrics/AbcSize
|
|
90
|
+
url = fedipub.client_actor_url current_user.fedipub_actor
|
|
91
|
+
|
|
92
|
+
respond_to do |format|
|
|
93
|
+
if @following.save
|
|
94
|
+
format.html { redirect_to url, notice: I18n.t('controller.followings.save_and_render.success') }
|
|
95
|
+
format.json { render :show, status: :created, location: @following }
|
|
96
|
+
else
|
|
97
|
+
format.html { redirect_to url, alert: I18n.t('controller.followings.save_and_render.error') }
|
|
98
|
+
format.json { render json: @following.errors, status: Fedipub::Utils::ResponseCodes::UNPROCESSABLE_CONTENT }
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Fedipub
|
|
2
|
+
module Rails
|
|
3
|
+
class ClientController < Fedipub.configuration.base_client_controller.constantize
|
|
4
|
+
include Pundit::Authorization
|
|
5
|
+
|
|
6
|
+
after_action :verify_authorized
|
|
7
|
+
|
|
8
|
+
layout Fedipub.configuration.app_layout if Fedipub.configuration.app_layout
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require 'fediverse/inbox'
|
|
2
|
+
|
|
3
|
+
module Fedipub
|
|
4
|
+
module Rails
|
|
5
|
+
module Server
|
|
6
|
+
class ActivitiesController < Fedipub::Rails::ServerController
|
|
7
|
+
include Fedipub::Rails::Server::RenderCollections
|
|
8
|
+
|
|
9
|
+
before_action :set_activity, only: [:show]
|
|
10
|
+
|
|
11
|
+
# GET /federation/activities
|
|
12
|
+
# GET /federation/actors/1/outbox.json
|
|
13
|
+
def outbox
|
|
14
|
+
authorize Fedipub::Activity, policy_class: Fedipub::Server::ActivityPolicy
|
|
15
|
+
|
|
16
|
+
actor = Actor.find_param(params[:actor_id])
|
|
17
|
+
activities = policy_scope(Fedipub::Activity, policy_scope_class: Fedipub::Server::ActivityPolicy::Scope).where(actor: actor).order(created_at: :desc)
|
|
18
|
+
|
|
19
|
+
render_collection(
|
|
20
|
+
collection: activities.page(params[:page]),
|
|
21
|
+
actor: actor,
|
|
22
|
+
url_helper: :server_actor_outbox_url
|
|
23
|
+
) do |builder, items|
|
|
24
|
+
builder.array! items, partial: 'fedipub/rails/server/activities/activity', as: :activity, context: false
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# GET /federation/actors/1/activities/1.json
|
|
29
|
+
def show; end
|
|
30
|
+
|
|
31
|
+
# POST /federation/actors/1/inbox and POST /federation/inbox
|
|
32
|
+
def create
|
|
33
|
+
skip_authorization
|
|
34
|
+
|
|
35
|
+
payload = payload_from_params
|
|
36
|
+
return head Fedipub::Utils::ResponseCodes::UNPROCESSABLE_CONTENT unless payload
|
|
37
|
+
|
|
38
|
+
if Fediverse::Inbox.dispatch_request(payload, actor_id: params[:actor_id])
|
|
39
|
+
head :created
|
|
40
|
+
else
|
|
41
|
+
head Fedipub::Utils::ResponseCodes::UNPROCESSABLE_CONTENT
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
48
|
+
def set_activity
|
|
49
|
+
@activity = Actor.find_param(params[:actor_id]).activities.find_param(params[:id])
|
|
50
|
+
authorize @activity, policy_class: Fedipub::Server::ActivityPolicy
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Only allow a list of trusted parameters through.
|
|
54
|
+
def activity_params
|
|
55
|
+
params.fetch(:activity, {})
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def payload_from_params
|
|
59
|
+
payload_string = request.body.read
|
|
60
|
+
request.body.rewind if request.body.respond_to? :rewind
|
|
61
|
+
|
|
62
|
+
begin
|
|
63
|
+
payload = JSON.parse(payload_string)
|
|
64
|
+
rescue JSON::ParserError
|
|
65
|
+
return
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
hash = JSON::LD::API.compact payload, payload['@context']
|
|
69
|
+
validate_payload hash
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def validate_payload(hash)
|
|
73
|
+
return unless hash['@context'] && hash['id'] && hash['type'] && hash['actor'] && hash['object']
|
|
74
|
+
|
|
75
|
+
hash
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
module Fedipub
|
|
2
|
+
module Rails
|
|
3
|
+
module Server
|
|
4
|
+
class ActorsController < Fedipub::Rails::ServerController
|
|
5
|
+
include Fedipub::Rails::Server::RenderCollections
|
|
6
|
+
|
|
7
|
+
before_action :set_actor, only: [:show, :followers, :following]
|
|
8
|
+
|
|
9
|
+
# GET /federation/actors/1
|
|
10
|
+
# GET /federation/actors/1.json
|
|
11
|
+
def show
|
|
12
|
+
status = @actor.tombstoned? ? :gone : :ok
|
|
13
|
+
render :show, status: status
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# GET /federation/actors/:id/followers
|
|
17
|
+
# GET /federation/actors/:id/followers.json
|
|
18
|
+
def followers
|
|
19
|
+
@actors = @actor.followers.order(created_at: :desc)
|
|
20
|
+
render_collection(
|
|
21
|
+
collection: @actors.page(params[:page]),
|
|
22
|
+
actor: @actor,
|
|
23
|
+
url_helper: :followers_server_actor_url
|
|
24
|
+
) do |builder, items|
|
|
25
|
+
builder.array! items.map(&:federated_url)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# GET /federation/actors/:id/followers
|
|
30
|
+
# GET /federation/actors/:id/followers.json
|
|
31
|
+
def following
|
|
32
|
+
@actors = @actor.follows.order(created_at: :desc)
|
|
33
|
+
render_collection(
|
|
34
|
+
collection: @actors.page(params[:page]),
|
|
35
|
+
actor: @actor,
|
|
36
|
+
url_helper: :following_server_actor_url
|
|
37
|
+
) do |builder, items|
|
|
38
|
+
builder.array! items.map(&:federated_url)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
45
|
+
def set_actor
|
|
46
|
+
@actor = Actor.find_param(params[:id])
|
|
47
|
+
authorize @actor, policy_class: Fedipub::Server::ActorPolicy
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Fedipub
|
|
2
|
+
module Rails
|
|
3
|
+
module Server
|
|
4
|
+
class ApprovalStampsController < Fedipub::Rails::ServerController
|
|
5
|
+
def show
|
|
6
|
+
@approval_stamp = Fedipub::ApprovalStamp.find_by!(uuid: params['id'])
|
|
7
|
+
authorize @approval_stamp, policy_class: Fedipub::Server::ApprovalStampPolicy
|
|
8
|
+
respond_to do |format|
|
|
9
|
+
format.activitypub
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module Fedipub
|
|
2
|
+
module Rails
|
|
3
|
+
module Server
|
|
4
|
+
class FollowingsController < Fedipub::Rails::ServerController
|
|
5
|
+
before_action :set_following, only: [:show]
|
|
6
|
+
|
|
7
|
+
# GET /federation/actors/1/followings/1.json
|
|
8
|
+
def show; end
|
|
9
|
+
|
|
10
|
+
private
|
|
11
|
+
|
|
12
|
+
# Use callbacks to share common setup or constraints between actions.
|
|
13
|
+
def set_following
|
|
14
|
+
actor = Actor.find_param(params[:actor_id])
|
|
15
|
+
@following = Following.find_by!(actor: actor, uuid: params[:id])
|
|
16
|
+
authorize @following, policy_class: Fedipub::Server::FollowingPolicy
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Fedipub
|
|
2
|
+
module Rails
|
|
3
|
+
module Server
|
|
4
|
+
class NodeinfoController < Fedipub::Rails::ServerController
|
|
5
|
+
def index
|
|
6
|
+
skip_authorization
|
|
7
|
+
|
|
8
|
+
render formats: [:nodeinfo]
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def show # rubocop:todo Metrics/AbcSize
|
|
12
|
+
skip_authorization
|
|
13
|
+
|
|
14
|
+
@total = @active_halfyear = @active_month = 0
|
|
15
|
+
@has_user_counts = false
|
|
16
|
+
Fedipub::Configuration.actor_types.each_value do |config|
|
|
17
|
+
next unless (method = config[:user_count_method]&.to_sym)
|
|
18
|
+
|
|
19
|
+
@has_user_counts = true
|
|
20
|
+
model = config[:class]
|
|
21
|
+
@total += model.send(method, nil)
|
|
22
|
+
@active_month += model.send(method, (30.days.ago)...Time.current)
|
|
23
|
+
@active_halfyear += model.send(method, (180.days.ago)...Time.current)
|
|
24
|
+
end
|
|
25
|
+
render formats: [:nodeinfo]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Fedipub
|
|
2
|
+
module Rails
|
|
3
|
+
module Server
|
|
4
|
+
# Controller to render ActivityPub representation of entities configured with Fedipub::DataEntity
|
|
5
|
+
class PublishedController < Fedipub::Rails::ServerController
|
|
6
|
+
def show
|
|
7
|
+
@publishable = type_scope.find_untombstoned_by!(url_param => params[:id])
|
|
8
|
+
authorize @publishable, policy_class: Fedipub::Server::PublishablePolicy
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def publishable_config
|
|
14
|
+
return @publishable_config if instance_variable_defined? :@publishable_config
|
|
15
|
+
|
|
16
|
+
_, @publishable_config = Fedipub.configuration.data_types.find { |_, v| v[:route_path_segment].to_s == params[:publishable_type] }
|
|
17
|
+
raise ActiveRecord::RecordNotFound, "Invalid #{params[:publishable_type]} type" unless @publishable_config
|
|
18
|
+
|
|
19
|
+
@publishable_config
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def url_param
|
|
23
|
+
publishable_config[:url_param]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def type_scope
|
|
27
|
+
publishable_config[:class].all
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'fediverse/webfinger'
|
|
2
|
+
|
|
3
|
+
module Fedipub
|
|
4
|
+
module Rails
|
|
5
|
+
module Server
|
|
6
|
+
class WebFingerController < Fedipub::Rails::ServerController
|
|
7
|
+
def find
|
|
8
|
+
skip_authorization
|
|
9
|
+
|
|
10
|
+
case resource = params.require(:resource)
|
|
11
|
+
when %r{^https?://#{Fedipub::Utils::Host.localhost}/?$}
|
|
12
|
+
@actor = Fedipub::Actor.application_actor
|
|
13
|
+
when %r{^https?://.+}
|
|
14
|
+
@actor = Fedipub::Actor.find_by_federation_url!(resource) # rubocop:disable Rails/DynamicFindBy
|
|
15
|
+
when /^acct:.+/
|
|
16
|
+
@actor = Fedipub::Actor.find_local_by_username(username)
|
|
17
|
+
raise Fedipub::Errors::TombstonedError if @actor&.tombstoned?
|
|
18
|
+
end
|
|
19
|
+
raise ActiveRecord::RecordNotFound if @actor.nil?
|
|
20
|
+
|
|
21
|
+
render formats: [:jrd]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def host_meta
|
|
25
|
+
skip_authorization
|
|
26
|
+
|
|
27
|
+
render formats: [:xrd]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# TODO: complete missing endpoints
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def username
|
|
35
|
+
return @username if instance_variable_defined? :@username
|
|
36
|
+
|
|
37
|
+
account = Fediverse::Webfinger.split_account params.require(:resource)
|
|
38
|
+
# Fail early if user don't _seems_ local
|
|
39
|
+
raise ActiveRecord::RecordNotFound unless account && Fediverse::Webfinger.local_user?(account)
|
|
40
|
+
|
|
41
|
+
@username = account[:username]
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module Fedipub
|
|
2
|
+
module Rails
|
|
3
|
+
class ServerController < ::ActionController::Base # rubocop:disable Rails/ApplicationController
|
|
4
|
+
include Pundit::Authorization
|
|
5
|
+
|
|
6
|
+
before_action :verify_request_signature!
|
|
7
|
+
after_action :verify_authorized
|
|
8
|
+
|
|
9
|
+
protect_from_forgery with: :null_session
|
|
10
|
+
helper Fedipub::Rails::ServerHelper
|
|
11
|
+
|
|
12
|
+
rescue_from ActiveRecord::RecordNotFound, with: :error_not_found
|
|
13
|
+
rescue_from Fedipub::Errors::TombstonedError, with: :error_gone
|
|
14
|
+
|
|
15
|
+
def self.require_signature?
|
|
16
|
+
false
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def verify_request_signature!
|
|
22
|
+
Fediverse::Signature.verify!(request: request, require_signature: ServerController.require_signature?)
|
|
23
|
+
rescue Fedipub::Errors::BadSignature
|
|
24
|
+
head :unauthorized
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def error_fallback(exception, fallback_message, status)
|
|
28
|
+
message = exception&.message || fallback_message
|
|
29
|
+
respond_to do |format|
|
|
30
|
+
format.jrd { head status }
|
|
31
|
+
format.xrd { head status }
|
|
32
|
+
format.activitypub { head status }
|
|
33
|
+
format.nodeinfo { head status }
|
|
34
|
+
format.json { render json: { error: message }, status: status }
|
|
35
|
+
format.html { raise exception }
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def error_not_found(exception = nil)
|
|
40
|
+
error_fallback(exception, 'Resource not found', :not_found)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def error_gone(exception = nil)
|
|
44
|
+
error_fallback(exception, 'Resource is gone', :gone)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'fedipub/utils/context'
|
|
2
|
+
|
|
3
|
+
module Fedipub
|
|
4
|
+
module Rails
|
|
5
|
+
module ServerHelper
|
|
6
|
+
def remote_follow_url
|
|
7
|
+
method_name = Fedipub.configuration.remote_follow_url_method.to_s
|
|
8
|
+
if method_name.starts_with? 'fedipub.'
|
|
9
|
+
send(method_name.gsub('fedipub.', ''))
|
|
10
|
+
else
|
|
11
|
+
::Rails.application.routes.url_helpers.send(method_name)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|