Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User creation API: allow custom "created" timestamps #22549

Merged
merged 17 commits into from
Feb 16, 2023

Commits on Jan 20, 2023

  1. User creation API: allow custom "created" timestamps

    Allow back-dating user creation via the `adminCreateUser` API operation.
    `CreateUserOption` now has an optional field `created_at`, which can
    contain a datetime-formatted string. If this field is present, the user's
    `created_unix` database field will be updated to its value.
    
    This is important for Blender's migration of users from Phabricator to
    Gitea. There are many users, and the creation timestamp of their account
    can give us some indication as to how long someone's been part of the
    community.
    
    The back-dating is done in a separate query that just updates the user's
    `created_unix` field. This was the easiest and cleanest way I could find,
    as in the initial `INSERT` query the field always is set to "now".
    drsybren committed Jan 20, 2023
    Configuration menu
    Copy the full SHA
    e9858cf View commit details
    Browse the repository at this point in the history
  2. Regenerate swagger & update field description

    Run `make generate-swagger` and update the comment describing the field
    so that they make sense from an API standpoint (and not just when reading
    the Go code).
    drsybren committed Jan 20, 2023
    Configuration menu
    Copy the full SHA
    a7633f3 View commit details
    Browse the repository at this point in the history

Commits on Jan 23, 2023

  1. Remove double space from SQL

    Thanks @yardenshoham for spotting this.
    
    Co-authored-by: Yarden Shoham <hrsi88@gmail.com>
    drsybren and yardenshoham authored Jan 23, 2023
    Configuration menu
    Copy the full SHA
    036b16d View commit details
    Browse the repository at this point in the history
  2. Update comments, avoid mentioning back-dating.

    Since any timestamp is accepted by the system, avoid mentioning
    "back-dating" user creation.
    drsybren committed Jan 23, 2023
    Configuration menu
    Copy the full SHA
    4831ec6 View commit details
    Browse the repository at this point in the history
  3. Run make generate-swagger

    drsybren committed Jan 23, 2023
    Configuration menu
    Copy the full SHA
    ce97999 View commit details
    Browse the repository at this point in the history
  4. Use NoAutoTime() to allow manual changes to creation timestamp

    With this change to the "insert" query, it was possible to set the creation
    timestamp:
    
    ```diff
    @@ -740,11 +747,11 @@ func CreateUser(u *User, overwriteDefault ...*CreateUserOverwriteOptions) (err e
    
     	if err = DeleteUserRedirect(ctx, u.Name); err != nil {
     		return err
     	}
    
    -	if err = db.Insert(ctx, u); err != nil {
    +	if _, err = db.GetEngine(ctx).NoAutoTime().Insert(u); err != nil {
     		return err
     	}
    
     	// insert email address
     	if err := db.Insert(ctx, &EmailAddress{
    ```
    drsybren committed Jan 23, 2023
    Configuration menu
    Copy the full SHA
    256dcf5 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    fcc33fe View commit details
    Browse the repository at this point in the history

Commits on Jan 24, 2023

  1. Detect whether NoAutoTime() should be used + a unittest

    Detect whether `NoAutoTime()` should be used based on `u.CreatedUnix`,
    and add two unittests that test the new functionality.
    drsybren committed Jan 24, 2023
    Configuration menu
    Copy the full SHA
    7e0b525 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    e48c075 View commit details
    Browse the repository at this point in the history

Commits on Jan 27, 2023

  1. Use "fake now" in unit test

    Suggestion by @wolfogre
    
    Co-authored-by: Jason Song <i@wolfogre.com>
    drsybren and wolfogre authored Jan 27, 2023
    Configuration menu
    Copy the full SHA
    6fd9f18 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    5d22df3 View commit details
    Browse the repository at this point in the history

Commits on Feb 10, 2023

  1. Configuration menu
    Copy the full SHA
    205d0f1 View commit details
    Browse the repository at this point in the history

Commits on Feb 13, 2023

  1. Handle reviewer feedback

    drsybren committed Feb 13, 2023
    Configuration menu
    Copy the full SHA
    f2bd162 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    931744f View commit details
    Browse the repository at this point in the history

Commits on Feb 14, 2023

  1. Configuration menu
    Copy the full SHA
    9354d5c View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    25b6aef View commit details
    Browse the repository at this point in the history

Commits on Feb 16, 2023

  1. Configuration menu
    Copy the full SHA
    3732233 View commit details
    Browse the repository at this point in the history