fedipub-frontend 0.12.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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +95 -0
  4. data/Rakefile +8 -0
  5. data/app/controllers/fedipub/frontend/activities_controller.rb +27 -0
  6. data/app/controllers/fedipub/frontend/actors_controller.rb +54 -0
  7. data/app/controllers/fedipub/frontend/base_controller.rb +11 -0
  8. data/app/controllers/fedipub/frontend/followings_controller.rb +106 -0
  9. data/app/policies/fedipub/frontend/activity_policy.rb +9 -0
  10. data/app/policies/fedipub/frontend/actor_policy.rb +15 -0
  11. data/app/policies/fedipub/frontend/following_policy.rb +35 -0
  12. data/app/views/fedipub/frontend/activities/_activity.html.erb +5 -0
  13. data/app/views/fedipub/frontend/activities/_activity.json.jbuilder +1 -0
  14. data/app/views/fedipub/frontend/activities/_index.json.jbuilder +1 -0
  15. data/app/views/fedipub/frontend/activities/feed.html.erb +11 -0
  16. data/app/views/fedipub/frontend/activities/feed.json.jbuilder +1 -0
  17. data/app/views/fedipub/frontend/activities/index.html.erb +5 -0
  18. data/app/views/fedipub/frontend/activities/index.json.jbuilder +1 -0
  19. data/app/views/fedipub/frontend/actors/_actor.json.jbuilder +18 -0
  20. data/app/views/fedipub/frontend/actors/_lookup_form.html.erb +5 -0
  21. data/app/views/fedipub/frontend/actors/gone.html.erb +1 -0
  22. data/app/views/fedipub/frontend/actors/index.html.erb +44 -0
  23. data/app/views/fedipub/frontend/actors/index.json.jbuilder +1 -0
  24. data/app/views/fedipub/frontend/actors/show.html.erb +117 -0
  25. data/app/views/fedipub/frontend/actors/show.json.jbuilder +1 -0
  26. data/app/views/fedipub/frontend/common/_client_links.html.erb +26 -0
  27. data/app/views/fedipub/frontend/followings/_follow.html.erb +4 -0
  28. data/app/views/fedipub/frontend/followings/_follow_actions.html.erb +36 -0
  29. data/app/views/fedipub/frontend/followings/_follower.html.erb +7 -0
  30. data/app/views/fedipub/frontend/followings/_following.json.jbuilder +1 -0
  31. data/app/views/fedipub/frontend/followings/_form.html.erb +22 -0
  32. data/app/views/fedipub/frontend/followings/index.html.erb +29 -0
  33. data/app/views/fedipub/frontend/followings/index.json.jbuilder +1 -0
  34. data/app/views/fedipub/frontend/followings/show.html.erb +21 -0
  35. data/app/views/fedipub/frontend/followings/show.json.jbuilder +1 -0
  36. data/config/routes.rb +23 -0
  37. data/lib/fedipub/frontend/configuration.rb +36 -0
  38. data/lib/fedipub/frontend/engine.rb +9 -0
  39. data/lib/fedipub/frontend/railtie.rb +6 -0
  40. data/lib/fedipub/frontend/version.rb +5 -0
  41. data/lib/fedipub/frontend.rb +5 -0
  42. data/lib/generators/fedipub/frontend/copy_policies/USAGE +8 -0
  43. data/lib/generators/fedipub/frontend/copy_policies/copy_policies_generator.rb +11 -0
  44. data/lib/generators/fedipub/frontend/copy_views/USAGE +8 -0
  45. data/lib/generators/fedipub/frontend/copy_views/copy_views_generator.rb +11 -0
  46. metadata +117 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: be2de388ada4d606ad35d5cc56f2680275acfa507565f8a469dc60e6cc5efba4
4
+ data.tar.gz: 1b015c46ea5b49b4aba6e708d3b4fd3fd59a6092461e4a798a30c107efee0c1f
5
+ SHA512:
6
+ metadata.gz: eb426bea3e4c22275d805ae58b1749d363051376773f452a90dce1f6a9f8fa7d1c5daa9c57d0278a5835a8b0b6311b098d8c5ea6b6d06d54a0b56969769fdf6b
7
+ data.tar.gz: 7d81adb9849103404d99dd92adb8a8f5e10683ea7281b8cefec701be85fc07e5b85cd0e8dd7e68fac669399021efbf11e2be2feb0a9bfede0aa3c2c3ebe8523d
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Experiments Labs / Experimentations
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # Fedipub Frontend
2
+
3
+ Fedipub is an engine that brings ActivityPub to Ruby on Rails application. This frontend gem provides
4
+ controllers, views and Pundit policies which you can use to get started quickly with an out-of-the-box
5
+ user interface if you're not ready to build your own.
6
+
7
+ > [!note]
8
+ > This code was previously part of the `federails` gem, named "client", and was enabled by default.
9
+
10
+ ## Community
11
+
12
+ You can join the [matrix chat room](https://matrix.to/#/#fedipub:matrix.org) to chat with humans.
13
+
14
+ Open issues or feature requests on the [issue tracker](https://gitlab.com/fedipub/fedipub-frontend/-/issues)
15
+
16
+ ## Usage
17
+
18
+ ### Mount the engine
19
+
20
+ This gem provides basic views to display and interact with Fedipub data. Mount it in `routes.rb` as an engine alongside Fedipub, at whatever path you want:
21
+
22
+ ```
23
+ mount Fedipub::Engine => '/'
24
+ mount Fedipub::Frontend::Engine => '/app'
25
+ ```
26
+
27
+ > [!note]
28
+ > Mounting this engine directly replaces the use of `client_routes_path` in the previous fedipub client code.
29
+
30
+ ### Configuration
31
+
32
+ There are two configuration options to help integrate the views into your application.
33
+
34
+ * `frontend_layout`: set a layout file from your application to be used by the controllers and views
35
+ * `frontend_base_controller`: the base controller class which frontend controller should inherit from, e.g. `::ApplicationController`
36
+
37
+ Both options are set using the standard `fedipub.yml` file or `Fedipub.configure` method:
38
+
39
+ ```yaml
40
+ frontend_layout: "layouts/my_app_layout"
41
+ frontend_base_controller: "::ApplicationController"
42
+ ```
43
+
44
+ ```ruby
45
+ Fedipub.configure do |config|
46
+ config.frontend_layout = "layouts/my_app_layout"
47
+ config.frontend_base_controller = ::ApplicationController
48
+ end
49
+ ```
50
+
51
+ ### Customising views
52
+
53
+ You can customise the default views, by copying them into your application:
54
+
55
+ ```sh
56
+ rails generate fedipub:frontend:copy_views
57
+ ```
58
+
59
+ ### Customising policies
60
+
61
+ You can also customise the default access policies, again by copying them into your application:
62
+
63
+ ```sh
64
+ rails generate fedipub:frontend:copy_policies
65
+ ```
66
+
67
+ ## Common questions
68
+
69
+ - **I set the base controller or a custom layout, and the links break**
70
+
71
+ Use `main_app.<url_helper>` for links to your application; `fedipub_frontend.<fedipub_url_helper>` for links to the Fedipub frontend.
72
+ - **I specified a custom layout and my helpers are not available**
73
+
74
+ You will have better results if you specify a `base_controller` from your application, as Fedipub frontend's base controller is isolated from the main app and does not have access to its helpers.
75
+
76
+ ## License
77
+
78
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
79
+
80
+ ## Contributing
81
+
82
+ See [CONTRIBUTING](CONTRIBUTING.md) to have an overview of the process and the tools we use.
83
+
84
+ ### Contributors
85
+
86
+ - [echarp](https://gitlab.com/echarp)
87
+ - [Francesco Urdih](https://gitlab.com/francesco.urdih)
88
+ - [James Smith](https://gitlab.com/floppy.uk)
89
+ - [Manuel Tancoigne](https://gitlab.com/mtancoigne)
90
+ - [pessi-v](https://github.com/pessi-v)
91
+
92
+ ### Supporters
93
+
94
+ - Gitlab runners are graciously provided by [Coopaname](https://coopaname.coop), a French cooperative.
95
+ - This project was funded through the [NGI0 Commons Fund](https://nlnet.nl/commonsfund), a fund established by [NLnet](https://nlnet.nl/) with financial support from the European Commission's [Next Generation Internet](https://ngi.eu/) program. Learn more at the NLnet [project page](https://nlnet.nl/project/Fedipub/).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+
3
+ APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
4
+ load 'rails/tasks/engine.rake'
5
+
6
+ load 'rails/tasks/statistics.rake'
7
+
8
+ require 'bundler/gem_tasks'
@@ -0,0 +1,27 @@
1
+ module Fedipub
2
+ module Frontend
3
+ class ActivitiesController < Fedipub::Frontend::BaseController
4
+ before_action :authenticate_user!, only: [:feed]
5
+ before_action :authorize_action!
6
+
7
+ # GET /app/activities
8
+ # GET /app/activities.json
9
+ def index
10
+ @activities = policy_scope(Fedipub::Activity, policy_scope_class: Fedipub::Frontend::ActivityPolicy::Scope).all
11
+ @activities = @activities.where actor: Actor.find_param(params[:actor_id]) if params[:actor_id]
12
+ end
13
+
14
+ # GET /app/feed
15
+ # GET /app/feed.json
16
+ def feed
17
+ @activities = Activity.feed_for(current_user.fedipub_actor)
18
+ end
19
+
20
+ private
21
+
22
+ def authorize_action!
23
+ authorize(Fedipub::Activity, policy_class: Fedipub::Frontend::ActivityPolicy)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,54 @@
1
+ module Fedipub
2
+ module Frontend
3
+ class ActorsController < Fedipub::Frontend::BaseController
4
+ before_action :set_actor, only: [:show]
5
+
6
+ # GET /app/actors
7
+ # GET /app/actors.json
8
+ def index
9
+ authorize Fedipub::Actor, policy_class: Fedipub::Frontend::ActorPolicy
10
+
11
+ @actors = policy_scope(Fedipub::Actor, policy_scope_class: Fedipub::Frontend::ActorPolicy::Scope).all
12
+ @actors = @actors.local if params[:local_only]
13
+ end
14
+
15
+ # GET /app/actors/1
16
+ # GET /app/actors/1.json
17
+ def show
18
+ render_show
19
+ end
20
+
21
+ # GET /app/actors/lookup
22
+ # GET /app/actors/lookup.json
23
+ def lookup
24
+ @actor = Fedipub::Actor.find_by_account account_param
25
+ authorize @actor, policy_class: Fedipub::Frontend::ActorPolicy
26
+ render_show
27
+ end
28
+
29
+ private
30
+
31
+ # Use callbacks to share common setup or constraints between actions.
32
+ def set_actor
33
+ @actor = Fedipub::Actor.find_param(params[:id])
34
+ authorize @actor, policy_class: Fedipub::Frontend::ActorPolicy
35
+ end
36
+
37
+ def account_param
38
+ params.require('account').strip
39
+ end
40
+
41
+ def render_show
42
+ respond_to do |format|
43
+ if @actor.tombstoned?
44
+ format.html { render :gone, status: :gone }
45
+ format.json { render json: { error: I18n.t('controller.actors.gone') }, status: :gone }
46
+ else
47
+ format.html { render :show }
48
+ format.json { render :show }
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,11 @@
1
+ module Fedipub
2
+ module Frontend
3
+ class BaseController < Fedipub.configuration.frontend_base_controller.constantize
4
+ include Pundit::Authorization
5
+
6
+ after_action :verify_authorized
7
+
8
+ layout Fedipub.configuration.frontend_layout if Fedipub.configuration.frontend_layout
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,106 @@
1
+ module Fedipub
2
+ module Frontend
3
+ class FollowingsController < Fedipub::Frontend::BaseController
4
+ before_action :authenticate_user!
5
+ before_action :skip_authorization, only: [:new, :create]
6
+ before_action :set_following, only: [:accept, :destroy]
7
+
8
+ # GET /app/followings/new?uri={uri}
9
+ def new
10
+ # Find actor (and fetch if necessary)
11
+ actor = Actor.find_or_create_by_federation_url(params.require(:uri))
12
+ # Redirect to local profile page which will have a follow button on it
13
+ redirect_to fedipub_frontend.actor_url(actor)
14
+ end
15
+
16
+ # PUT /app/followings/:id/accept
17
+ # PUT /app/followings/:id/accept.json
18
+ def accept
19
+ respond_to do |format|
20
+ url = fedipub_frontend.actor_url @following.actor
21
+ if @following.accept!
22
+ format.html { redirect_to url, notice: I18n.t('controller.followings.accept.success') }
23
+ format.json { render :show, status: :ok, location: @following }
24
+ else
25
+ format.html { redirect_to url, alert: I18n.t('controller.followings.accept.error') }
26
+ format.json { render json: @following.errors, status: Fedipub::Utils::ResponseCodes::UNPROCESSABLE_CONTENT }
27
+ end
28
+ end
29
+ end
30
+
31
+ # POST /app/followings
32
+ # POST /app/followings.json
33
+ def create
34
+ @following = Following.new(following_params)
35
+ @following.actor = current_user.fedipub_actor
36
+ authorize @following, policy_class: Fedipub::Frontend::FollowingPolicy
37
+
38
+ save_and_render
39
+ end
40
+
41
+ # POST /app/followings/follow
42
+ # POST /app/followings/follow.json
43
+ def follow
44
+ authorize Fedipub::Following, policy_class: Fedipub::Frontend::FollowingPolicy
45
+
46
+ begin
47
+ @following = Following.new_from_account following_account_params, actor: current_user.fedipub_actor
48
+ rescue ::ActiveRecord::RecordNotFound
49
+ # Renders a 422 instead of a 404
50
+ respond_to do |format|
51
+ format.html { redirect_to fedipub_frontend.actors_url, alert: I18n.t('controller.followings.follow.error') }
52
+ format.json { render json: { target_actor: ['does not exist'] }, status: Fedipub::Utils::ResponseCodes::UNPROCESSABLE_CONTENT }
53
+ end
54
+
55
+ return
56
+ end
57
+
58
+ save_and_render
59
+ end
60
+
61
+ # DELETE /app/followings/1
62
+ # DELETE /app/followings/1.json
63
+ def destroy
64
+ @following.destroy
65
+ respond_to do |format|
66
+ format.html do
67
+ redirect_to fedipub_frontend.actor_url(@following.actor),
68
+ notice: I18n.t('controller.followings.destroy.success')
69
+ end
70
+ format.json { head :no_content }
71
+ end
72
+ end
73
+
74
+ private
75
+
76
+ # Use callbacks to share common setup or constraints between actions.
77
+ def set_following
78
+ @following = Following.find_param(params[:id])
79
+ authorize @following, policy_class: Fedipub::Frontend::FollowingPolicy
80
+ end
81
+
82
+ # Only allow a list of trusted parameters through.
83
+ def following_params
84
+ params.require(:following).permit(:target_actor_id)
85
+ end
86
+
87
+ def following_account_params
88
+ params.require(:account)
89
+ end
90
+
91
+ def save_and_render # rubocop:disable Metrics/AbcSize
92
+ url = fedipub_frontend.actor_url current_user.fedipub_actor
93
+
94
+ respond_to do |format|
95
+ if @following.save
96
+ format.html { redirect_to url, notice: I18n.t('controller.followings.save_and_render.success') }
97
+ format.json { render :show, status: :created, location: @following }
98
+ else
99
+ format.html { redirect_to url, alert: I18n.t('controller.followings.save_and_render.error') }
100
+ format.json { render json: @following.errors, status: Fedipub::Utils::ResponseCodes::UNPROCESSABLE_CONTENT }
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,9 @@
1
+ module Fedipub
2
+ module Frontend
3
+ class ActivityPolicy < Fedipub::FedipubPolicy
4
+ def feed?
5
+ user_with_actor?
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module Fedipub
2
+ module Frontend
3
+ class ActorPolicy < Fedipub::FedipubPolicy
4
+ def lookup?
5
+ true
6
+ end
7
+
8
+ class Scope < Scope
9
+ def resolve
10
+ scope
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,35 @@
1
+ module Fedipub
2
+ module Frontend
3
+ class FollowingPolicy < Fedipub::FedipubPolicy
4
+ def show?
5
+ in_following?
6
+ end
7
+
8
+ def destroy?
9
+ in_following?
10
+ end
11
+
12
+ def accept?
13
+ in_following? && @record.target_actor_id == @user.fedipub_actor.id
14
+ end
15
+
16
+ def follow?
17
+ create?
18
+ end
19
+
20
+ class Scope < Scope
21
+ def resolve
22
+ scope.with_actor(@user.fedipub_actor)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def in_following?
29
+ return false unless user_with_actor?
30
+
31
+ @record.actor_id == @user.fedipub_actor&.id || @record.target_actor_id == @user.fedipub_actor&.id
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ <div>
2
+ <b><%= link_to activity.actor.name, fedipub_frontend.actor_url(activity.actor) %></b>
3
+ <code><%= activity.action %></code>
4
+ <!-- < %= link_to activity.entity_type, activity.entity %>-->
5
+ </div>
@@ -0,0 +1 @@
1
+ json.extract! activity, :id, :entity_id, :entity_type, :action, :actor_id, :created_at
@@ -0,0 +1 @@
1
+ json.array! @activities, partial: 'fedipub/frontend/activities/activity', as: :activity
@@ -0,0 +1,11 @@
1
+ <h1>Your feed</h1>
2
+ <p>
3
+ This is the list of activities from actors you follow.
4
+ </p>
5
+
6
+ <% if @activities.size.zero? %>
7
+ <p>There is nothing to display. Start following things!</p>
8
+ <% end %>
9
+ <% @activities.each do |activity| %>
10
+ <%= render 'activity', activity: activity %>
11
+ <% end %>
@@ -0,0 +1 @@
1
+ json.partial! 'fedipub/frontend/activities/index'
@@ -0,0 +1,5 @@
1
+ <h1>Listing activities</h1>
2
+
3
+ <% @activities.each do |activity| %>
4
+ <%= render 'activity', activity: activity %>
5
+ <% end %>
@@ -0,0 +1 @@
1
+ json.partial! 'fedipub/frontend/activities/index'
@@ -0,0 +1,18 @@
1
+ json.extract! actor,
2
+ :id,
3
+ :name,
4
+ :federated_url,
5
+ :username,
6
+ :inbox_url,
7
+ :shared_inbox_url,
8
+ :outbox_url,
9
+ :followers_url,
10
+ :followings_url,
11
+ :profile_url,
12
+ :at_address,
13
+ :local,
14
+ :entity_id,
15
+ :entity_type,
16
+ :tombstoned_at,
17
+ :created_at,
18
+ :updated_at
@@ -0,0 +1,5 @@
1
+ <%= form_tag fedipub_frontend.lookup_actors_url, method: :get do %>
2
+ <%= label_tag :account %>
3
+ <%= text_field_tag :account, nil, placeholder: 'user@domain.tld or username', required: true %>
4
+ <%= submit_tag 'Search' %>
5
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= t('.gone') %>
@@ -0,0 +1,44 @@
1
+ <h1>Listing actors</h1>
2
+
3
+ <section>
4
+ Filters:
5
+ <% if params[:local_only] %>
6
+ <%= link_to 'All actors', fedipub_frontend.actors_url %>
7
+ <% else %>
8
+ <%= link_to 'Only local actors', fedipub_frontend.actors_url(local_only: true) %>
9
+ <% end %>
10
+ </section>
11
+
12
+ <table>
13
+ <thead>
14
+ <tr>
15
+ <th>Name</th>
16
+ <th>Username</th>
17
+ <th>Federation address</th>
18
+ <th>Local?</th>
19
+ <th></th>
20
+ </tr>
21
+ </thead>
22
+ <tbody>
23
+ <% if @actors.size.zero? %>
24
+ <tr>
25
+ <td colspan="5">There are no actors to display</td>
26
+ </tr>
27
+ <% end %>
28
+ <% @actors.each do |actor| %>
29
+ <tr>
30
+ <td>
31
+ <% if actor.tombstoned? %>
32
+ <del><%= actor.name %></del>
33
+ <% else %>
34
+ <%= actor.name %>
35
+ <% end %>
36
+ </td>
37
+ <td><%= actor.username %></td>
38
+ <td><%= actor.at_address %></td>
39
+ <td><%= actor.local? %></td>
40
+ <td><%= link_to 'Show', fedipub_frontend.actor_url(actor) %></td>
41
+ </tr>
42
+ <% end %>
43
+ </tbody>
44
+ </table>
@@ -0,0 +1 @@
1
+ json.array! @actors, partial: 'fedipub/frontend/actors/actor', as: :actor
@@ -0,0 +1,117 @@
1
+ <h1><%= @actor.name %></h1>
2
+
3
+ <section>
4
+ <%= render 'fedipub/frontend/followings/follow_actions', user: current_user, actor: @actor %>
5
+ </section>
6
+
7
+ <section>
8
+ <% if @actor.local? %>
9
+ <%= link_to 'All activities', fedipub_frontend.actor_activities_path(@actor) %>
10
+ <% elsif @actor.profile_url %>
11
+ <%= link_to 'Visit profile', @actor.profile_url %>
12
+ <% end %>
13
+ </section>
14
+
15
+ <section>
16
+ <h2>Actor details</h2>
17
+
18
+ <p>
19
+ <b>Federated url:</b>
20
+ <%= @actor.federated_url %>
21
+ </p>
22
+
23
+ <p>
24
+ <b>Username:</b>
25
+ <%= @actor.username %>
26
+ </p>
27
+
28
+ <p>
29
+ <b>Inbox URL:</b>
30
+ <%= @actor.inbox_url %>
31
+ </p>
32
+
33
+ <p>
34
+ <b>Outbox URL:</b>
35
+ <%= @actor.outbox_url %>
36
+ </p>
37
+
38
+ <p>
39
+ <b>Shared Inbox URL:</b>
40
+ <%= @actor.shared_inbox_url %>
41
+ </p>
42
+
43
+ <p>
44
+ <b>Followers URL:</b>
45
+ <%= @actor.followers_url %>
46
+ </p>
47
+
48
+ <p>
49
+ <b>Followings URL:</b>
50
+ <%= @actor.followings_url %>
51
+ </p>
52
+
53
+ <p>
54
+ <b>Profile url:</b>
55
+ <% if @actor.profile_url %>
56
+ <%= link_to 'Profile', @actor.profile_url %>
57
+ <% end %>
58
+ </p>
59
+
60
+ <p>
61
+ <b>Federation address:</b>
62
+ <%= @actor.at_address %>
63
+ </p>
64
+
65
+ <p>
66
+ <% if @actor.local? && @actor.entity_configuration[:profile_url_method] %>
67
+ <b>Home page:</b>
68
+ <%= link_to @actor.entity.send(@actor.entity_configuration[:username_field]),
69
+ ::Rails.application.routes.url_helpers.send(@actor.entity_configuration[:profile_url_method], @actor.entity)
70
+ %>
71
+ <% elsif @actor.profile_url %>
72
+ <b>Federation profile URL (JSON):</b>
73
+ <%= link_to @actor.name, @actor.profile_url %>
74
+ <% else %>
75
+ (No homepage)
76
+ <% end %>
77
+ </p>
78
+ </section>
79
+
80
+ <hr>
81
+
82
+ <section>
83
+ <h2>Follows <small>(<em>Who is followed?</em>)</small></h2>
84
+
85
+ <% if @actor.following_follows.size.zero? %>
86
+ <p><%= @actor.username %> follows nothing</p>
87
+ <% end %>
88
+
89
+ <% @actor.following_follows.each do |following| %>
90
+ <%= render 'fedipub/frontend/followings/follow', following: following %>
91
+ <% end %>
92
+ </section>
93
+
94
+ <section>
95
+ <h2>Followers <small>(<em>Who follows?</em>)</small></h2>
96
+
97
+ <% if @actor.following_followers.size.zero? %>
98
+ <p>Nothing follows <%= @actor.username %></p>
99
+ <% end %>
100
+
101
+ <% @actor.following_followers.each do |following| %>
102
+ <%= render 'fedipub/frontend/followings/follower', following: following %>
103
+ <% end %>
104
+ </section>
105
+
106
+ <section>
107
+ <%# FIXME: Fetch distant content somehow %>
108
+ <h2>10 last activities</h2>
109
+
110
+ <% activities = @actor.activities.last(10) %>
111
+ <% if activities.size.zero? %>
112
+ <p>No activity to display</p>
113
+ <% end %>
114
+ <% activities.each do |activity| %>
115
+ <%= render 'fedipub/frontend/activities/activity', activity: activity %>
116
+ <% end %>
117
+ </section>
@@ -0,0 +1 @@
1
+ json.partial! 'fedipub/frontend/actors/actor', actor: @actor
@@ -0,0 +1,26 @@
1
+ Federation:
2
+
3
+ <ul>
4
+ <%# Available publicly %>
5
+ <li><%= link_to 'Actors', fedipub_frontend.actors_url %></li>
6
+ <li><%= link_to 'Activities', fedipub_frontend.activities_url %></li>
7
+
8
+ <%# Available when user has an associated actor %>
9
+ <% if Fedipub::Frontend::ActivityPolicy.new(user, nil).feed? %>
10
+ <li><%= link_to 'Feed', fedipub_frontend.feed_url %></li>
11
+ <%end %>
12
+
13
+ <%# Available when user has an associated actor. The actor must exist to create the link %>
14
+ <% if Fedipub.actor_entity?(user) && user.fedipub_actor.present? %>
15
+ <li><%= link_to "You (#{user.fedipub_actor.username})", fedipub_frontend.actor_path(user.fedipub_actor) %></li>
16
+ <% end %>
17
+ </ul>
18
+
19
+ <%# Debug information%>
20
+ <% if !user %>
21
+ Register or login to view your actor's information
22
+ <% elsif !Fedipub::actor_entity?(user) %>
23
+ <p><%= user.class.name %> is not configured to have an associated actor; you won't be allowed to follow or be followed</p>
24
+ <% elsif !user.fedipub_actor.present? %>
25
+ <p>Your account does not have an associated actor; you won't be allowed to follow or be followed</p>
26
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <div>
2
+ <b><%= link_to following.target_actor.name, fedipub_frontend.actor_url(following.target_actor) %></b>
3
+ (<%= following.target_actor.at_address %>) (<%= following.status %>)
4
+ </div>
@@ -0,0 +1,36 @@
1
+ <%#
2
+ Displays buttons to follow/revoke following on a given actor.
3
+ Requires variables:
4
+ - user (usually user)
5
+ - actor (target actor)
6
+ %>
7
+ <p>
8
+ <% if Fedipub::Frontend::FollowingPolicy.new(user, Fedipub::Following).create? %>
9
+ <% follow = user.fedipub_actor.follows? actor %>
10
+ <% if actor.entity == user %>
11
+ <button type="button" role="button" disabled="disabled">That's you</button>
12
+ <% elsif follow %>
13
+ You are already following (<%= follow.status %>)
14
+ <%= button_to 'Cancel', fedipub_frontend.following_path(follow), method: :delete %>
15
+ <% else %>
16
+ <%= button_to "Follow #{actor.username}", fedipub_frontend.follow_followings_path, params: { account: actor.at_address }, method: :post %>
17
+ <% end %>
18
+
19
+ <% followed = actor.follows? user.fedipub_actor %>
20
+ <% if followed %>
21
+ <% if followed.pending? %>
22
+ <%= actor.username %> wants to follow you.
23
+ <%= button_to 'Accept request', fedipub_frontend.accept_following_path(followed), method: :put %>
24
+ <% else %>
25
+ <%= actor.username %> follows you.
26
+ <%= button_to 'Revoke', fedipub_frontend.following_path(followed), method: :delete %>
27
+ <% end %>
28
+ <% end %>
29
+ <% elsif !user %>
30
+ Register or login to be able to follow this actor. Alternatively, search for this address on Fediverse server where
31
+ you already have an account:
32
+ <input type="text" readonly="readonly" value="<%= actor.at_address(prefix: '') %>">
33
+ <% else %>
34
+ <%= user.class.name %> is not configured to follow/be followed, or has no associated actor.
35
+ <% end %>
36
+ </p>
@@ -0,0 +1,7 @@
1
+ <div>
2
+ <b><%= link_to following.actor.name, fedipub_frontend.actor_url(following.actor) %></b>
3
+ (<%= following.actor.at_address %>) (<%= following.status %>)
4
+ <% if following.pending? && following.target_actor == current_user&.fedipub_actor %>
5
+ <%= button_to 'Accept', fedipub_frontend.accept_following_path(following), method: :put %>
6
+ <% end %>
7
+ </div>
@@ -0,0 +1 @@
1
+ json.extract! following, :id, :actor_id, :target_actor_id, :status, :created_at, :updated_at
@@ -0,0 +1,22 @@
1
+ <%= form_for following, url: fedipub_frontend.following_url do |f| %>
2
+ <h1>DELETE ME</h1>
3
+ <% if following.errors.any? %>
4
+ <div class="error_explanation">
5
+ <h2><%= pluralize(following.errors.count, 'error') %> prohibited this following from being saved:</h2>
6
+ <ul>
7
+ <% following.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :target_actor %>
16
+ <%= f.collection_select :target_actor_id, Fedipub::Actor.all, :id, :name %>
17
+ </div>
18
+
19
+ <div class="actions">
20
+ <%= f.submit 'Save' %>
21
+ </div>
22
+ <% end %>
@@ -0,0 +1,29 @@
1
+ <h1>Listing followings</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Actor</th>
7
+ <th>Target actor</th>
8
+ <th>Status</th>
9
+ <th></th>
10
+ <th></th>
11
+ <th></th>
12
+ </tr>
13
+ </thead>
14
+
15
+ <tbody>
16
+ <% @followings.each do |following| %>
17
+ <tr>
18
+ <td><%= following.actor %></td>
19
+ <td><%= following.target_actor %></td>
20
+ <td><%= following.status %></td>
21
+ <td><%= link_to 'Show', following %></td>
22
+ <td><%= link_to 'Edit', edit_following_path(following) %></td>
23
+ <td><%= link_to 'Destroy', following, method: :delete, data: { confirm: 'Are you sure?' } %></td>
24
+ </tr>
25
+ <% end %>
26
+ </tbody>
27
+ </table>
28
+
29
+ <%= link_to 'New Following', new_following_path %>
@@ -0,0 +1 @@
1
+ json.array! @followings, partial: 'fedipub/frontend/followings/following', as: :following
@@ -0,0 +1,21 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <b>Actor:</b>
5
+ <%= @following.actor %>
6
+ </p>
7
+
8
+ <p>
9
+ <b>Target actor:</b>
10
+ <%= @following.target_actor %>
11
+ </p>
12
+
13
+ <p>
14
+ <b>Status:</b>
15
+ <%= @following.status %>
16
+ </p>
17
+
18
+
19
+ <%= link_to 'Edit', edit_following_path(@following) %>
20
+ \|
21
+ <%= link_to 'Back', followings_path %>
@@ -0,0 +1 @@
1
+ json.partial! 'fedipub/frontend/followings/following', following: @following
data/config/routes.rb ADDED
@@ -0,0 +1,23 @@
1
+ Fedipub::Frontend::Engine.routes.draw do
2
+ resources :activities, only: [:index] do
3
+ collection do
4
+ get :feed, to: 'activities#feed'
5
+ end
6
+ end
7
+ resources :actors, only: [:index, :show] do
8
+ collection do
9
+ get :lookup, to: 'actors#lookup'
10
+ end
11
+ resources :activities, only: [:index]
12
+ end
13
+ get :feed, to: 'activities#feed'
14
+ resources :followings, only: [:new, :create, :destroy] do
15
+ collection do
16
+ post :follow, to: 'followings#follow'
17
+ end
18
+
19
+ member do
20
+ put :accept, to: 'followings#accept'
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,36 @@
1
+ module Fedipub
2
+ module Frontend
3
+ # rubocop:disable Style/ClassVars
4
+
5
+ # Mixin for Fedipub configuration object which adds Frontend options
6
+ module Configuration
7
+ # Frontend application layout
8
+ mattr_accessor :frontend_layout
9
+ @@frontend_layout = nil
10
+
11
+ # Default controller to use as base for frontend controllers
12
+ mattr_accessor :frontend_base_controller
13
+ @@frontend_base_controller = 'ActionController::Base'
14
+
15
+ def self.file_keys
16
+ [
17
+ :frontend_layout,
18
+ :frontend_base_controller,
19
+ ].freeze
20
+ end
21
+ end
22
+ # rubocop:enable Style/ClassVars
23
+ end
24
+
25
+ module Configuration
26
+ extend Fedipub::Frontend::Configuration
27
+
28
+ class << self
29
+ alias core_file_keys file_keys
30
+
31
+ def file_keys
32
+ Fedipub::Frontend::Configuration.file_keys + core_file_keys
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,9 @@
1
+ require 'fedipub/frontend'
2
+
3
+ module Fedipub
4
+ module Frontend
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace Fedipub::Frontend
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ module Fedipub
2
+ module Frontend
3
+ class Railtie < ::Rails::Railtie
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Fedipub
2
+ module Frontend
3
+ VERSION = '0.12.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require 'fedipub'
2
+
3
+ require 'fedipub/frontend/version'
4
+ require 'fedipub/frontend/engine'
5
+ require 'fedipub/frontend/configuration'
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Copies the Pundit frontend policies to be overridden in main application.
3
+
4
+ Example:
5
+ bin/rails generate fedipub:frontend:copy_policies
6
+
7
+ This will create:
8
+ app/policies/fedipub/frontend/*
@@ -0,0 +1,11 @@
1
+ module Fedipub
2
+ module Frontend
3
+ class CopyPoliciesGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path('../../../../../app/policies/fedipub', __dir__)
5
+
6
+ def copy_policies
7
+ directory 'frontend', ::Rails.root.join('app', 'policies', 'fedipub', 'frontend')
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Copies the frontend views to be overridden in main application
3
+
4
+ Example:
5
+ bin/rails generate fedipub:frontend:copy_views
6
+
7
+ This will create:
8
+ app/views/fedipub/frontend/**/*
@@ -0,0 +1,11 @@
1
+ module Fedipub
2
+ module Frontend
3
+ class CopyViewsGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path('../../../../../app/views', __dir__)
5
+
6
+ def copy_views
7
+ directory 'fedipub/frontend', ::Rails.root.join('app', 'views', 'fedipub', 'frontend')
8
+ end
9
+ end
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fedipub-frontend
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.12.0
5
+ platform: ruby
6
+ authors:
7
+ - Manuel Tancoigne
8
+ - James Smith
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 1980-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fedipub
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.12'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 7.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 7.2.0
41
+ description: Simple Rails frontend controllers and views for use with Fedipub
42
+ email:
43
+ - info@fedipub.dev
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - LICENSE
49
+ - README.md
50
+ - Rakefile
51
+ - app/controllers/fedipub/frontend/activities_controller.rb
52
+ - app/controllers/fedipub/frontend/actors_controller.rb
53
+ - app/controllers/fedipub/frontend/base_controller.rb
54
+ - app/controllers/fedipub/frontend/followings_controller.rb
55
+ - app/policies/fedipub/frontend/activity_policy.rb
56
+ - app/policies/fedipub/frontend/actor_policy.rb
57
+ - app/policies/fedipub/frontend/following_policy.rb
58
+ - app/views/fedipub/frontend/activities/_activity.html.erb
59
+ - app/views/fedipub/frontend/activities/_activity.json.jbuilder
60
+ - app/views/fedipub/frontend/activities/_index.json.jbuilder
61
+ - app/views/fedipub/frontend/activities/feed.html.erb
62
+ - app/views/fedipub/frontend/activities/feed.json.jbuilder
63
+ - app/views/fedipub/frontend/activities/index.html.erb
64
+ - app/views/fedipub/frontend/activities/index.json.jbuilder
65
+ - app/views/fedipub/frontend/actors/_actor.json.jbuilder
66
+ - app/views/fedipub/frontend/actors/_lookup_form.html.erb
67
+ - app/views/fedipub/frontend/actors/gone.html.erb
68
+ - app/views/fedipub/frontend/actors/index.html.erb
69
+ - app/views/fedipub/frontend/actors/index.json.jbuilder
70
+ - app/views/fedipub/frontend/actors/show.html.erb
71
+ - app/views/fedipub/frontend/actors/show.json.jbuilder
72
+ - app/views/fedipub/frontend/common/_client_links.html.erb
73
+ - app/views/fedipub/frontend/followings/_follow.html.erb
74
+ - app/views/fedipub/frontend/followings/_follow_actions.html.erb
75
+ - app/views/fedipub/frontend/followings/_follower.html.erb
76
+ - app/views/fedipub/frontend/followings/_following.json.jbuilder
77
+ - app/views/fedipub/frontend/followings/_form.html.erb
78
+ - app/views/fedipub/frontend/followings/index.html.erb
79
+ - app/views/fedipub/frontend/followings/index.json.jbuilder
80
+ - app/views/fedipub/frontend/followings/show.html.erb
81
+ - app/views/fedipub/frontend/followings/show.json.jbuilder
82
+ - config/routes.rb
83
+ - lib/fedipub/frontend.rb
84
+ - lib/fedipub/frontend/configuration.rb
85
+ - lib/fedipub/frontend/engine.rb
86
+ - lib/fedipub/frontend/railtie.rb
87
+ - lib/fedipub/frontend/version.rb
88
+ - lib/generators/fedipub/frontend/copy_policies/USAGE
89
+ - lib/generators/fedipub/frontend/copy_policies/copy_policies_generator.rb
90
+ - lib/generators/fedipub/frontend/copy_views/USAGE
91
+ - lib/generators/fedipub/frontend/copy_views/copy_views_generator.rb
92
+ homepage: https://fedipub.dev
93
+ licenses:
94
+ - MIT
95
+ metadata:
96
+ rubygems_mfa_required: 'true'
97
+ homepage_uri: https://fedipub.dev
98
+ source_code_uri: https://gitlab.com/fedipub/fedipub-frontend/
99
+ changelog_uri: https://gitlab.com/fedipub/fedipub-frontend/-/blob/main/CHANGELOG.md
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 3.3.0
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.6.9
115
+ specification_version: 4
116
+ summary: Simple Rails frontend controllers and views for use with Fedipub
117
+ test_files: []