This commit is contained in:
tsmethurst 2021-04-19 19:33:57 +02:00
commit 0775e51a36
8 changed files with 23 additions and 29 deletions

View file

@ -33,12 +33,8 @@ import (
) )
const ( const (
idKey = "id" basePath = "/api/v1/admin"
basePath = "/api/v1/admin" emojiPath = basePath + "/custom_emojis"
emojiPath = basePath + "/custom_emojis"
basePathWithID = basePath + "/:" + idKey
verifyPath = basePath + "/verify_credentials"
updateCredentialsPath = basePath + "/update_credentials"
) )
type adminModule struct { type adminModule struct {

View file

@ -32,11 +32,11 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
mediamodule "github.com/superseriousbusiness/gotosocial/internal/apimodule/media"
"github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db" "github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/db/gtsmodel"
"github.com/superseriousbusiness/gotosocial/internal/mastotypes" "github.com/superseriousbusiness/gotosocial/internal/mastotypes"
mediamodule "github.com/superseriousbusiness/gotosocial/internal/apimodule/media"
mastomodel "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel" mastomodel "github.com/superseriousbusiness/gotosocial/internal/mastotypes/mastomodel"
"github.com/superseriousbusiness/gotosocial/internal/media" "github.com/superseriousbusiness/gotosocial/internal/media"
"github.com/superseriousbusiness/gotosocial/internal/oauth" "github.com/superseriousbusiness/gotosocial/internal/oauth"

View file

@ -36,28 +36,28 @@ import (
) )
const ( const (
IDKey = "id" IDKey = "id"
BasePath = "/api/v1/statuses" BasePath = "/api/v1/statuses"
BasePathWithID = BasePath + "/:" + IDKey BasePathWithID = BasePath + "/:" + IDKey
ContextPath = BasePathWithID + "/context" ContextPath = BasePathWithID + "/context"
FavouritedPath = BasePathWithID + "/favourited_by" FavouritedPath = BasePathWithID + "/favourited_by"
FavouritePath = BasePathWithID + "/favourite" FavouritePath = BasePathWithID + "/favourite"
UnfavouritePath = BasePathWithID + "/unfavourite" UnfavouritePath = BasePathWithID + "/unfavourite"
RebloggedPath = BasePathWithID + "/reblogged_by" RebloggedPath = BasePathWithID + "/reblogged_by"
ReblogPath = BasePathWithID + "/reblog" ReblogPath = BasePathWithID + "/reblog"
UnreblogPath = BasePathWithID + "/unreblog" UnreblogPath = BasePathWithID + "/unreblog"
BookmarkPath = BasePathWithID + "/bookmark" BookmarkPath = BasePathWithID + "/bookmark"
UnbookmarkPath = BasePathWithID + "/unbookmark" UnbookmarkPath = BasePathWithID + "/unbookmark"
MutePath = BasePathWithID + "/mute" MutePath = BasePathWithID + "/mute"
UnmutePath = BasePathWithID + "/unmute" UnmutePath = BasePathWithID + "/unmute"
PinPath = BasePathWithID + "/pin" PinPath = BasePathWithID + "/pin"
UnpinPath = BasePathWithID + "/unpin" UnpinPath = BasePathWithID + "/unpin"
) )
type StatusModule struct { type StatusModule struct {
@ -89,7 +89,6 @@ func (m *StatusModule) Route(r router.Router) error {
r.AttachHandler(http.MethodPost, FavouritePath, m.StatusFavePOSTHandler) r.AttachHandler(http.MethodPost, FavouritePath, m.StatusFavePOSTHandler)
r.AttachHandler(http.MethodPost, UnfavouritePath, m.StatusFavePOSTHandler) r.AttachHandler(http.MethodPost, UnfavouritePath, m.StatusFavePOSTHandler)
r.AttachHandler(http.MethodGet, BasePathWithID, m.muxHandler) r.AttachHandler(http.MethodGet, BasePathWithID, m.muxHandler)
return nil return nil
} }

View file

@ -97,9 +97,9 @@ func (m *StatusModule) StatusDELETEHandler(c *gin.Context) {
} }
m.distributor.FromClientAPI() <- distributor.FromClientAPI{ m.distributor.FromClientAPI() <- distributor.FromClientAPI{
APObjectType: gtsmodel.ActivityStreamsNote, APObjectType: gtsmodel.ActivityStreamsNote,
APActivityType: gtsmodel.ActivityStreamsDelete, APActivityType: gtsmodel.ActivityStreamsDelete,
Activity: targetStatus, Activity: targetStatus,
} }
c.JSON(http.StatusOK, mastoStatus) c.JSON(http.StatusOK, mastoStatus)

View file

@ -94,7 +94,7 @@ func (m *StatusModule) StatusFavedByGETHandler(c *gin.Context) {
// get ALL accounts that faved a status -- doesn't take account of blocks and mutes and stuff // get ALL accounts that faved a status -- doesn't take account of blocks and mutes and stuff
favingAccounts, err := m.db.WhoFavedStatus(targetStatus) favingAccounts, err := m.db.WhoFavedStatus(targetStatus)
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error":err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
@ -103,7 +103,7 @@ func (m *StatusModule) StatusFavedByGETHandler(c *gin.Context) {
for _, acc := range favingAccounts { for _, acc := range favingAccounts {
blocked, err := m.db.Blocked(authed.Account.ID, acc.ID) blocked, err := m.db.Blocked(authed.Account.ID, acc.ID)
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error":err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
if !blocked { if !blocked {
@ -118,7 +118,7 @@ func (m *StatusModule) StatusFavedByGETHandler(c *gin.Context) {
for _, acc := range filteredAccounts { for _, acc := range filteredAccounts {
mastoAccount, err := m.mastoConverter.AccountToMastoPublic(acc) mastoAccount, err := m.mastoConverter.AccountToMastoPublic(acc)
if err != nil { if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error":err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
mastoAccounts = append(mastoAccounts, mastoAccount) mastoAccounts = append(mastoAccounts, mastoAccount)

View file

@ -122,7 +122,6 @@ func (suite *StatusFaveTestSuite) TestPostFave() {
t := suite.testTokens["local_account_1"] t := suite.testTokens["local_account_1"]
oauthToken := oauth.PGTokenToOauthToken(t) oauthToken := oauth.PGTokenToOauthToken(t)
targetStatus := suite.testStatuses["admin_account_status_2"] targetStatus := suite.testStatuses["admin_account_status_2"]
// setup // setup

View file

@ -655,7 +655,7 @@ func (ps *postgresService) StatusVisible(targetStatus *gtsmodel.Status, targetAc
// At this point we have a populated targetAccount, targetStatus, and requestingAccount, so we can check for blocks and whathaveyou // At this point we have a populated targetAccount, targetStatus, and requestingAccount, so we can check for blocks and whathaveyou
// First check if a block exists directly between the target account (which authored the status) and the requesting account. // First check if a block exists directly between the target account (which authored the status) and the requesting account.
if blocked, err := ps.Blocked(targetAccount.ID, requestingAccount.ID); err != nil { if blocked, err := ps.Blocked(targetAccount.ID, requestingAccount.ID); err != nil {
l.Debug("something went wrong figuring out if the accounts have a block: %s", err) l.Debugf("something went wrong figuring out if the accounts have a block: %s", err)
return false, err return false, err
} else if blocked { } else if blocked {
// don't allow the status to be viewed if a block exists in *either* direction between these two accounts, no creepy stalking please // don't allow the status to be viewed if a block exists in *either* direction between these two accounts, no creepy stalking please

View file

@ -507,7 +507,7 @@ func (c *converter) StatusToMasto(
} }
} }
var mastoCard *mastotypes.Card var mastoCard *mastotypes.Card
var mastoPoll *mastotypes.Poll var mastoPoll *mastotypes.Poll
return &mastotypes.Status{ return &mastotypes.Status{