mirror of
https://github.com/gogs/gogs.git
synced 2026-05-07 02:17:04 +02:00
all: unwrap database.UsersStore interface (#7708)
This commit is contained in:
@@ -39,7 +39,7 @@ func CreateUser(c *context.APIContext, form api.CreateUserOption) {
|
||||
return
|
||||
}
|
||||
|
||||
user, err := database.Users.Create(
|
||||
user, err := database.Handle.Users().Create(
|
||||
c.Req.Context(),
|
||||
form.Username,
|
||||
form.Email,
|
||||
@@ -104,7 +104,7 @@ func EditUser(c *context.APIContext, form api.EditUserOption) {
|
||||
opts.Email = &form.Email
|
||||
}
|
||||
|
||||
err := database.Users.Update(c.Req.Context(), u.ID, opts)
|
||||
err := database.Handle.Users().Update(c.Req.Context(), u.ID, opts)
|
||||
if err != nil {
|
||||
if database.IsErrEmailAlreadyUsed(err) {
|
||||
c.ErrorStatus(http.StatusUnprocessableEntity, err)
|
||||
@@ -115,7 +115,7 @@ func EditUser(c *context.APIContext, form api.EditUserOption) {
|
||||
}
|
||||
log.Trace("Account updated by admin %q: %s", c.User.Name, u.Name)
|
||||
|
||||
u, err = database.Users.GetByID(c.Req.Context(), u.ID)
|
||||
u, err = database.Handle.Users().GetByID(c.Req.Context(), u.ID)
|
||||
if err != nil {
|
||||
c.Error(err, "get user")
|
||||
return
|
||||
@@ -129,7 +129,7 @@ func DeleteUser(c *context.APIContext) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := database.Users.DeleteByID(c.Req.Context(), u.ID, false); err != nil {
|
||||
if err := database.Handle.Users().DeleteByID(c.Req.Context(), u.ID, false); err != nil {
|
||||
if database.IsErrUserOwnRepos(err) ||
|
||||
database.IsErrUserHasOrgs(err) {
|
||||
c.ErrorStatus(http.StatusUnprocessableEntity, err)
|
||||
|
||||
@@ -37,7 +37,7 @@ func repoAssignment() macaron.Handler {
|
||||
if c.IsLogged && c.User.LowerName == strings.ToLower(username) {
|
||||
owner = c.User
|
||||
} else {
|
||||
owner, err = database.Users.GetByUsername(c.Req.Context(), username)
|
||||
owner, err = database.Handle.Users().GetByUsername(c.Req.Context(), username)
|
||||
if err != nil {
|
||||
c.NotFoundOrError(err, "get user by name")
|
||||
return
|
||||
@@ -91,7 +91,7 @@ func orgAssignment(args ...bool) macaron.Handler {
|
||||
|
||||
var err error
|
||||
if assignOrg {
|
||||
c.Org.Organization, err = database.Users.GetByUsername(c.Req.Context(), c.Params(":orgname"))
|
||||
c.Org.Organization, err = database.Handle.Users().GetByUsername(c.Req.Context(), c.Params(":orgname"))
|
||||
if err != nil {
|
||||
c.NotFoundOrError(err, "get organization by name")
|
||||
return
|
||||
|
||||
@@ -45,12 +45,12 @@ func ToTag(b *database.Tag, c *git.Commit) *Tag {
|
||||
|
||||
func ToCommit(c *git.Commit) *api.PayloadCommit {
|
||||
authorUsername := ""
|
||||
author, err := database.Users.GetByEmail(context.TODO(), c.Author.Email)
|
||||
author, err := database.Handle.Users().GetByEmail(context.TODO(), c.Author.Email)
|
||||
if err == nil {
|
||||
authorUsername = author.Name
|
||||
}
|
||||
committerUsername := ""
|
||||
committer, err := database.Users.GetByEmail(context.TODO(), c.Committer.Email)
|
||||
committer, err := database.Handle.Users().GetByEmail(context.TODO(), c.Committer.Email)
|
||||
if err == nil {
|
||||
committerUsername = committer.Name
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ func Edit(c *context.APIContext, form api.EditOrgOption) {
|
||||
return
|
||||
}
|
||||
|
||||
err := database.Users.Update(
|
||||
err := database.Handle.Users().Update(
|
||||
c.Req.Context(),
|
||||
c.Org.Organization.ID,
|
||||
database.UpdateUserOptions{
|
||||
|
||||
@@ -28,7 +28,7 @@ func ListCollaborators(c *context.APIContext) {
|
||||
}
|
||||
|
||||
func AddCollaborator(c *context.APIContext, form api.AddCollaboratorOption) {
|
||||
collaborator, err := database.Users.GetByUsername(c.Req.Context(), c.Params(":collaborator"))
|
||||
collaborator, err := database.Handle.Users().GetByUsername(c.Req.Context(), c.Params(":collaborator"))
|
||||
if err != nil {
|
||||
if database.IsErrUserNotExist(err) {
|
||||
c.Status(http.StatusUnprocessableEntity)
|
||||
@@ -54,7 +54,7 @@ func AddCollaborator(c *context.APIContext, form api.AddCollaboratorOption) {
|
||||
}
|
||||
|
||||
func IsCollaborator(c *context.APIContext) {
|
||||
collaborator, err := database.Users.GetByUsername(c.Req.Context(), c.Params(":collaborator"))
|
||||
collaborator, err := database.Handle.Users().GetByUsername(c.Req.Context(), c.Params(":collaborator"))
|
||||
if err != nil {
|
||||
if database.IsErrUserNotExist(err) {
|
||||
c.Status(http.StatusUnprocessableEntity)
|
||||
@@ -72,7 +72,7 @@ func IsCollaborator(c *context.APIContext) {
|
||||
}
|
||||
|
||||
func DeleteCollaborator(c *context.APIContext) {
|
||||
collaborator, err := database.Users.GetByUsername(c.Req.Context(), c.Params(":collaborator"))
|
||||
collaborator, err := database.Handle.Users().GetByUsername(c.Req.Context(), c.Params(":collaborator"))
|
||||
if err != nil {
|
||||
if database.IsErrUserNotExist(err) {
|
||||
c.Status(http.StatusUnprocessableEntity)
|
||||
|
||||
@@ -120,7 +120,7 @@ func GetReferenceSHA(c *context.APIContext) {
|
||||
func gitCommitToAPICommit(commit *git.Commit, c *context.APIContext) (*api.Commit, error) {
|
||||
// Retrieve author and committer information
|
||||
var apiAuthor, apiCommitter *api.User
|
||||
author, err := database.Users.GetByEmail(c.Req.Context(), commit.Author.Email)
|
||||
author, err := database.Handle.Users().GetByEmail(c.Req.Context(), commit.Author.Email)
|
||||
if err != nil && !database.IsErrUserNotExist(err) {
|
||||
return nil, err
|
||||
} else if err == nil {
|
||||
@@ -131,7 +131,7 @@ func gitCommitToAPICommit(commit *git.Commit, c *context.APIContext) (*api.Commi
|
||||
if commit.Committer.Email == commit.Author.Email {
|
||||
apiCommitter = apiAuthor
|
||||
} else {
|
||||
committer, err := database.Users.GetByEmail(c.Req.Context(), commit.Committer.Email)
|
||||
committer, err := database.Handle.Users().GetByEmail(c.Req.Context(), commit.Committer.Email)
|
||||
if err != nil && !database.IsErrUserNotExist(err) {
|
||||
return nil, err
|
||||
} else if err == nil {
|
||||
|
||||
@@ -83,7 +83,7 @@ func CreateIssue(c *context.APIContext, form api.CreateIssueOption) {
|
||||
|
||||
if c.Repo.IsWriter() {
|
||||
if len(form.Assignee) > 0 {
|
||||
assignee, err := database.Users.GetByUsername(c.Req.Context(), form.Assignee)
|
||||
assignee, err := database.Handle.Users().GetByUsername(c.Req.Context(), form.Assignee)
|
||||
if err != nil {
|
||||
if database.IsErrUserNotExist(err) {
|
||||
c.ErrorStatus(http.StatusUnprocessableEntity, fmt.Errorf("assignee does not exist: [name: %s]", form.Assignee))
|
||||
@@ -145,7 +145,7 @@ func EditIssue(c *context.APIContext, form api.EditIssueOption) {
|
||||
if *form.Assignee == "" {
|
||||
issue.AssigneeID = 0
|
||||
} else {
|
||||
assignee, err := database.Users.GetByUsername(c.Req.Context(), *form.Assignee)
|
||||
assignee, err := database.Handle.Users().GetByUsername(c.Req.Context(), *form.Assignee)
|
||||
if err != nil {
|
||||
if database.IsErrUserNotExist(err) {
|
||||
c.ErrorStatus(http.StatusUnprocessableEntity, fmt.Errorf("assignee does not exist: [name: %s]", *form.Assignee))
|
||||
|
||||
@@ -32,7 +32,7 @@ func Search(c *context.APIContext) {
|
||||
if c.User.ID == opts.OwnerID {
|
||||
opts.Private = true
|
||||
} else {
|
||||
u, err := database.Users.GetByID(c.Req.Context(), opts.OwnerID)
|
||||
u, err := database.Handle.Users().GetByID(c.Req.Context(), opts.OwnerID)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, map[string]any{
|
||||
"ok": false,
|
||||
@@ -77,7 +77,7 @@ func Search(c *context.APIContext) {
|
||||
}
|
||||
|
||||
func listUserRepositories(c *context.APIContext, username string) {
|
||||
user, err := database.Users.GetByUsername(c.Req.Context(), username)
|
||||
user, err := database.Handle.Users().GetByUsername(c.Req.Context(), username)
|
||||
if err != nil {
|
||||
c.NotFoundOrError(err, "get user by name")
|
||||
return
|
||||
@@ -209,7 +209,7 @@ func Migrate(c *context.APIContext, f form.MigrateRepo) {
|
||||
// Not equal means context user is an organization,
|
||||
// or is another user/organization if current user is admin.
|
||||
if f.Uid != ctxUser.ID {
|
||||
org, err := database.Users.GetByID(c.Req.Context(), f.Uid)
|
||||
org, err := database.Handle.Users().GetByID(c.Req.Context(), f.Uid)
|
||||
if err != nil {
|
||||
if database.IsErrUserNotExist(err) {
|
||||
c.ErrorStatus(http.StatusUnprocessableEntity, err)
|
||||
@@ -287,7 +287,7 @@ func Migrate(c *context.APIContext, f form.MigrateRepo) {
|
||||
|
||||
// FIXME: inject in the handler chain
|
||||
func parseOwnerAndRepo(c *context.APIContext) (*database.User, *database.Repository) {
|
||||
owner, err := database.Users.GetByUsername(c.Req.Context(), c.Params(":username"))
|
||||
owner, err := database.Handle.Users().GetByUsername(c.Req.Context(), c.Params(":username"))
|
||||
if err != nil {
|
||||
if database.IsErrUserNotExist(err) {
|
||||
c.ErrorStatus(http.StatusUnprocessableEntity, err)
|
||||
@@ -453,7 +453,7 @@ func Releases(c *context.APIContext) {
|
||||
}
|
||||
apiReleases := make([]*api.Release, 0, len(releases))
|
||||
for _, r := range releases {
|
||||
publisher, err := database.Users.GetByID(c.Req.Context(), r.PublisherID)
|
||||
publisher, err := database.Handle.Users().GetByID(c.Req.Context(), r.PublisherID)
|
||||
if err != nil {
|
||||
c.Error(err, "get release publisher")
|
||||
return
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
func ListEmails(c *context.APIContext) {
|
||||
emails, err := database.Users.ListEmails(c.Req.Context(), c.User.ID)
|
||||
emails, err := database.Handle.Users().ListEmails(c.Req.Context(), c.User.ID)
|
||||
if err != nil {
|
||||
c.Error(err, "get email addresses")
|
||||
return
|
||||
@@ -37,7 +37,7 @@ func AddEmail(c *context.APIContext, form api.CreateEmailOption) {
|
||||
|
||||
apiEmails := make([]*api.Email, 0, len(form.Emails))
|
||||
for _, email := range form.Emails {
|
||||
err := database.Users.AddEmail(c.Req.Context(), c.User.ID, email, !conf.Auth.RequireEmailConfirmation)
|
||||
err := database.Handle.Users().AddEmail(c.Req.Context(), c.User.ID, email, !conf.Auth.RequireEmailConfirmation)
|
||||
if err != nil {
|
||||
if database.IsErrEmailAlreadyUsed(err) {
|
||||
c.ErrorStatus(http.StatusUnprocessableEntity, errors.Errorf("email address has been used: %s", err.(database.ErrEmailAlreadyUsed).Email()))
|
||||
@@ -64,7 +64,7 @@ func DeleteEmail(c *context.APIContext, form api.CreateEmailOption) {
|
||||
return
|
||||
}
|
||||
|
||||
err := database.Users.DeleteEmail(c.Req.Context(), c.User.ID, email)
|
||||
err := database.Handle.Users().DeleteEmail(c.Req.Context(), c.User.ID, email)
|
||||
if err != nil {
|
||||
c.Error(err, "delete email addresses")
|
||||
return
|
||||
|
||||
@@ -20,7 +20,7 @@ func responseApiUsers(c *context.APIContext, users []*database.User) {
|
||||
}
|
||||
|
||||
func listUserFollowers(c *context.APIContext, u *database.User) {
|
||||
users, err := database.Users.ListFollowers(c.Req.Context(), u.ID, c.QueryInt("page"), database.ItemsPerPage)
|
||||
users, err := database.Handle.Users().ListFollowers(c.Req.Context(), u.ID, c.QueryInt("page"), database.ItemsPerPage)
|
||||
if err != nil {
|
||||
c.Error(err, "list followers")
|
||||
return
|
||||
@@ -41,7 +41,7 @@ func ListFollowers(c *context.APIContext) {
|
||||
}
|
||||
|
||||
func listUserFollowing(c *context.APIContext, u *database.User) {
|
||||
users, err := database.Users.ListFollowings(c.Req.Context(), u.ID, c.QueryInt("page"), database.ItemsPerPage)
|
||||
users, err := database.Handle.Users().ListFollowings(c.Req.Context(), u.ID, c.QueryInt("page"), database.ItemsPerPage)
|
||||
if err != nil {
|
||||
c.Error(err, "list followings")
|
||||
return
|
||||
@@ -62,7 +62,7 @@ func ListFollowing(c *context.APIContext) {
|
||||
}
|
||||
|
||||
func checkUserFollowing(c *context.APIContext, u *database.User, followID int64) {
|
||||
if database.Users.IsFollowing(c.Req.Context(), u.ID, followID) {
|
||||
if database.Handle.Users().IsFollowing(c.Req.Context(), u.ID, followID) {
|
||||
c.NoContent()
|
||||
} else {
|
||||
c.NotFound()
|
||||
@@ -94,7 +94,7 @@ func Follow(c *context.APIContext) {
|
||||
if c.Written() {
|
||||
return
|
||||
}
|
||||
if err := database.Users.Follow(c.Req.Context(), c.User.ID, target.ID); err != nil {
|
||||
if err := database.Handle.Users().Follow(c.Req.Context(), c.User.ID, target.ID); err != nil {
|
||||
c.Error(err, "follow user")
|
||||
return
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func Unfollow(c *context.APIContext) {
|
||||
if c.Written() {
|
||||
return
|
||||
}
|
||||
if err := database.Users.Unfollow(c.Req.Context(), c.User.ID, target.ID); err != nil {
|
||||
if err := database.Handle.Users().Unfollow(c.Req.Context(), c.User.ID, target.ID); err != nil {
|
||||
c.Error(err, "unfollow user")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func GetUserByParamsName(c *context.APIContext, name string) *database.User {
|
||||
user, err := database.Users.GetByUsername(c.Req.Context(), c.Params(name))
|
||||
user, err := database.Handle.Users().GetByUsername(c.Req.Context(), c.Params(name))
|
||||
if err != nil {
|
||||
c.NotFoundOrError(err, "get user by name")
|
||||
return nil
|
||||
|
||||
@@ -19,7 +19,7 @@ func Search(c *context.APIContext) {
|
||||
if pageSize <= 0 {
|
||||
pageSize = 10
|
||||
}
|
||||
users, _, err := database.Users.SearchByName(c.Req.Context(), c.Query("q"), 1, pageSize, "")
|
||||
users, _, err := database.Handle.Users().SearchByName(c.Req.Context(), c.Query("q"), 1, pageSize, "")
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, map[string]any{
|
||||
"ok": false,
|
||||
@@ -48,7 +48,7 @@ func Search(c *context.APIContext) {
|
||||
}
|
||||
|
||||
func GetInfo(c *context.APIContext) {
|
||||
u, err := database.Users.GetByUsername(c.Req.Context(), c.Params(":username"))
|
||||
u, err := database.Handle.Users().GetByUsername(c.Req.Context(), c.Params(":username"))
|
||||
if err != nil {
|
||||
c.NotFoundOrError(err, "get user by name")
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user