migration

This commit is contained in:
Tim-Niclas Oelschläger 2024-02-22 03:58:18 +01:00
parent d1e3a6ce77
commit 18e74749ab
No known key found for this signature in database
3 changed files with 45 additions and 4 deletions

View File

@ -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() {

View File

@ -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

View File

@ -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()
}