aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2021-03-27 17:45:26 +0100
committerGitHub <noreply@github.com>2021-03-27 17:45:26 +0100
commit290cf75f9343a43d9770b1d6f8f3332a23357e27 (patch)
tree520f9f8616fbff3b43a1808ef2d73af3f2fe534b /routers/api
parentf4d27498bdc615605e14f783501e1d1256cd8d22 (diff)
downloadgitea-290cf75f9343a43d9770b1d6f8f3332a23357e27.tar.gz
gitea-290cf75f9343a43d9770b1d6f8f3332a23357e27.zip
[refactor] Unify the export of user data via API (#15144)
* [refactor] unify how user data is exported via API * test time via unix timestamp
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/admin/user.go6
-rw-r--r--routers/api/v1/org/member.go2
-rw-r--r--routers/api/v1/org/team.go4
-rw-r--r--routers/api/v1/repo/collaborators.go2
-rw-r--r--routers/api/v1/repo/hook.go4
-rw-r--r--routers/api/v1/repo/issue_reaction.go12
-rw-r--r--routers/api/v1/repo/issue_subscription.go2
-rw-r--r--routers/api/v1/repo/star.go2
-rw-r--r--routers/api/v1/repo/subscriber.go2
-rw-r--r--routers/api/v1/user/follower.go2
-rw-r--r--routers/api/v1/user/key.go4
-rw-r--r--routers/api/v1/user/user.go6
12 files changed, 24 insertions, 24 deletions
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go
index 116c622048..cbb9f6b21c 100644
--- a/routers/api/v1/admin/user.go
+++ b/routers/api/v1/admin/user.go
@@ -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)
diff --git a/routers/api/v1/org/member.go b/routers/api/v1/org/member.go
index 5f0e36386e..09abad2557 100644
--- a/routers/api/v1/org/member.go
+++ b/routers/api/v1/org/member.go
@@ -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)
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go
index c749751ac4..99bbd9eefe 100644
--- a/routers/api/v1/org/team.go
+++ b/routers/api/v1/org/team.go
@@ -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
diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go
index a4fc1d8f11..d0936019fa 100644
--- a/routers/api/v1/repo/collaborators.go
+++ b/routers/api/v1/repo/collaborators.go
@@ -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)
}
diff --git a/routers/api/v1/repo/hook.go b/routers/api/v1/repo/hook.go
index 520a7a0202..5a0911544a 100644
--- a/routers/api/v1/repo/hook.go
+++ b/routers/api/v1/repo/hook.go
@@ -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
diff --git a/routers/api/v1/repo/issue_reaction.go b/routers/api/v1/repo/issue_reaction.go
index 3994c6b941..d0ba8dac65 100644
--- a/routers/api/v1/repo/issue_reaction.go
+++ b/routers/api/v1/repo/issue_reaction.go
@@ -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(),
})
diff --git a/routers/api/v1/repo/issue_subscription.go b/routers/api/v1/repo/issue_subscription.go
index 2bbd72299a..8acd378cc5 100644
--- a/routers/api/v1/repo/issue_subscription.go
+++ b/routers/api/v1/repo/issue_subscription.go
@@ -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)
diff --git a/routers/api/v1/repo/star.go b/routers/api/v1/repo/star.go
index 774b326472..3af0a4ac12 100644
--- a/routers/api/v1/repo/star.go
+++ b/routers/api/v1/repo/star.go
@@ -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)
}
diff --git a/routers/api/v1/repo/subscriber.go b/routers/api/v1/repo/subscriber.go
index ac61710bd2..37bf3c29d4 100644
--- a/routers/api/v1/repo/subscriber.go
+++ b/routers/api/v1/repo/subscriber.go
@@ -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)
}
diff --git a/routers/api/v1/user/follower.go b/routers/api/v1/user/follower.go
index 39f3c20927..4d316425cd 100644
--- a/routers/api/v1/user/follower.go
+++ b/routers/api/v1/user/follower.go
@@ -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)
}
diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go
index df8a11c61f..780cdf417c 100644
--- a/routers/api/v1/user/key.go
+++ b/routers/api/v1/user/key.go
@@ -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"
diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go
index ecc149fe52..6e811bf0f8 100644
--- a/routers/api/v1/user/user.go
+++ b/routers/api/v1/user/user.go
@@ -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