Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
feat(admin): allow removing a follower without blocking them
Gabe Kangasac657a838879
diff --git a/openapi.yaml b/openapi.yamlindex 26f2e29f41..ae66439a4f 100644--- a/openapi.yaml+++ b/openapi.yaml@@ -982,6 +982,44 @@ paths:responses:'204':$ref: '#/components/responses/204'+ /admin/followers/remove:+ post:+ summary: Remove a follower without blocking them (they may follow again)+ operationId: RemoveFollower+ tags: ['Internal', 'Admin', 'Social']+ security:+ - BasicAuth: []+ requestBody:+ content:+ application/json:+ schema:+ type: object+ required:+ - actorIRI+ properties:+ actorIRI:+ type: string+ description: IRI of the follower to remove+ responses:+ '200':+ description: Follower removed+ content:+ application/json:+ schema:+ $ref: '#/components/schemas/BaseAPIResponse'+ '400':+ $ref: '#/components/responses/400'+ '401':+ $ref: '#/components/responses/401BasicAuth'+ default:+ $ref: '#/components/responses/Default'+ options:+ operationId: RemoveFollowerOptions+ x-internal: true+ tags: ['Objects', 'Internal', 'Admin', 'Social']+ responses:+ '204':+ $ref: '#/components/responses/204'/admin/emoji/upload:post:summary: Upload custom emojidiff --git a/test/automated/activitypub/test-following.sh b/test/automated/activitypub/test-following.shindex 790352aaa3..0fde76c905 100755--- a/test/automated/activitypub/test-following.sh+++ b/test/automated/activitypub/test-following.sh@@ -61,6 +61,7 @@ log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }log_error() { echo -e "${RED}[ERROR]${NC} $1"; }log_test() { echo -e "${CYAN}[TEST]${NC} $1"; }+# shellcheck disable=SC2329 # invoked via trap, not called directlycleanup() {log_info "Cleaning up..."@@ -505,6 +506,58 @@ test_message_delivery_to_snac2_followers() {return 1}+test_remove_follower_without_ban() {+ log_test "TEST 4: Removing a follower removes them without banning"++ local auth+ auth=$(get_admin_auth)++ local followers_json link before+ followers_json=$(curl -s "http://localhost:${OWNCAST_PORT}/api/admin/followers?limit=200" \+ -H "Authorization: Basic ${auth}")+ link=$(echo "${followers_json}" | jq -r '.results[0].link // empty' 2>/dev/null)+ before=$(echo "${followers_json}" | jq -r '.total // 0' 2>/dev/null)++ if [[ -z "${link}" ]]; then+ log_error "TEST 4 FAILED: no follower available to remove"+ return 1+ fi++ log_info "Removing follower ${link} (count before: ${before})"+ curl -s -X POST "http://localhost:${OWNCAST_PORT}/api/admin/followers/remove" \+ -H "Authorization: Basic ${auth}" -H "Content-Type: application/json" \+ -d "{\"actorIRI\": \"${link}\"}" > /dev/null++ # The follower count must drop.+ local waited=0 after="${before}"+ while [[ ${waited} -lt 20 ]]; do+ after=$(get_follower_count)+ if [[ "${after}" -lt "${before}" ]]; then+ break+ fi+ sleep 2+ waited=$((waited + 2))+ done+ if [[ "${after}" -ge "${before}" ]]; then+ log_error "TEST 4 FAILED: follower count did not drop after removal (${before} -> ${after})"+ return 1+ fi++ # Crucially, the removed follower must NOT appear in the blocked list:+ # removing is not banning.+ local blocked_json+ blocked_json=$(curl -s "http://localhost:${OWNCAST_PORT}/api/admin/followers/blocked" \+ -H "Authorization: Basic ${auth}")+ if echo "${blocked_json}" | jq -e --arg link "${link}" '.[]? | select(.link == $link)' > /dev/null 2>&1; then+ log_error "TEST 4 FAILED: removed follower ${link} was banned (present in blocked list)"+ log_error "Blocked: ${blocked_json}"+ return 1+ fi++ log_test "TEST 4 PASSED: follower removed (${before} -> ${after}) and not blocked"+ return 0+}+# ==========================# Results# ==========================@@ -600,6 +653,13 @@ main() {fiecho ""+ if test_remove_follower_without_ban; then+ passed=$((passed + 1))+ else+ failed=$((failed + 1))+ fi+ echo ""+# ==========================================# Results# ==========================================diff --git a/web/pages/admin/federation/followers.tsx b/web/pages/admin/federation/followers.tsxindex 1506807f90..92fecc88d4 100644--- a/web/pages/admin/federation/followers.tsx+++ b/web/pages/admin/federation/followers.tsx@@ -9,6 +9,7 @@ import {FOLLOWERS_PENDING,SET_FOLLOWER_APPROVAL,FOLLOWERS_BLOCKED,+ REMOVE_FOLLOWER,fetchData,} from '../../../utils/apis';import { isEmptyObject } from '../../../utils/format';@@ -21,7 +22,13 @@ const UserAddOutlined = dynamic(() => import('@ant-design/icons/UserAddOutlined'ssr: false,});-const UserDeleteOutlined = dynamic(() => import('@ant-design/icons/UserDeleteOutlined'), {+// Used for removing a follower (without blocking them).+const DeleteOutlined = dynamic(() => import('@ant-design/icons/DeleteOutlined'), {+ ssr: false,+});++// Used for blocking/banning a follower; a clearer "no entry" mark.+const StopOutlined = dynamic(() => import('@ant-design/icons/StopOutlined'), {ssr: false,});export interface Follower {@@ -171,6 +178,24 @@ export default function FediverseFollowers() {}}+ // Remove a follower without blocking them. They are free to follow again.+ async function removeFollower(request) {+ try {+ await fetchData(REMOVE_FOLLOWER, {+ auth: true,+ method: 'POST',+ data: {+ actorIRI: request.link,+ },+ });++ // Refetch and update the current data.+ getFollowers();+ } catch (err) {+ console.error(err);+ }+ }+const pendingColumns: ColumnsType<Follower> = [...columns];pendingColumns.unshift({@@ -196,7 +221,8 @@ export default function FediverseFollowers() {<Buttontype="primary"danger- icon={<UserDeleteOutlined />}+ title="Reject and block this request"+ icon={<StopOutlined />}onClick={() => {rejectFollowRequest(request);}}@@ -286,12 +312,28 @@ export default function FediverseFollowers() {{title: 'Remove',dataIndex: null,- key: null,+ key: 'remove',+ render: request => (+ <Button+ title="Remove this follower (they can follow again)"+ icon={<DeleteOutlined />}+ onClick={() => {+ removeFollower(request);+ }}+ />+ ),+ width: 50,+ },+ {+ title: 'Block',+ dataIndex: null,+ key: 'block',render: request => (<Buttontype="primary"danger- icon={<UserDeleteOutlined />}+ title="Block this follower (prevents them from following again)"+ icon={<StopOutlined />}onClick={() => {rejectFollowRequest(request);}}diff --git a/web/utils/apis.ts b/web/utils/apis.tsindex 269e43dede..130b33f58e 100644--- a/web/utils/apis.ts+++ b/web/utils/apis.ts@@ -116,6 +116,9 @@ export const FOLLOWERS_BLOCKED = `${API_LOCATION}followers/blocked`;// Approve, reject a follow requestexport const SET_FOLLOWER_APPROVAL = `${API_LOCATION}followers/approve`;+// Remove a follower without blocking them (they may follow again)+export const REMOVE_FOLLOWER = `${API_LOCATION}followers/remove`;+// List of inbound federated actions that took place.export const FEDERATION_ACTIONS = `${API_LOCATION}federation/actions`;diff --git a/webserver/handlers/admin.go b/webserver/handlers/admin.goindex 3cf28ff825..0a1b39681a 100644--- a/webserver/handlers/admin.go+++ b/webserver/handlers/admin.go@@ -184,6 +184,14 @@ func (s *ServerInterfaceImpl) ApproveFollowerOptions(w http.ResponseWriter, r *hs.h.middleware.RequireAdminAuth(s.h.admin.ApproveFollower)(w, r)}+func (s *ServerInterfaceImpl) RemoveFollower(w http.ResponseWriter, r *http.Request) {+ s.h.middleware.RequireAdminAuth(s.h.admin.RemoveFollower)(w, r)+}++func (s *ServerInterfaceImpl) RemoveFollowerOptions(w http.ResponseWriter, r *http.Request) {+ s.h.middleware.RequireAdminAuth(s.h.admin.RemoveFollower)(w, r)+}+func (s *ServerInterfaceImpl) UploadCustomEmoji(w http.ResponseWriter, r *http.Request) {s.h.middleware.RequireAdminAuth(admin.UploadCustomEmoji)(w, r)}diff --git a/webserver/handlers/admin/followers.go b/webserver/handlers/admin/followers.goindex e3067a0400..caf6b7fae2 100644--- a/webserver/handlers/admin/followers.go+++ b/webserver/handlers/admin/followers.go@@ -67,6 +67,32 @@ func (a *Admin) ApproveFollower(w http.ResponseWriter, r *http.Request) {webutils.WriteSimpleResponse(w, true, "follower updated")}+// RemoveFollower removes a follower without blocking them. Unlike rejecting,+// this deletes the follow outright (no disabled_at), so the actor is free to+// follow again later.+func (a *Admin) RemoveFollower(w http.ResponseWriter, r *http.Request) {+ if !requirePOST(w, r) {+ return+ }++ var request generated.RemoveFollowerJSONBody+ if err := json.NewDecoder(r.Body).Decode(&request); err != nil {+ webutils.WriteSimpleResponse(w, false, "unable to parse request: "+err.Error())+ return+ }+ if request.ActorIRI == "" {+ webutils.WriteSimpleResponse(w, false, "actorIRI is required")+ return+ }++ if err := a.followersRepository.RemoveByIRI(request.ActorIRI); err != nil {+ webutils.WriteSimpleResponse(w, false, err.Error())+ return+ }++ webutils.WriteSimpleResponse(w, true, "follower removed")+}+// GetPendingFollowRequests will return a list of pending follow requests.func (a *Admin) GetPendingFollowRequests(w http.ResponseWriter, r *http.Request) {requests, err := a.followersRepository.GetPendingFollowRequests()diff --git a/webserver/handlers/generated/generated-types.gen.go b/webserver/handlers/generated/generated-types.gen.goindex 975831a7d7..2b9842402f 100644--- a/webserver/handlers/generated/generated-types.gen.go+++ b/webserver/handlers/generated/generated-types.gen.go@@ -807,6 +807,12 @@ type ApproveFollowerJSONBody struct {Approved *bool `json:"approved,omitempty"`}+// RemoveFollowerJSONBody defines parameters for RemoveFollower.+type RemoveFollowerJSONBody struct {+ // ActorIRI IRI of the follower to remove+ ActorIRI string `json:"actorIRI"`+}+// GetViewersOverTimeParams defines parameters for GetViewersOverTime.type GetViewersOverTimeParams struct {// WindowStart Start date in unix time@@ -1108,6 +1114,9 @@ type AddFederatedServerJSONRequestBody AddFederatedServerJSONBody// ApproveFollowerJSONRequestBody defines body for ApproveFollower for application/json ContentType.type ApproveFollowerJSONRequestBody ApproveFollowerJSONBody+// RemoveFollowerJSONRequestBody defines body for RemoveFollower for application/json ContentType.+type RemoveFollowerJSONRequestBody RemoveFollowerJSONBody+// CreateWebhookJSONRequestBody defines body for CreateWebhook for application/json ContentType.type CreateWebhookJSONRequestBody CreateWebhookJSONBodydiff --git a/webserver/handlers/generated/generated.gen.go b/webserver/handlers/generated/generated.gen.goindex 47bde66720..254242aa52 100644--- a/webserver/handlers/generated/generated.gen.go+++ b/webserver/handlers/generated/generated.gen.go@@ -446,6 +446,12 @@ type ServerInterface interface {// (OPTIONS /admin/followers/pending)GetPendingFollowRequestsOptions(w http.ResponseWriter, r *http.Request)++ // (OPTIONS /admin/followers/remove)+ RemoveFollowerOptions(w http.ResponseWriter, r *http.Request)+ // Remove a follower without blocking them (they may follow again)+ // (POST /admin/followers/remove)+ RemoveFollower(w http.ResponseWriter, r *http.Request)// Get the current hardware stats// (GET /admin/hardwarestats)GetHardwareStats(w http.ResponseWriter, r *http.Request)@@ -1482,6 +1488,17 @@ func (_ Unimplemented) GetPendingFollowRequestsOptions(w http.ResponseWriter, rw.WriteHeader(http.StatusNotImplemented)}+// (OPTIONS /admin/followers/remove)+func (_ Unimplemented) RemoveFollowerOptions(w http.ResponseWriter, r *http.Request) {+ w.WriteHeader(http.StatusNotImplemented)+}++// Remove a follower without blocking them (they may follow again)+// (POST /admin/followers/remove)+func (_ Unimplemented) RemoveFollower(w http.ResponseWriter, r *http.Request) {+ w.WriteHeader(http.StatusNotImplemented)+}+// Get the current hardware stats// (GET /admin/hardwarestats)func (_ Unimplemented) GetHardwareStats(w http.ResponseWriter, r *http.Request) {@@ -4314,6 +4331,38 @@ func (siw *ServerInterfaceWrapper) GetPendingFollowRequestsOptions(w http.Responhandler.ServeHTTP(w, r)}+// RemoveFollowerOptions operation middleware+func (siw *ServerInterfaceWrapper) RemoveFollowerOptions(w http.ResponseWriter, r *http.Request) {+ handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ siw.Handler.RemoveFollowerOptions(w, r)+ }))++ for _, middleware := range siw.HandlerMiddlewares {+ handler = middleware(handler)+ }++ handler.ServeHTTP(w, r)+}++// RemoveFollower operation middleware+func (siw *ServerInterfaceWrapper) RemoveFollower(w http.ResponseWriter, r *http.Request) {+ ctx := r.Context()++ ctx = context.WithValue(ctx, BasicAuthScopes, []string{})++ r = r.WithContext(ctx)++ handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ siw.Handler.RemoveFollower(w, r)+ }))++ for _, middleware := range siw.HandlerMiddlewares {+ handler = middleware(handler)+ }++ handler.ServeHTTP(w, r)+}+// GetHardwareStats operation middlewarefunc (siw *ServerInterfaceWrapper) GetHardwareStats(w http.ResponseWriter, r *http.Request) {ctx := r.Context()@@ -6363,6 +6412,12 @@ func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handlr.Group(func(r chi.Router) {r.Options(options.BaseURL+"/admin/followers/pending", wrapper.GetPendingFollowRequestsOptions)})+ r.Group(func(r chi.Router) {+ r.Options(options.BaseURL+"/admin/followers/remove", wrapper.RemoveFollowerOptions)+ })+ r.Group(func(r chi.Router) {+ r.Post(options.BaseURL+"/admin/followers/remove", wrapper.RemoveFollower)+ })r.Group(func(r chi.Router) {r.Get(options.BaseURL+"/admin/hardwarestats", wrapper.GetHardwareStats)})