diff --git a/models/activities/action.go b/models/activities/action.go index bedcaf789e..fc6f7d8dcc 100644 --- a/models/activities/action.go +++ b/models/activities/action.go @@ -487,14 +487,17 @@ func activityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder. if opts.Actor == nil { cond = cond.And(builder.In("act_user_id", builder.Select("`user`.id").Where( - builder.Eq{"keep_activity_private": false, "visibility": structs.VisibleTypePublic}, + builder.Eq{"visibility": structs.VisibleTypePublic}, + ).Where( + builder.Neq{"actions_visibility": structs.ActionsVisibilityNone}, ).From("`user`"), )) } else if !opts.Actor.IsAdmin { uidCond := builder.Select("`user`.id").From("`user`").Where( - builder.Eq{"keep_activity_private": false}. - And(builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited))). - Or(builder.Eq{"id": opts.Actor.ID}) + builder.Neq{"actions_visibility": structs.ActionsVisibilityNone}, + ).Where( + builder.In("visibility", structs.VisibleTypePublic, structs.VisibleTypeLimited), + ).Or(builder.Eq{"id": opts.Actor.ID}) if opts.RequestedUser != nil { if opts.RequestedUser.IsOrganization() { diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go index beb1f3bb96..5c13481fad 100644 --- a/models/migrations/migrations.go +++ b/models/migrations/migrations.go @@ -558,6 +558,8 @@ var migrations = []Migration{ NewMigration("Add PreviousDuration to ActionRun", v1_22.AddPreviousDurationToActionRun), // v286 -> v287 NewMigration("Add support for SHA256 git repositories", v1_22.AdjustDBForSha256), + // v287 -> v288 + NewMigration("Add change KeepActivityPrivate to AddActionsVisibility", v1_22.AddActionsVisibility), } // GetCurrentDBVersion returns the current db version diff --git a/models/migrations/v1_22/v287.go b/models/migrations/v1_22/v287.go new file mode 100644 index 0000000000..c6a331a169 --- /dev/null +++ b/models/migrations/v1_22/v287.go @@ -0,0 +1,36 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package v1_22 //nolint + +import ( + "code.gitea.io/gitea/models/migrations/base" + "code.gitea.io/gitea/modules/structs" + + "code.gitea.io/gitea/models/user" + + "xorm.io/builder" + "xorm.io/xorm" +) + +func AddActionsVisibility(x *xorm.Engine) error { + sess := x.NewSession() + defer sess.Close() + + if err := sess.Begin(); err != nil { + return err + } + + if _, err := sess. + Where(builder.Eq{"keep_activity_private": 1}). + Cols("actions_visibility"). + Update(user.User{ActionsVisibility: structs.ActionsVisibilityNone}); err != nil { + return err + } + + if err := base.DropTableColumns(sess, "user", "keep_activity_private"); err != nil { + return err + } + + return sess.Commit() +}