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

Allow admins to reject existing followers #91

Draft
wants to merge 41 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3ac89d4
Move category settings to admin panel
angusmcleod Mar 15, 2024
247d024
Fixes and tests
angusmcleod Mar 16, 2024
1b7b790
Merge remote-tracking branch 'upstream/main' into create_activity_pub…
angusmcleod Mar 16, 2024
976b8f4
Fix merge
angusmcleod Mar 16, 2024
4ea297b
Add missing requires
angusmcleod Mar 16, 2024
903ce84
Fix lint errors
angusmcleod Mar 16, 2024
61a301d
Fix rubocop and controller inheritance
angusmcleod Mar 18, 2024
78e0e8f
Fix stree
angusmcleod Mar 18, 2024
dfa7385
Merge remote-tracking branch 'upstream/main' into create_activity_pub…
angusmcleod Apr 17, 2024
64635e2
Fix merge
angusmcleod Apr 18, 2024
06b7c49
Update topic_spec.rb
angusmcleod Apr 18, 2024
c147122
fix typo
pmusaraj Apr 18, 2024
daabbed
Modernize route
pmusaraj Apr 18, 2024
dcc992a
Continue modernizing routes
pmusaraj Apr 18, 2024
494606b
One more
pmusaraj Apr 18, 2024
ecabfd7
Move to admin plugins parent route
angusmcleod Apr 19, 2024
fc157e3
Linting
angusmcleod Apr 19, 2024
ee841c5
Move category custom fields to plugin actor table
angusmcleod Apr 8, 2024
5885b78
Migrate category to abstract actor architechture
angusmcleod Apr 10, 2024
fc1287a
Fixes and cleanup items
angusmcleod Apr 10, 2024
27a748c
First working version of tag actors
angusmcleod Apr 12, 2024
ecc6ee5
Minor fix and linting
angusmcleod Apr 12, 2024
7f49bb5
Improve tag and category chooser styling
angusmcleod Apr 12, 2024
dbc1e79
Explicitly handle taxonomic overlap
angusmcleod Apr 12, 2024
fb61f31
Various fixes
angusmcleod Apr 19, 2024
1c2bfed
Merge remote-tracking branch 'upstream/main' into add_tag_actors
angusmcleod Apr 19, 2024
591a15c
Fixes from merge
angusmcleod Apr 20, 2024
fc04ca0
Fix linting
angusmcleod Apr 20, 2024
924142b
More linting fixes
angusmcleod Apr 20, 2024
b70f8f1
First working version
angusmcleod Apr 24, 2024
6dc9efd
Working server-side
angusmcleod Apr 29, 2024
6d75c39
Working version
angusmcleod Apr 30, 2024
06dc879
Linting
angusmcleod May 1, 2024
d6c1a4c
Fix tests
angusmcleod May 1, 2024
72b0f0d
Linting fixes
angusmcleod May 1, 2024
39d60bc
Update verify redirect error text
angusmcleod May 1, 2024
1b44422
Merge remote-tracking branch 'upstream/main' into add_discourse_to_di…
angusmcleod May 7, 2024
07e150f
Remove duplicated methods from merge
angusmcleod May 7, 2024
b467063
Working version
angusmcleod Apr 19, 2024
9dda938
Fixes from merge
angusmcleod Apr 20, 2024
601d3cb
More fixes from merge
angusmcleod Apr 20, 2024
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
65 changes: 45 additions & 20 deletions app/controllers/discourse_activity_pub/actor_controller.rb
Expand Up @@ -9,12 +9,13 @@ class ActorController < ApplicationController

include DiscourseActivityPub::EnabledVerification

before_action :ensure_admin, only: %i[follow unfollow find_by_handle]
before_action :ensure_admin, only: %i[follow unfollow reject find_by_handle]
before_action :ensure_site_enabled
before_action :find_actor
before_action :ensure_model_enabled
before_action :ensure_can_access
before_action :find_target_actor, only: %i[follow unfollow]
before_action :ensure_user_api, only: %i[find_by_user]
before_action :find_actor, except: %i[find_by_user]
before_action :ensure_model_enabled, except: %i[find_by_user]
before_action :ensure_can_access, except: %i[find_by_user]
before_action :find_target_actor, only: %i[follow unfollow reject]

def show
render_serialized(@actor, DiscourseActivityPub::ActorSerializer, include_model: true)
Expand Down Expand Up @@ -44,6 +45,34 @@ def unfollow
end
end

def follows
guardian.ensure_can_admin!(@actor)

actors.each { |actor| actor.followed_at = actor.follow_followers&.first&.followed_at }

render_actors
end

def followers
guardian.ensure_can_see!(@actor.model)

actors.each { |actor| actor.followed_at = actor.follow_follows&.first&.followed_at }

render_actors
end

def reject
# Currently, we only process rejections of existing follows.
# See further https://github.com/mastodon/mastodon/issues/5708
return render_actor_error("not_following_actor", 404) if !@target_actor.following?(@actor)

if FollowHandler.reject(@actor.id, @target_actor.id)
render json: success_json
else
render json: failed_json
end
end

def find_by_handle
params.require(:handle)

Expand All @@ -59,20 +88,12 @@ def find_by_handle
end
end

def follows
guardian.ensure_can_admin!(@actor)

actors.each { |actor| actor.followed_at = actor.follow_followers&.first&.followed_at }

render_actors
end

def followers
guardian.ensure_can_see!(@actor.model)

actors.each { |actor| actor.followed_at = actor.follow_follows&.first&.followed_at }

render_actors
def find_by_user
if current_user.present? && current_user.activity_pub_actor.present?
render json: current_user.activity_pub_actor.ap.json
else
render json: failed_json, status: 404
end
end

protected
Expand Down Expand Up @@ -145,7 +166,7 @@ def order
def load_more_url(page)
load_more_params = params.slice(:order, :asc).permit!
load_more_params[:page] = page + 1
load_more_uri = ::URI.parse("/ap/actor/#{params[:actor_id]}/followers.json")
load_more_uri = ::URI.parse("/ap/local/actor/#{params[:actor_id]}/followers.json")
load_more_uri.query = ::URI.encode_www_form(load_more_params.to_h)
load_more_uri.to_s
end
Expand All @@ -169,6 +190,10 @@ def find_target_actor
render_actor_error("target_actor_not_found", 404) unless @target_actor.present?
end

def ensure_user_api
render_actor_error("user_not_authorized", 403) unless is_user_api?
end

def render_actor_error(key, status)
render_json_error I18n.t("discourse_activity_pub.actor.error.#{key}"), status: status
end
Expand Down

This file was deleted.

91 changes: 0 additions & 91 deletions app/controllers/discourse_activity_pub/auth/oauth_controller.rb

This file was deleted.

22 changes: 0 additions & 22 deletions app/controllers/discourse_activity_pub/auth_controller.rb

This file was deleted.