mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-01 04:12:10 +00:00
[refactor] Unify the export of user data via API (#15144)
* [refactor] unify how user data is exported via API * test time via unix timestamp
This commit is contained in:
parent
f4d27498bd
commit
290cf75f93
26 changed files with 117 additions and 97 deletions
|
@ -116,7 +116,7 @@ func CreateUser(ctx *context.APIContext) {
|
|||
if form.SendNotify {
|
||||
mailer.SendRegisterNotifyMail(ctx.Locale, u)
|
||||
}
|
||||
ctx.JSON(http.StatusCreated, convert.ToUser(u, ctx.IsSigned, ctx.User.IsAdmin))
|
||||
ctx.JSON(http.StatusCreated, convert.ToUser(u, ctx.User))
|
||||
}
|
||||
|
||||
// EditUser api for modifying a user's information
|
||||
|
@ -238,7 +238,7 @@ func EditUser(ctx *context.APIContext) {
|
|||
}
|
||||
log.Trace("Account profile updated by admin (%s): %s", ctx.User.Name, u.Name)
|
||||
|
||||
ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.IsSigned, ctx.User.IsAdmin))
|
||||
ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.User))
|
||||
}
|
||||
|
||||
// DeleteUser api for deleting a user
|
||||
|
@ -403,7 +403,7 @@ func GetAllUsers(ctx *context.APIContext) {
|
|||
|
||||
results := make([]*api.User, len(users))
|
||||
for i := range users {
|
||||
results[i] = convert.ToUser(users[i], ctx.IsSigned, ctx.User.IsAdmin)
|
||||
results[i] = convert.ToUser(users[i], ctx.User)
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
|
||||
|
|
|
@ -32,7 +32,7 @@ func listMembers(ctx *context.APIContext, publicOnly bool) {
|
|||
|
||||
apiMembers := make([]*api.User, len(members))
|
||||
for i, member := range members {
|
||||
apiMembers[i] = convert.ToUser(member, ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
|
||||
apiMembers[i] = convert.ToUser(member, ctx.User)
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, apiMembers)
|
||||
|
|
|
@ -337,7 +337,7 @@ func GetTeamMembers(ctx *context.APIContext) {
|
|||
}
|
||||
members := make([]*api.User, len(team.Members))
|
||||
for i, member := range team.Members {
|
||||
members[i] = convert.ToUser(member, ctx.IsSigned, ctx.User.IsAdmin)
|
||||
members[i] = convert.ToUser(member, ctx.User)
|
||||
}
|
||||
ctx.JSON(http.StatusOK, members)
|
||||
}
|
||||
|
@ -380,7 +380,7 @@ func GetTeamMember(ctx *context.APIContext) {
|
|||
ctx.NotFound()
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.IsSigned, ctx.User.IsAdmin))
|
||||
ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.User))
|
||||
}
|
||||
|
||||
// AddTeamMember api for add a member to a team
|
||||
|
|
|
@ -54,7 +54,7 @@ func ListCollaborators(ctx *context.APIContext) {
|
|||
}
|
||||
users := make([]*api.User, len(collaborators))
|
||||
for i, collaborator := range collaborators {
|
||||
users[i] = convert.ToUser(collaborator.User, ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
|
||||
users[i] = convert.ToUser(collaborator.User, ctx.User)
|
||||
}
|
||||
ctx.JSON(http.StatusOK, users)
|
||||
}
|
||||
|
|
|
@ -148,8 +148,8 @@ func TestHook(ctx *context.APIContext) {
|
|||
convert.ToPayloadCommit(ctx.Repo.Repository, ctx.Repo.Commit),
|
||||
},
|
||||
Repo: convert.ToRepo(ctx.Repo.Repository, models.AccessModeNone),
|
||||
Pusher: convert.ToUser(ctx.User, ctx.IsSigned, false),
|
||||
Sender: convert.ToUser(ctx.User, ctx.IsSigned, false),
|
||||
Pusher: convert.ToUserWithAccessMode(ctx.User, models.AccessModeNone),
|
||||
Sender: convert.ToUserWithAccessMode(ctx.User, models.AccessModeNone),
|
||||
}); err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "PrepareWebhook: ", err)
|
||||
return
|
||||
|
|
|
@ -81,7 +81,7 @@ func GetIssueCommentReactions(ctx *context.APIContext) {
|
|||
var result []api.Reaction
|
||||
for _, r := range reactions {
|
||||
result = append(result, api.Reaction{
|
||||
User: convert.ToUser(r.User, ctx.IsSigned, false),
|
||||
User: convert.ToUser(r.User, ctx.User),
|
||||
Reaction: r.Type,
|
||||
Created: r.CreatedUnix.AsTime(),
|
||||
})
|
||||
|
@ -203,7 +203,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
|
|||
ctx.Error(http.StatusForbidden, err.Error(), err)
|
||||
} else if models.IsErrReactionAlreadyExist(err) {
|
||||
ctx.JSON(http.StatusOK, api.Reaction{
|
||||
User: convert.ToUser(ctx.User, true, true),
|
||||
User: convert.ToUser(ctx.User, ctx.User),
|
||||
Reaction: reaction.Type,
|
||||
Created: reaction.CreatedUnix.AsTime(),
|
||||
})
|
||||
|
@ -214,7 +214,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
|
|||
}
|
||||
|
||||
ctx.JSON(http.StatusCreated, api.Reaction{
|
||||
User: convert.ToUser(ctx.User, true, true),
|
||||
User: convert.ToUser(ctx.User, ctx.User),
|
||||
Reaction: reaction.Type,
|
||||
Created: reaction.CreatedUnix.AsTime(),
|
||||
})
|
||||
|
@ -299,7 +299,7 @@ func GetIssueReactions(ctx *context.APIContext) {
|
|||
var result []api.Reaction
|
||||
for _, r := range reactions {
|
||||
result = append(result, api.Reaction{
|
||||
User: convert.ToUser(r.User, ctx.IsSigned, false),
|
||||
User: convert.ToUser(r.User, ctx.User),
|
||||
Reaction: r.Type,
|
||||
Created: r.CreatedUnix.AsTime(),
|
||||
})
|
||||
|
@ -412,7 +412,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
|
|||
ctx.Error(http.StatusForbidden, err.Error(), err)
|
||||
} else if models.IsErrReactionAlreadyExist(err) {
|
||||
ctx.JSON(http.StatusOK, api.Reaction{
|
||||
User: convert.ToUser(ctx.User, true, true),
|
||||
User: convert.ToUser(ctx.User, ctx.User),
|
||||
Reaction: reaction.Type,
|
||||
Created: reaction.CreatedUnix.AsTime(),
|
||||
})
|
||||
|
@ -423,7 +423,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
|
|||
}
|
||||
|
||||
ctx.JSON(http.StatusCreated, api.Reaction{
|
||||
User: convert.ToUser(ctx.User, true, true),
|
||||
User: convert.ToUser(ctx.User, ctx.User),
|
||||
Reaction: reaction.Type,
|
||||
Created: reaction.CreatedUnix.AsTime(),
|
||||
})
|
||||
|
|
|
@ -279,7 +279,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
|
|||
}
|
||||
apiUsers := make([]*api.User, 0, len(users))
|
||||
for i := range users {
|
||||
apiUsers[i] = convert.ToUser(users[i], ctx.IsSigned, false)
|
||||
apiUsers[i] = convert.ToUser(users[i], ctx.User)
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, apiUsers)
|
||||
|
|
|
@ -50,7 +50,7 @@ func ListStargazers(ctx *context.APIContext) {
|
|||
}
|
||||
users := make([]*api.User, len(stargazers))
|
||||
for i, stargazer := range stargazers {
|
||||
users[i] = convert.ToUser(stargazer, ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
|
||||
users[i] = convert.ToUser(stargazer, ctx.User)
|
||||
}
|
||||
ctx.JSON(http.StatusOK, users)
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ func ListSubscribers(ctx *context.APIContext) {
|
|||
}
|
||||
users := make([]*api.User, len(subscribers))
|
||||
for i, subscriber := range subscribers {
|
||||
users[i] = convert.ToUser(subscriber, ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
|
||||
users[i] = convert.ToUser(subscriber, ctx.User)
|
||||
}
|
||||
ctx.JSON(http.StatusOK, users)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
func responseAPIUsers(ctx *context.APIContext, users []*models.User) {
|
||||
apiUsers := make([]*api.User, len(users))
|
||||
for i := range users {
|
||||
apiUsers[i] = convert.ToUser(users[i], ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
|
||||
apiUsers[i] = convert.ToUser(users[i], ctx.User)
|
||||
}
|
||||
ctx.JSON(http.StatusOK, &apiUsers)
|
||||
}
|
||||
|
|
|
@ -25,13 +25,13 @@ func appendPrivateInformation(apiKey *api.PublicKey, key *models.PublicKey, defa
|
|||
apiKey.KeyType = "user"
|
||||
|
||||
if defaultUser.ID == key.OwnerID {
|
||||
apiKey.Owner = convert.ToUser(defaultUser, true, true)
|
||||
apiKey.Owner = convert.ToUser(defaultUser, defaultUser)
|
||||
} else {
|
||||
user, err := models.GetUserByID(key.OwnerID)
|
||||
if err != nil {
|
||||
return apiKey, err
|
||||
}
|
||||
apiKey.Owner = convert.ToUser(user, true, true)
|
||||
apiKey.Owner = convert.ToUser(user, user)
|
||||
}
|
||||
} else {
|
||||
apiKey.KeyType = "unknown"
|
||||
|
|
|
@ -75,7 +75,7 @@ func Search(ctx *context.APIContext) {
|
|||
|
||||
results := make([]*api.User, len(users))
|
||||
for i := range users {
|
||||
results[i] = convert.ToUser(users[i], ctx.IsSigned, ctx.User != nil && ctx.User.IsAdmin)
|
||||
results[i] = convert.ToUser(users[i], ctx.User)
|
||||
}
|
||||
|
||||
ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
|
||||
|
@ -112,7 +112,7 @@ func GetInfo(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.IsSigned, ctx.User != nil && (ctx.User.ID == u.ID || ctx.User.IsAdmin)))
|
||||
ctx.JSON(http.StatusOK, convert.ToUser(u, ctx.User))
|
||||
}
|
||||
|
||||
// GetAuthenticatedUser get current user's information
|
||||
|
@ -126,7 +126,7 @@ func GetAuthenticatedUser(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/User"
|
||||
|
||||
ctx.JSON(http.StatusOK, convert.ToUser(ctx.User, ctx.IsSigned, ctx.User != nil))
|
||||
ctx.JSON(http.StatusOK, convert.ToUser(ctx.User, ctx.User))
|
||||
}
|
||||
|
||||
// GetUserHeatmapData is the handler to get a users heatmap
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue