summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorLibravatar Rob Sargant <robert@sargant.com>2022-11-14 09:30:01 +0000
committerLibravatar GitHub <noreply@github.com>2022-11-14 10:30:01 +0100
commitd120743e8bee74bbb6381a6ec017d7fa62b3f13e (patch)
tree166ab39f161b77cf6055abcc26de370c932c474f /internal
parent[chore]: Bump codeberg.org/gruf/go-cache/v3 from 3.1.7 to 3.1.8 (#1043) (diff)
downloadgotosocial-d120743e8bee74bbb6381a6ec017d7fa62b3f13e.tar.xz
[feature] add instance-expose-public-timeline flag (#1039)
* Add instance-expose-public-timeline flag Adds a config flag that allows unauthenticated access to /api/v1/timelines/public. Defaults to false to replicate existing behaviour. * Update structure following review * Add comment * Fix linting
Diffstat (limited to 'internal')
-rw-r--r--internal/api/client/timeline/public.go13
-rw-r--r--internal/config/config.go1
-rw-r--r--internal/config/helpers.gen.go25
-rw-r--r--internal/db/bundb/timeline.go2
-rw-r--r--internal/db/bundb/timeline_test.go8
-rw-r--r--internal/db/timeline.go2
-rw-r--r--internal/processing/statustimeline.go2
7 files changed, 43 insertions, 10 deletions
diff --git a/internal/api/client/timeline/public.go b/internal/api/client/timeline/public.go
index 673c20a99..a2e1faf59 100644
--- a/internal/api/client/timeline/public.go
+++ b/internal/api/client/timeline/public.go
@@ -25,6 +25,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/superseriousbusiness/gotosocial/internal/api"
+ "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
@@ -110,7 +111,17 @@ import (
// '400':
// description: bad request
func (m *Module) PublicTimelineGETHandler(c *gin.Context) {
- authed, err := oauth.Authed(c, true, true, true, true)
+ var authed *oauth.Auth
+ var err error
+
+ if config.GetInstanceExposePublicTimeline() {
+ // If the public timeline is allowed to be exposed, still check if we
+ // can extract various authentication properties, but don't require them.
+ authed, err = oauth.Authed(c, false, false, false, false)
+ } else {
+ authed, err = oauth.Authed(c, true, true, true, true)
+ }
+
if err != nil {
api.ErrorHandler(c, gtserror.NewErrorUnauthorized(err, err.Error()), m.processor.InstanceGet)
return
diff --git a/internal/config/config.go b/internal/config/config.go
index 907f250b0..ecbd079e6 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -71,6 +71,7 @@ type Configuration struct {
InstanceExposePeers bool `name:"instance-expose-peers" usage:"Allow unauthenticated users to query /api/v1/instance/peers?filter=open"`
InstanceExposeSuspended bool `name:"instance-expose-suspended" usage:"Expose suspended instances via web UI, and allow unauthenticated users to query /api/v1/instance/peers?filter=suspended"`
+ InstanceExposePublicTimeline bool `name:"instance-expose-public-timeline" usage:"Allow unauthenticated users to query /api/v1/timelines/public"`
InstanceDeliverToSharedInboxes bool `name:"instance-deliver-to-shared-inboxes" usage:"Deliver federated messages to shared inboxes, if they're available."`
AccountsRegistrationOpen bool `name:"accounts-registration-open" usage:"Allow anyone to submit an account signup request. If false, server will be invite-only."`
diff --git a/internal/config/helpers.gen.go b/internal/config/helpers.gen.go
index 1947fdadf..2786f5b5a 100644
--- a/internal/config/helpers.gen.go
+++ b/internal/config/helpers.gen.go
@@ -620,6 +620,31 @@ func GetInstanceExposeSuspended() bool { return global.GetInstanceExposeSuspende
// SetInstanceExposeSuspended safely sets the value for global configuration 'InstanceExposeSuspended' field
func SetInstanceExposeSuspended(v bool) { global.SetInstanceExposeSuspended(v) }
+// GetInstanceExposePublicTimeline safely fetches the Configuration value for state's 'InstanceExposePublicTimeline' field
+func (st *ConfigState) GetInstanceExposePublicTimeline() (v bool) {
+ st.mutex.Lock()
+ v = st.config.InstanceExposePublicTimeline
+ st.mutex.Unlock()
+ return
+}
+
+// SetInstanceExposePublicTimeline safely sets the Configuration value for state's 'InstanceExposePublicTimeline' field
+func (st *ConfigState) SetInstanceExposePublicTimeline(v bool) {
+ st.mutex.Lock()
+ defer st.mutex.Unlock()
+ st.config.InstanceExposePublicTimeline = v
+ st.reloadToViper()
+}
+
+// InstanceExposePublicTimelineFlag returns the flag name for the 'InstanceExposePublicTimeline' field
+func InstanceExposePublicTimelineFlag() string { return "instance-expose-public-timeline" }
+
+// GetInstanceExposePublicTimeline safely fetches the value for global configuration 'InstanceExposePublicTimeline' field
+func GetInstanceExposePublicTimeline() bool { return global.GetInstanceExposePublicTimeline() }
+
+// SetInstanceExposePublicTimeline safely sets the value for global configuration 'InstanceExposePublicTimeline' field
+func SetInstanceExposePublicTimeline(v bool) { global.SetInstanceExposePublicTimeline(v) }
+
// GetInstanceDeliverToSharedInboxes safely fetches the Configuration value for state's 'InstanceDeliverToSharedInboxes' field
func (st *ConfigState) GetInstanceDeliverToSharedInboxes() (v bool) {
st.mutex.Lock()
diff --git a/internal/db/bundb/timeline.go b/internal/db/bundb/timeline.go
index 35b754d73..d15c07e9c 100644
--- a/internal/db/bundb/timeline.go
+++ b/internal/db/bundb/timeline.go
@@ -124,7 +124,7 @@ func (t *timelineDB) GetHomeTimeline(ctx context.Context, accountID string, maxI
return statuses, nil
}
-func (t *timelineDB) GetPublicTimeline(ctx context.Context, accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, db.Error) {
+func (t *timelineDB) GetPublicTimeline(ctx context.Context, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, db.Error) {
// Ensure reasonable
if limit < 0 {
limit = 0
diff --git a/internal/db/bundb/timeline_test.go b/internal/db/bundb/timeline_test.go
index 8822879dd..9b6365621 100644
--- a/internal/db/bundb/timeline_test.go
+++ b/internal/db/bundb/timeline_test.go
@@ -35,23 +35,19 @@ type TimelineTestSuite struct {
}
func (suite *TimelineTestSuite) TestGetPublicTimeline() {
- viewingAccount := suite.testAccounts["local_account_1"]
-
- s, err := suite.db.GetPublicTimeline(context.Background(), viewingAccount.ID, "", "", "", 20, false)
+ s, err := suite.db.GetPublicTimeline(context.Background(), "", "", "", 20, false)
suite.NoError(err)
suite.Len(s, 6)
}
func (suite *TimelineTestSuite) TestGetPublicTimelineWithFutureStatus() {
- viewingAccount := suite.testAccounts["local_account_1"]
-
futureStatus := getFutureStatus()
if err := suite.db.Put(context.Background(), futureStatus); err != nil {
suite.FailNow(err.Error())
}
- s, err := suite.db.GetPublicTimeline(context.Background(), viewingAccount.ID, "", "", "", 20, false)
+ s, err := suite.db.GetPublicTimeline(context.Background(), "", "", "", 20, false)
suite.NoError(err)
suite.Len(s, 6)
diff --git a/internal/db/timeline.go b/internal/db/timeline.go
index 58b5b3a21..27f89d997 100644
--- a/internal/db/timeline.go
+++ b/internal/db/timeline.go
@@ -35,7 +35,7 @@ type Timeline interface {
// It will use the given filters and try to return as many statuses as possible up to the limit.
//
// Statuses should be returned in descending order of when they were created (newest first).
- GetPublicTimeline(ctx context.Context, accountID string, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, Error)
+ GetPublicTimeline(ctx context.Context, maxID string, sinceID string, minID string, limit int, local bool) ([]*gtsmodel.Status, Error)
// GetFavedTimeline fetches the account's FAVED timeline -- ie., posts and replies that the requesting account has faved.
// It will use the given filters and try to return as many statuses as possible up to the limit.
diff --git a/internal/processing/statustimeline.go b/internal/processing/statustimeline.go
index 4491308f3..4600844f5 100644
--- a/internal/processing/statustimeline.go
+++ b/internal/processing/statustimeline.go
@@ -173,7 +173,7 @@ func (p *processor) HomeTimelineGet(ctx context.Context, authed *oauth.Auth, max
}
func (p *processor) PublicTimelineGet(ctx context.Context, authed *oauth.Auth, maxID string, sinceID string, minID string, limit int, local bool) (*apimodel.PageableResponse, gtserror.WithCode) {
- statuses, err := p.db.GetPublicTimeline(ctx, authed.Account.ID, maxID, sinceID, minID, limit, local)
+ statuses, err := p.db.GetPublicTimeline(ctx, maxID, sinceID, minID, limit, local)
if err != nil {
if err == db.ErrNoEntries {
// there are just no entries left