diff options
author | Gusted <postmaster@gusted.xyz> | 2025-01-24 05:16:56 +0100 |
---|---|---|
committer | Gusted <gusted@noreply.codeberg.org> | 2025-01-24 05:16:56 +0100 |
commit | a9c97110f9da75776d6f9f86adcca712367fb052 (patch) | |
tree | 63622738e22357587e988f7738ebd56c8d64ccfa /models/forgejo_migrations | |
parent | Update module google.golang.org/grpc to v1.69.4 (forgejo) (#6560) (diff) | |
download | forgejo-a9c97110f9da75776d6f9f86adcca712367fb052.tar.xz forgejo-a9c97110f9da75776d6f9f86adcca712367fb052.zip |
feat: add configurable cooldown to claim usernames (#6422)
Add a new option that allows instances to set a cooldown period to claim
old usernames. In the context of public instances this can be used to
prevent old usernames to be claimed after they are free and allow
graceful migration (by making use of the redirect feature) to a new
username. The granularity of this cooldown is a day. By default this
feature is disabled and thus no cooldown period.
The `CreatedUnix` column is added the `user_redirect` table, for
existing redirects the timestamp is simply zero as we simply do not know
when they were created and are likely already over the cooldown period
if the instance configures one.
Users can always reclaim their 'old' user name again within the cooldown
period. Users can also always reclaim 'old' names of organization they
currently own within the cooldown period.
Creating and renaming users as an admin user are not affected by the
cooldown period for moderation and user support reasons.
To avoid abuse of the cooldown feature, such that a user holds a lot of
usernames, a new option is added `MAX_USER_REDIRECTS` which sets a limit
to the amount of user redirects a user may have, by default this is
disabled. If a cooldown period is set then the default is 5. This
feature operates independently of the cooldown period feature.
Added integration and unit testing.
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6422
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
Reviewed-by: Otto <otto@codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
Diffstat (limited to 'models/forgejo_migrations')
-rw-r--r-- | models/forgejo_migrations/migrate.go | 2 | ||||
-rw-r--r-- | models/forgejo_migrations/v27.go | 18 |
2 files changed, 20 insertions, 0 deletions
diff --git a/models/forgejo_migrations/migrate.go b/models/forgejo_migrations/migrate.go index 3bf7843211..1450ad3c54 100644 --- a/models/forgejo_migrations/migrate.go +++ b/models/forgejo_migrations/migrate.go @@ -90,6 +90,8 @@ var migrations = []*Migration{ NewMigration("Migrate `secret` column to store keying material", MigrateTwoFactorToKeying), // v26 -> v27 NewMigration("Add `hash_blake2b` column to `package_blob` table", AddHashBlake2bToPackageBlob), + // v27 -> v28 + NewMigration("Add `created_unix` column to `user_redirect` table", AddCreatedUnixToRedirect), } // GetCurrentDBVersion returns the current Forgejo database version. diff --git a/models/forgejo_migrations/v27.go b/models/forgejo_migrations/v27.go new file mode 100644 index 0000000000..b3a93a9aad --- /dev/null +++ b/models/forgejo_migrations/v27.go @@ -0,0 +1,18 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: GPL-3.0-or-later + +package forgejo_migrations //nolint:revive + +import ( + "code.gitea.io/gitea/modules/timeutil" + + "xorm.io/xorm" +) + +func AddCreatedUnixToRedirect(x *xorm.Engine) error { + type UserRedirect struct { + ID int64 `xorm:"pk autoincr"` + CreatedUnix timeutil.TimeStamp `xorm:"created NOT NULL DEFAULT 0"` + } + return x.Sync(new(UserRedirect)) +} |