summaryrefslogtreecommitdiff
path: root/internal/api/client/followrequest
diff options
context:
space:
mode:
Diffstat (limited to 'internal/api/client/followrequest')
-rw-r--r--internal/api/client/followrequest/authorize.go98
-rw-r--r--internal/api/client/followrequest/authorize_test.go115
-rw-r--r--internal/api/client/followrequest/followrequest.go61
-rw-r--r--internal/api/client/followrequest/followrequest_test.go122
-rw-r--r--internal/api/client/followrequest/get.go93
-rw-r--r--internal/api/client/followrequest/get_test.go78
-rw-r--r--internal/api/client/followrequest/reject.go96
-rw-r--r--internal/api/client/followrequest/reject_test.go87
8 files changed, 0 insertions, 750 deletions
diff --git a/internal/api/client/followrequest/authorize.go b/internal/api/client/followrequest/authorize.go
deleted file mode 100644
index a5a392f76..000000000
--- a/internal/api/client/followrequest/authorize.go
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package followrequest
-
-import (
- "errors"
- "net/http"
-
- "github.com/gin-gonic/gin"
- "github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
- "github.com/superseriousbusiness/gotosocial/internal/oauth"
-)
-
-// FollowRequestAuthorizePOSTHandler swagger:operation POST /api/v1/follow_requests/{account_id}/authorize authorizeFollowRequest
-//
-// Accept/authorize follow request from the given account ID.
-//
-// Accept a follow request and put the requesting account in your 'followers' list.
-//
-// ---
-// tags:
-// - follow_requests
-//
-// produces:
-// - application/json
-//
-// parameters:
-// -
-// name: account_id
-// type: string
-// description: ID of the account requesting to follow you.
-// in: path
-// required: true
-//
-// security:
-// - OAuth2 Bearer:
-// - write:follows
-//
-// responses:
-// '200':
-// name: account relationship
-// description: Your relationship to this account.
-// schema:
-// "$ref": "#/definitions/accountRelationship"
-// '400':
-// description: bad request
-// '401':
-// description: unauthorized
-// '404':
-// description: not found
-// '406':
-// description: not acceptable
-// '500':
-// description: internal server error
-func (m *Module) FollowRequestAuthorizePOSTHandler(c *gin.Context) {
- authed, err := oauth.Authed(c, true, true, true, true)
- if err != nil {
- api.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet)
- return
- }
-
- if _, err := api.NegotiateAccept(c, api.JSONAcceptHeaders...); err != nil {
- api.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet)
- return
- }
-
- originAccountID := c.Param(IDKey)
- if originAccountID == "" {
- err := errors.New("no account id specified")
- api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet)
- return
- }
-
- relationship, errWithCode := m.processor.FollowRequestAccept(c.Request.Context(), authed, originAccountID)
- if errWithCode != nil {
- api.ErrorHandler(c, errWithCode, m.processor.InstanceGet)
- return
- }
-
- c.JSON(http.StatusOK, relationship)
-}
diff --git a/internal/api/client/followrequest/authorize_test.go b/internal/api/client/followrequest/authorize_test.go
deleted file mode 100644
index 693380d91..000000000
--- a/internal/api/client/followrequest/authorize_test.go
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package followrequest_test
-
-import (
- "context"
- "fmt"
- "io/ioutil"
- "net/http"
- "net/http/httptest"
- "testing"
- "time"
-
- "github.com/gin-gonic/gin"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/suite"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/followrequest"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
-)
-
-type AuthorizeTestSuite struct {
- FollowRequestStandardTestSuite
-}
-
-func (suite *AuthorizeTestSuite) TestAuthorize() {
- requestingAccount := suite.testAccounts["remote_account_2"]
- targetAccount := suite.testAccounts["local_account_1"]
-
- // put a follow request in the database
- fr := &gtsmodel.FollowRequest{
- ID: "01FJ1S8DX3STJJ6CEYPMZ1M0R3",
- CreatedAt: time.Now(),
- UpdatedAt: time.Now(),
- URI: fmt.Sprintf("%s/follow/01FJ1S8DX3STJJ6CEYPMZ1M0R3", requestingAccount.URI),
- AccountID: requestingAccount.ID,
- TargetAccountID: targetAccount.ID,
- }
-
- err := suite.db.Put(context.Background(), fr)
- suite.NoError(err)
-
- recorder := httptest.NewRecorder()
- ctx := suite.newContext(recorder, http.MethodPost, []byte{}, fmt.Sprintf("/api/v1/follow_requests/%s/authorize", requestingAccount.ID), "")
-
- ctx.Params = gin.Params{
- gin.Param{
- Key: followrequest.IDKey,
- Value: requestingAccount.ID,
- },
- }
-
- // call the handler
- suite.followRequestModule.FollowRequestAuthorizePOSTHandler(ctx)
-
- // 1. we should have OK because our request was valid
- suite.Equal(http.StatusOK, recorder.Code)
-
- // 2. we should have no error message in the result body
- result := recorder.Result()
- defer result.Body.Close()
-
- // check the response
- b, err := ioutil.ReadAll(result.Body)
- assert.NoError(suite.T(), err)
-
- suite.Equal(`{"id":"01FHMQX3GAABWSM0S2VZEC2SWC","following":false,"showing_reblogs":false,"notifying":false,"followed_by":true,"blocking":false,"blocked_by":false,"muting":false,"muting_notifications":false,"requested":false,"domain_blocking":false,"endorsed":false,"note":""}`, string(b))
-}
-
-func (suite *AuthorizeTestSuite) TestAuthorizeNoFR() {
- requestingAccount := suite.testAccounts["remote_account_2"]
-
- recorder := httptest.NewRecorder()
- ctx := suite.newContext(recorder, http.MethodPost, []byte{}, fmt.Sprintf("/api/v1/follow_requests/%s/authorize", requestingAccount.ID), "")
-
- ctx.Params = gin.Params{
- gin.Param{
- Key: followrequest.IDKey,
- Value: requestingAccount.ID,
- },
- }
-
- // call the handler
- suite.followRequestModule.FollowRequestAuthorizePOSTHandler(ctx)
-
- suite.Equal(http.StatusNotFound, recorder.Code)
-
- result := recorder.Result()
- defer result.Body.Close()
-
- // check the response
- b, err := ioutil.ReadAll(result.Body)
- assert.NoError(suite.T(), err)
-
- suite.Equal(`{"error":"Not Found"}`, string(b))
-}
-
-func TestAuthorizeTestSuite(t *testing.T) {
- suite.Run(t, &AuthorizeTestSuite{})
-}
diff --git a/internal/api/client/followrequest/followrequest.go b/internal/api/client/followrequest/followrequest.go
deleted file mode 100644
index a511d7226..000000000
--- a/internal/api/client/followrequest/followrequest.go
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package followrequest
-
-import (
- "net/http"
-
- "github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/processing"
- "github.com/superseriousbusiness/gotosocial/internal/router"
-)
-
-const (
- // IDKey is for account IDs
- IDKey = "id"
- // BasePath is the base path for serving the follow request API
- BasePath = "/api/v1/follow_requests"
- // BasePathWithID is just the base path with the ID key in it.
- // Use this anywhere you need to know the ID of the account that owns the follow request being queried.
- BasePathWithID = BasePath + "/:" + IDKey
- // AuthorizePath is used for authorizing follow requests
- AuthorizePath = BasePathWithID + "/authorize"
- // RejectPath is used for rejecting follow requests
- RejectPath = BasePathWithID + "/reject"
-)
-
-// Module implements the ClientAPIModule interface
-type Module struct {
- processor processing.Processor
-}
-
-// New returns a new follow request module
-func New(processor processing.Processor) api.ClientModule {
- return &Module{
- processor: processor,
- }
-}
-
-// Route attaches all routes from this module to the given router
-func (m *Module) Route(r router.Router) error {
- r.AttachHandler(http.MethodGet, BasePath, m.FollowRequestGETHandler)
- r.AttachHandler(http.MethodPost, AuthorizePath, m.FollowRequestAuthorizePOSTHandler)
- r.AttachHandler(http.MethodPost, RejectPath, m.FollowRequestRejectPOSTHandler)
- return nil
-}
diff --git a/internal/api/client/followrequest/followrequest_test.go b/internal/api/client/followrequest/followrequest_test.go
deleted file mode 100644
index ca00ea054..000000000
--- a/internal/api/client/followrequest/followrequest_test.go
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package followrequest_test
-
-import (
- "bytes"
- "fmt"
- "net/http/httptest"
-
- "github.com/gin-gonic/gin"
- "github.com/stretchr/testify/suite"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/followrequest"
- "github.com/superseriousbusiness/gotosocial/internal/concurrency"
- "github.com/superseriousbusiness/gotosocial/internal/config"
- "github.com/superseriousbusiness/gotosocial/internal/db"
- "github.com/superseriousbusiness/gotosocial/internal/email"
- "github.com/superseriousbusiness/gotosocial/internal/federation"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
- "github.com/superseriousbusiness/gotosocial/internal/media"
- "github.com/superseriousbusiness/gotosocial/internal/messages"
- "github.com/superseriousbusiness/gotosocial/internal/oauth"
- "github.com/superseriousbusiness/gotosocial/internal/processing"
- "github.com/superseriousbusiness/gotosocial/internal/storage"
- "github.com/superseriousbusiness/gotosocial/testrig"
-)
-
-type FollowRequestStandardTestSuite struct {
- suite.Suite
- db db.DB
- storage *storage.Driver
- mediaManager media.Manager
- federator federation.Federator
- processor processing.Processor
- emailSender email.Sender
-
- // standard suite models
- testTokens map[string]*gtsmodel.Token
- testClients map[string]*gtsmodel.Client
- testApplications map[string]*gtsmodel.Application
- testUsers map[string]*gtsmodel.User
- testAccounts map[string]*gtsmodel.Account
- testAttachments map[string]*gtsmodel.MediaAttachment
- testStatuses map[string]*gtsmodel.Status
-
- // module being tested
- followRequestModule *followrequest.Module
-}
-
-func (suite *FollowRequestStandardTestSuite) SetupSuite() {
- suite.testTokens = testrig.NewTestTokens()
- suite.testClients = testrig.NewTestClients()
- suite.testApplications = testrig.NewTestApplications()
- suite.testUsers = testrig.NewTestUsers()
- suite.testAccounts = testrig.NewTestAccounts()
- suite.testAttachments = testrig.NewTestAttachments()
- suite.testStatuses = testrig.NewTestStatuses()
-}
-
-func (suite *FollowRequestStandardTestSuite) SetupTest() {
- testrig.InitTestConfig()
- testrig.InitTestLog()
-
- fedWorker := concurrency.NewWorkerPool[messages.FromFederator](-1, -1)
- clientWorker := concurrency.NewWorkerPool[messages.FromClientAPI](-1, -1)
-
- suite.db = testrig.NewTestDB()
- suite.storage = testrig.NewInMemoryStorage()
- suite.mediaManager = testrig.NewTestMediaManager(suite.db, suite.storage)
- suite.federator = testrig.NewTestFederator(suite.db, testrig.NewTestTransportController(testrig.NewMockHTTPClient(nil, "../../../../testrig/media"), suite.db, fedWorker), suite.storage, suite.mediaManager, fedWorker)
- suite.emailSender = testrig.NewEmailSender("../../../../web/template/", nil)
- suite.processor = testrig.NewTestProcessor(suite.db, suite.storage, suite.federator, suite.emailSender, suite.mediaManager, clientWorker, fedWorker)
- suite.followRequestModule = followrequest.New(suite.processor).(*followrequest.Module)
- testrig.StandardDBSetup(suite.db, nil)
- testrig.StandardStorageSetup(suite.storage, "../../../../testrig/media")
-
- suite.NoError(suite.processor.Start())
-}
-
-func (suite *FollowRequestStandardTestSuite) TearDownTest() {
- testrig.StandardDBTeardown(suite.db)
- testrig.StandardStorageTeardown(suite.storage)
-}
-
-func (suite *FollowRequestStandardTestSuite) newContext(recorder *httptest.ResponseRecorder, requestMethod string, requestBody []byte, requestPath string, bodyContentType string) *gin.Context {
- ctx, _ := testrig.CreateGinTestContext(recorder, nil)
-
- ctx.Set(oauth.SessionAuthorizedAccount, suite.testAccounts["local_account_1"])
- ctx.Set(oauth.SessionAuthorizedToken, oauth.DBTokenToToken(suite.testTokens["local_account_1"]))
- ctx.Set(oauth.SessionAuthorizedApplication, suite.testApplications["application_1"])
- ctx.Set(oauth.SessionAuthorizedUser, suite.testUsers["local_account_1"])
-
- protocol := config.GetProtocol()
- host := config.GetHost()
-
- baseURI := fmt.Sprintf("%s://%s", protocol, host)
- requestURI := fmt.Sprintf("%s/%s", baseURI, requestPath)
-
- ctx.Request = httptest.NewRequest(requestMethod, requestURI, bytes.NewReader(requestBody)) // the endpoint we're hitting
-
- if bodyContentType != "" {
- ctx.Request.Header.Set("Content-Type", bodyContentType)
- }
- ctx.Request.Header.Set("accept", "application/json")
-
- return ctx
-}
diff --git a/internal/api/client/followrequest/get.go b/internal/api/client/followrequest/get.go
deleted file mode 100644
index 8a2be3686..000000000
--- a/internal/api/client/followrequest/get.go
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package followrequest
-
-import (
- "net/http"
-
- "github.com/gin-gonic/gin"
- "github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
- "github.com/superseriousbusiness/gotosocial/internal/oauth"
-)
-
-// FollowRequestGETHandler swagger:operation GET /api/v1/follow_requests getFollowRequests
-//
-// Get an array of accounts that have requested to follow you.
-// Accounts will be sorted in order of follow request date descending (newest first).
-//
-// ---
-// tags:
-// - follow_requests
-//
-// produces:
-// - application/json
-//
-// parameters:
-// -
-// name: limit
-// type: integer
-// description: Number of accounts to return.
-// default: 40
-// in: query
-//
-// security:
-// - OAuth2 Bearer:
-// - read:follows
-//
-// responses:
-// '200':
-// headers:
-// Link:
-// type: string
-// description: Links to the next and previous queries.
-// schema:
-// type: array
-// items:
-// "$ref": "#/definitions/account"
-// '400':
-// description: bad request
-// '401':
-// description: unauthorized
-// '404':
-// description: not found
-// '406':
-// description: not acceptable
-// '500':
-// description: internal server error
-func (m *Module) FollowRequestGETHandler(c *gin.Context) {
- authed, err := oauth.Authed(c, true, true, true, true)
- if err != nil {
- api.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet)
- return
- }
-
- if _, err := api.NegotiateAccept(c, api.JSONAcceptHeaders...); err != nil {
- api.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet)
- return
- }
-
- accts, errWithCode := m.processor.FollowRequestsGet(c.Request.Context(), authed)
- if errWithCode != nil {
- api.ErrorHandler(c, errWithCode, m.processor.InstanceGet)
- return
- }
-
- c.JSON(http.StatusOK, accts)
-}
diff --git a/internal/api/client/followrequest/get_test.go b/internal/api/client/followrequest/get_test.go
deleted file mode 100644
index c9b72a35b..000000000
--- a/internal/api/client/followrequest/get_test.go
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package followrequest_test
-
-import (
- "context"
- "fmt"
- "io/ioutil"
- "net/http"
- "net/http/httptest"
- "testing"
- "time"
-
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/suite"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
-)
-
-type GetTestSuite struct {
- FollowRequestStandardTestSuite
-}
-
-func (suite *GetTestSuite) TestGet() {
- requestingAccount := suite.testAccounts["remote_account_2"]
- targetAccount := suite.testAccounts["local_account_1"]
-
- // put a follow request in the database
- fr := &gtsmodel.FollowRequest{
- ID: "01FJ1S8DX3STJJ6CEYPMZ1M0R3",
- CreatedAt: time.Now(),
- UpdatedAt: time.Now(),
- URI: fmt.Sprintf("%s/follow/01FJ1S8DX3STJJ6CEYPMZ1M0R3", requestingAccount.URI),
- AccountID: requestingAccount.ID,
- TargetAccountID: targetAccount.ID,
- }
-
- err := suite.db.Put(context.Background(), fr)
- suite.NoError(err)
-
- recorder := httptest.NewRecorder()
- ctx := suite.newContext(recorder, http.MethodGet, []byte{}, "/api/v1/follow_requests", "")
-
- // call the handler
- suite.followRequestModule.FollowRequestGETHandler(ctx)
-
- // 1. we should have OK because our request was valid
- suite.Equal(http.StatusOK, recorder.Code)
-
- // 2. we should have no error message in the result body
- result := recorder.Result()
- defer result.Body.Close()
-
- // check the response
- b, err := ioutil.ReadAll(result.Body)
- assert.NoError(suite.T(), err)
-
- suite.Equal(`[{"id":"01FHMQX3GAABWSM0S2VZEC2SWC","username":"Some_User","acct":"Some_User@example.org","display_name":"some user","locked":true,"bot":false,"created_at":"2020-08-10T12:13:28.000Z","note":"i'm a real son of a gun","url":"http://example.org/@Some_User","avatar":"","avatar_static":"","header":"http://localhost:8080/assets/default_header.png","header_static":"http://localhost:8080/assets/default_header.png","followers_count":0,"following_count":0,"statuses_count":0,"last_status_at":null,"emojis":[],"fields":[]}]`, string(b))
-}
-
-func TestGetTestSuite(t *testing.T) {
- suite.Run(t, &GetTestSuite{})
-}
diff --git a/internal/api/client/followrequest/reject.go b/internal/api/client/followrequest/reject.go
deleted file mode 100644
index 717dbf4dd..000000000
--- a/internal/api/client/followrequest/reject.go
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package followrequest
-
-import (
- "errors"
- "net/http"
-
- "github.com/gin-gonic/gin"
- "github.com/superseriousbusiness/gotosocial/internal/api"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
- "github.com/superseriousbusiness/gotosocial/internal/oauth"
-)
-
-// FollowRequestRejectPOSTHandler swagger:operation POST /api/v1/follow_requests/{account_id}/reject rejectFollowRequest
-//
-// Reject/deny follow request from the given account ID.
-//
-// ---
-// tags:
-// - follow_requests
-//
-// produces:
-// - application/json
-//
-// parameters:
-// -
-// name: account_id
-// type: string
-// description: ID of the account requesting to follow you.
-// in: path
-// required: true
-//
-// security:
-// - OAuth2 Bearer:
-// - write:follows
-//
-// responses:
-// '200':
-// name: account relationship
-// description: Your relationship to this account.
-// schema:
-// "$ref": "#/definitions/accountRelationship"
-// '400':
-// description: bad request
-// '401':
-// description: unauthorized
-// '404':
-// description: not found
-// '406':
-// description: not acceptable
-// '500':
-// description: internal server error
-func (m *Module) FollowRequestRejectPOSTHandler(c *gin.Context) {
- authed, err := oauth.Authed(c, true, true, true, true)
- if err != nil {
- api.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet)
- return
- }
-
- if _, err := api.NegotiateAccept(c, api.JSONAcceptHeaders...); err != nil {
- api.ErrorHandler(c, gtserror.NewErrorNotAcceptable(err, err.Error()), m.processor.InstanceGet)
- return
- }
-
- originAccountID := c.Param(IDKey)
- if originAccountID == "" {
- err := errors.New("no account id specified")
- api.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGet)
- return
- }
-
- relationship, errWithCode := m.processor.FollowRequestReject(c.Request.Context(), authed, originAccountID)
- if errWithCode != nil {
- api.ErrorHandler(c, errWithCode, m.processor.InstanceGet)
- return
- }
-
- c.JSON(http.StatusOK, relationship)
-}
diff --git a/internal/api/client/followrequest/reject_test.go b/internal/api/client/followrequest/reject_test.go
deleted file mode 100644
index 94c646ddc..000000000
--- a/internal/api/client/followrequest/reject_test.go
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- GoToSocial
- Copyright (C) 2021-2022 GoToSocial Authors admin@gotosocial.org
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-package followrequest_test
-
-import (
- "context"
- "fmt"
- "io/ioutil"
- "net/http"
- "net/http/httptest"
- "testing"
- "time"
-
- "github.com/gin-gonic/gin"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/suite"
- "github.com/superseriousbusiness/gotosocial/internal/api/client/followrequest"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
-)
-
-type RejectTestSuite struct {
- FollowRequestStandardTestSuite
-}
-
-func (suite *RejectTestSuite) TestReject() {
- requestingAccount := suite.testAccounts["remote_account_2"]
- targetAccount := suite.testAccounts["local_account_1"]
-
- // put a follow request in the database
- fr := &gtsmodel.FollowRequest{
- ID: "01FJ1S8DX3STJJ6CEYPMZ1M0R3",
- CreatedAt: time.Now(),
- UpdatedAt: time.Now(),
- URI: fmt.Sprintf("%s/follow/01FJ1S8DX3STJJ6CEYPMZ1M0R3", requestingAccount.URI),
- AccountID: requestingAccount.ID,
- TargetAccountID: targetAccount.ID,
- }
-
- err := suite.db.Put(context.Background(), fr)
- suite.NoError(err)
-
- recorder := httptest.NewRecorder()
- ctx := suite.newContext(recorder, http.MethodPost, []byte{}, fmt.Sprintf("/api/v1/follow_requests/%s/reject", requestingAccount.ID), "")
-
- ctx.Params = gin.Params{
- gin.Param{
- Key: followrequest.IDKey,
- Value: requestingAccount.ID,
- },
- }
-
- // call the handler
- suite.followRequestModule.FollowRequestRejectPOSTHandler(ctx)
-
- // 1. we should have OK because our request was valid
- suite.Equal(http.StatusOK, recorder.Code)
-
- // 2. we should have no error message in the result body
- result := recorder.Result()
- defer result.Body.Close()
-
- // check the response
- b, err := ioutil.ReadAll(result.Body)
- assert.NoError(suite.T(), err)
-
- suite.Equal(`{"id":"01FHMQX3GAABWSM0S2VZEC2SWC","following":false,"showing_reblogs":false,"notifying":false,"followed_by":false,"blocking":false,"blocked_by":false,"muting":false,"muting_notifications":false,"requested":false,"domain_blocking":false,"endorsed":false,"note":""}`, string(b))
-}
-
-func TestRejectTestSuite(t *testing.T) {
- suite.Run(t, &RejectTestSuite{})
-}