[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
|
@ -61,7 +61,7 @@ func TestAPIIssuesReactions(t *testing.T) {
|
|||
DecodeJSON(t, resp, &apiReactions)
|
||||
expectResponse := make(map[int]api.Reaction)
|
||||
expectResponse[0] = api.Reaction{
|
||||
User: convert.ToUser(user2, true, true),
|
||||
User: convert.ToUser(user2, user2),
|
||||
Reaction: "eyes",
|
||||
Created: time.Unix(1573248003, 0),
|
||||
}
|
||||
|
@ -121,12 +121,12 @@ func TestAPICommentReactions(t *testing.T) {
|
|||
DecodeJSON(t, resp, &apiReactions)
|
||||
expectResponse := make(map[int]api.Reaction)
|
||||
expectResponse[0] = api.Reaction{
|
||||
User: convert.ToUser(user2, true, true),
|
||||
User: convert.ToUser(user2, user2),
|
||||
Reaction: "laugh",
|
||||
Created: time.Unix(1573248004, 0),
|
||||
}
|
||||
expectResponse[1] = api.Reaction{
|
||||
User: convert.ToUser(user1, true, true),
|
||||
User: convert.ToUser(user1, user1),
|
||||
Reaction: "laugh",
|
||||
Created: time.Unix(1573248005, 0),
|
||||
}
|
||||
|
|
|
@ -31,5 +31,13 @@ func TestAPITeamUser(t *testing.T) {
|
|||
user2.Created = user2.Created.In(time.Local)
|
||||
user := models.AssertExistsAndLoadBean(t, &models.User{Name: "user2"}).(*models.User)
|
||||
|
||||
assert.Equal(t, convert.ToUser(user, true, false), user2)
|
||||
expectedUser := convert.ToUser(user, user)
|
||||
|
||||
// test time via unix timestamp
|
||||
assert.EqualValues(t, expectedUser.LastLogin.Unix(), user2.LastLogin.Unix())
|
||||
assert.EqualValues(t, expectedUser.Created.Unix(), user2.Created.Unix())
|
||||
expectedUser.LastLogin = user2.LastLogin
|
||||
expectedUser.Created = user2.Created
|
||||
|
||||
assert.Equal(t, expectedUser, user2)
|
||||
}
|
||||
|
|
|
@ -86,13 +86,13 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
|
|||
}
|
||||
|
||||
if ok {
|
||||
apiAuthor = ToUser(cacheAuthor, false, false)
|
||||
apiAuthor = ToUser(cacheAuthor, nil)
|
||||
} else {
|
||||
author, err := models.GetUserByEmail(commit.Author.Email)
|
||||
if err != nil && !models.IsErrUserNotExist(err) {
|
||||
return nil, err
|
||||
} else if err == nil {
|
||||
apiAuthor = ToUser(author, false, false)
|
||||
apiAuthor = ToUser(author, nil)
|
||||
if userCache != nil {
|
||||
userCache[commit.Author.Email] = author
|
||||
}
|
||||
|
@ -108,13 +108,13 @@ func ToCommit(repo *models.Repository, commit *git.Commit, userCache map[string]
|
|||
}
|
||||
|
||||
if ok {
|
||||
apiCommitter = ToUser(cacheCommitter, false, false)
|
||||
apiCommitter = ToUser(cacheCommitter, nil)
|
||||
} else {
|
||||
committer, err := models.GetUserByEmail(commit.Committer.Email)
|
||||
if err != nil && !models.IsErrUserNotExist(err) {
|
||||
return nil, err
|
||||
} else if err == nil {
|
||||
apiCommitter = ToUser(committer, false, false)
|
||||
apiCommitter = ToUser(committer, nil)
|
||||
if userCache != nil {
|
||||
userCache[commit.Committer.Email] = committer
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ func ToAPIIssue(issue *models.Issue) *api.Issue {
|
|||
URL: issue.APIURL(),
|
||||
HTMLURL: issue.HTMLURL(),
|
||||
Index: issue.Index,
|
||||
Poster: ToUser(issue.Poster, false, false),
|
||||
Poster: ToUser(issue.Poster, nil),
|
||||
Title: issue.Title,
|
||||
Body: issue.Content,
|
||||
Ref: issue.Ref,
|
||||
|
@ -66,9 +66,9 @@ func ToAPIIssue(issue *models.Issue) *api.Issue {
|
|||
}
|
||||
if len(issue.Assignees) > 0 {
|
||||
for _, assignee := range issue.Assignees {
|
||||
apiIssue.Assignees = append(apiIssue.Assignees, ToUser(assignee, false, false))
|
||||
apiIssue.Assignees = append(apiIssue.Assignees, ToUser(assignee, nil))
|
||||
}
|
||||
apiIssue.Assignee = ToUser(issue.Assignees[0], false, false) // For compatibility, we're keeping the first assignee as `apiIssue.Assignee`
|
||||
apiIssue.Assignee = ToUser(issue.Assignees[0], nil) // For compatibility, we're keeping the first assignee as `apiIssue.Assignee`
|
||||
}
|
||||
if issue.IsPull {
|
||||
if err := issue.LoadPullRequest(); err != nil {
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
func ToComment(c *models.Comment) *api.Comment {
|
||||
return &api.Comment{
|
||||
ID: c.ID,
|
||||
Poster: ToUser(c.Poster, false, false),
|
||||
Poster: ToUser(c.Poster, nil),
|
||||
HTMLURL: c.HTMLURL(),
|
||||
IssueURL: c.IssueURL(),
|
||||
PRURL: c.PRURL(),
|
||||
|
|
|
@ -159,7 +159,7 @@ func ToAPIPullRequest(pr *models.PullRequest) *api.PullRequest {
|
|||
if pr.HasMerged {
|
||||
apiPullRequest.Merged = pr.MergedUnix.AsTimePtr()
|
||||
apiPullRequest.MergedCommitID = &pr.MergedCommitID
|
||||
apiPullRequest.MergedBy = ToUser(pr.Merger, false, false)
|
||||
apiPullRequest.MergedBy = ToUser(pr.Merger, nil)
|
||||
}
|
||||
|
||||
return apiPullRequest
|
||||
|
|
|
@ -20,14 +20,9 @@ func ToPullReview(r *models.Review, doer *models.User) (*api.PullReview, error)
|
|||
r.Reviewer = models.NewGhostUser()
|
||||
}
|
||||
|
||||
auth := false
|
||||
if doer != nil {
|
||||
auth = doer.IsAdmin || doer.ID == r.ReviewerID
|
||||
}
|
||||
|
||||
result := &api.PullReview{
|
||||
ID: r.ID,
|
||||
Reviewer: ToUser(r.Reviewer, doer != nil, auth),
|
||||
Reviewer: ToUser(r.Reviewer, doer),
|
||||
ReviewerTeam: ToTeam(r.ReviewerTeam),
|
||||
State: api.ReviewStateUnknown,
|
||||
Body: r.Content,
|
||||
|
@ -88,14 +83,10 @@ func ToPullReviewCommentList(review *models.Review, doer *models.User) ([]*api.P
|
|||
for _, lines := range review.CodeComments {
|
||||
for _, comments := range lines {
|
||||
for _, comment := range comments {
|
||||
auth := false
|
||||
if doer != nil {
|
||||
auth = doer.IsAdmin || doer.ID == comment.Poster.ID
|
||||
}
|
||||
apiComment := &api.PullReviewComment{
|
||||
ID: comment.ID,
|
||||
Body: comment.Content,
|
||||
Reviewer: ToUser(comment.Poster, doer != nil, auth),
|
||||
Reviewer: ToUser(comment.Poster, doer),
|
||||
ReviewID: review.ID,
|
||||
Created: comment.CreatedUnix.AsTime(),
|
||||
Updated: comment.UpdatedUnix.AsTime(),
|
||||
|
|
|
@ -29,7 +29,7 @@ func ToRelease(r *models.Release) *api.Release {
|
|||
IsPrerelease: r.IsPrerelease,
|
||||
CreatedAt: r.CreatedUnix.AsTime(),
|
||||
PublishedAt: r.CreatedUnix.AsTime(),
|
||||
Publisher: ToUser(r.Publisher, false, false),
|
||||
Publisher: ToUser(r.Publisher, nil),
|
||||
Attachments: assets,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ func innerToRepo(repo *models.Repository, mode models.AccessMode, isParent bool)
|
|||
|
||||
return &api.Repository{
|
||||
ID: repo.ID,
|
||||
Owner: ToUser(repo.Owner, mode != models.AccessModeNone, mode >= models.AccessModeAdmin),
|
||||
Owner: ToUserWithAccessMode(repo.Owner, mode),
|
||||
Name: repo.Name,
|
||||
FullName: repo.FullName(),
|
||||
Description: repo.Description,
|
||||
|
|
|
@ -24,7 +24,7 @@ func ToCommitStatus(status *models.CommitStatus) *api.CommitStatus {
|
|||
|
||||
if status.CreatorID != 0 {
|
||||
creator, _ := models.GetUserByID(status.CreatorID)
|
||||
apiStatus.Creator = ToUser(creator, false, false)
|
||||
apiStatus.Creator = ToUser(creator, nil)
|
||||
}
|
||||
|
||||
return apiStatus
|
||||
|
|
|
@ -11,11 +11,32 @@ import (
|
|||
)
|
||||
|
||||
// ToUser convert models.User to api.User
|
||||
// signed shall only be set if requester is logged in. authed shall only be set if user is site admin or user himself
|
||||
func ToUser(user *models.User, signed, authed bool) *api.User {
|
||||
// if doer is set, private information is added if the doer has the permission to see it
|
||||
func ToUser(user, doer *models.User) *api.User {
|
||||
if user == nil {
|
||||
return nil
|
||||
}
|
||||
authed := false
|
||||
signed := false
|
||||
if doer != nil {
|
||||
signed = true
|
||||
authed = doer.ID == user.ID || doer.IsAdmin
|
||||
}
|
||||
return toUser(user, signed, authed)
|
||||
}
|
||||
|
||||
// ToUserWithAccessMode convert models.User to api.User
|
||||
// AccessMode is not none show add some more information
|
||||
func ToUserWithAccessMode(user *models.User, accessMode models.AccessMode) *api.User {
|
||||
if user == nil {
|
||||
return nil
|
||||
}
|
||||
return toUser(user, accessMode != models.AccessModeNone, false)
|
||||
}
|
||||
|
||||
// toUser convert models.User to api.User
|
||||
// signed shall only be set if requester is logged in. authed shall only be set if user is site admin or user himself
|
||||
func toUser(user *models.User, signed, authed bool) *api.User {
|
||||
result := &api.User{
|
||||
ID: user.ID,
|
||||
UserName: user.Name,
|
||||
|
|
|
@ -15,14 +15,14 @@ func TestUser_ToUser(t *testing.T) {
|
|||
|
||||
user1 := models.AssertExistsAndLoadBean(t, &models.User{ID: 1, IsAdmin: true}).(*models.User)
|
||||
|
||||
apiUser := ToUser(user1, true, true)
|
||||
apiUser := toUser(user1, true, true)
|
||||
assert.True(t, apiUser.IsAdmin)
|
||||
|
||||
user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2, IsAdmin: false}).(*models.User)
|
||||
|
||||
apiUser = ToUser(user2, true, true)
|
||||
apiUser = toUser(user2, true, true)
|
||||
assert.False(t, apiUser.IsAdmin)
|
||||
|
||||
apiUser = ToUser(user1, false, false)
|
||||
apiUser = toUser(user1, false, false)
|
||||
assert.False(t, apiUser.IsAdmin)
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ func (m *webhookNotifier) NotifyIssueClearLabels(doer *models.User, issue *model
|
|||
Index: issue.Index,
|
||||
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
})
|
||||
} else {
|
||||
err = webhook_services.PrepareWebhooks(issue.Repo, models.HookEventIssueLabel, &api.IssuePayload{
|
||||
|
@ -61,7 +61,7 @@ func (m *webhookNotifier) NotifyIssueClearLabels(doer *models.User, issue *model
|
|||
Index: issue.Index,
|
||||
Issue: convert.ToAPIIssue(issue),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -77,7 +77,7 @@ func (m *webhookNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo
|
|||
if err := webhook_services.PrepareWebhooks(oldRepo, models.HookEventFork, &api.ForkPayload{
|
||||
Forkee: convert.ToRepo(oldRepo, oldMode),
|
||||
Repo: convert.ToRepo(repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
}); err != nil {
|
||||
log.Error("PrepareWebhooks [repo_id: %d]: %v", oldRepo.ID, err)
|
||||
}
|
||||
|
@ -89,8 +89,8 @@ func (m *webhookNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo
|
|||
if err := webhook_services.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
|
||||
Action: api.HookRepoCreated,
|
||||
Repository: convert.ToRepo(repo, models.AccessModeOwner),
|
||||
Organization: convert.ToUser(u, false, false),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Organization: convert.ToUser(u, nil),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
}); err != nil {
|
||||
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
|
||||
}
|
||||
|
@ -102,8 +102,8 @@ func (m *webhookNotifier) NotifyCreateRepository(doer *models.User, u *models.Us
|
|||
if err := webhook_services.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
|
||||
Action: api.HookRepoCreated,
|
||||
Repository: convert.ToRepo(repo, models.AccessModeOwner),
|
||||
Organization: convert.ToUser(u, false, false),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Organization: convert.ToUser(u, nil),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
}); err != nil {
|
||||
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
|
||||
}
|
||||
|
@ -115,8 +115,8 @@ func (m *webhookNotifier) NotifyDeleteRepository(doer *models.User, repo *models
|
|||
if err := webhook_services.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
|
||||
Action: api.HookRepoDeleted,
|
||||
Repository: convert.ToRepo(repo, models.AccessModeOwner),
|
||||
Organization: convert.ToUser(u, false, false),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Organization: convert.ToUser(u, nil),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
}); err != nil {
|
||||
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
|
||||
}
|
||||
|
@ -127,8 +127,8 @@ func (m *webhookNotifier) NotifyMigrateRepository(doer *models.User, u *models.U
|
|||
if err := webhook_services.PrepareWebhooks(repo, models.HookEventRepository, &api.RepositoryPayload{
|
||||
Action: api.HookRepoCreated,
|
||||
Repository: convert.ToRepo(repo, models.AccessModeOwner),
|
||||
Organization: convert.ToUser(u, false, false),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Organization: convert.ToUser(u, nil),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
}); err != nil {
|
||||
log.Error("PrepareWebhooks [repo_id: %d]: %v", repo.ID, err)
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *mo
|
|||
Index: issue.Index,
|
||||
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
}
|
||||
if removed {
|
||||
apiPullRequest.Action = api.HookIssueUnassigned
|
||||
|
@ -165,7 +165,7 @@ func (m *webhookNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *mo
|
|||
Index: issue.Index,
|
||||
Issue: convert.ToAPIIssue(issue),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
}
|
||||
if removed {
|
||||
apiIssue.Action = api.HookIssueUnassigned
|
||||
|
@ -199,7 +199,7 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(doer *models.User, issue *model
|
|||
},
|
||||
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
})
|
||||
} else {
|
||||
err = webhook_services.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
|
||||
|
@ -212,7 +212,7 @@ func (m *webhookNotifier) NotifyIssueChangeTitle(doer *models.User, issue *model
|
|||
},
|
||||
Issue: convert.ToAPIIssue(issue),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(issue.Poster, false, false),
|
||||
Sender: convert.ToUser(issue.Poster, nil),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -234,7 +234,7 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(doer *models.User, issue *mode
|
|||
Index: issue.Index,
|
||||
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
}
|
||||
if isClosed {
|
||||
apiPullRequest.Action = api.HookIssueClosed
|
||||
|
@ -247,7 +247,7 @@ func (m *webhookNotifier) NotifyIssueChangeStatus(doer *models.User, issue *mode
|
|||
Index: issue.Index,
|
||||
Issue: convert.ToAPIIssue(issue),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
}
|
||||
if isClosed {
|
||||
apiIssue.Action = api.HookIssueClosed
|
||||
|
@ -277,7 +277,7 @@ func (m *webhookNotifier) NotifyNewIssue(issue *models.Issue, mentions []*models
|
|||
Index: issue.Index,
|
||||
Issue: convert.ToAPIIssue(issue),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(issue.Poster, false, false),
|
||||
Sender: convert.ToUser(issue.Poster, nil),
|
||||
}); err != nil {
|
||||
log.Error("PrepareWebhooks: %v", err)
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ func (m *webhookNotifier) NotifyNewPullRequest(pull *models.PullRequest, mention
|
|||
Index: pull.Issue.Index,
|
||||
PullRequest: convert.ToAPIPullRequest(pull),
|
||||
Repository: convert.ToRepo(pull.Issue.Repo, mode),
|
||||
Sender: convert.ToUser(pull.Issue.Poster, false, false),
|
||||
Sender: convert.ToUser(pull.Issue.Poster, nil),
|
||||
}); err != nil {
|
||||
log.Error("PrepareWebhooks: %v", err)
|
||||
}
|
||||
|
@ -324,7 +324,7 @@ func (m *webhookNotifier) NotifyIssueChangeContent(doer *models.User, issue *mod
|
|||
},
|
||||
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
})
|
||||
} else {
|
||||
err = webhook_services.PrepareWebhooks(issue.Repo, models.HookEventIssues, &api.IssuePayload{
|
||||
|
@ -337,7 +337,7 @@ func (m *webhookNotifier) NotifyIssueChangeContent(doer *models.User, issue *mod
|
|||
},
|
||||
Issue: convert.ToAPIIssue(issue),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -374,7 +374,7 @@ func (m *webhookNotifier) NotifyUpdateComment(doer *models.User, c *models.Comme
|
|||
},
|
||||
},
|
||||
Repository: convert.ToRepo(c.Issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
IsPull: true,
|
||||
})
|
||||
} else {
|
||||
|
@ -388,7 +388,7 @@ func (m *webhookNotifier) NotifyUpdateComment(doer *models.User, c *models.Comme
|
|||
},
|
||||
},
|
||||
Repository: convert.ToRepo(c.Issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
IsPull: false,
|
||||
})
|
||||
}
|
||||
|
@ -409,7 +409,7 @@ func (m *webhookNotifier) NotifyCreateIssueComment(doer *models.User, repo *mode
|
|||
Issue: convert.ToAPIIssue(issue),
|
||||
Comment: convert.ToComment(comment),
|
||||
Repository: convert.ToRepo(repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
IsPull: true,
|
||||
})
|
||||
} else {
|
||||
|
@ -418,7 +418,7 @@ func (m *webhookNotifier) NotifyCreateIssueComment(doer *models.User, repo *mode
|
|||
Issue: convert.ToAPIIssue(issue),
|
||||
Comment: convert.ToComment(comment),
|
||||
Repository: convert.ToRepo(repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
IsPull: false,
|
||||
})
|
||||
}
|
||||
|
@ -453,7 +453,7 @@ func (m *webhookNotifier) NotifyDeleteComment(doer *models.User, comment *models
|
|||
Issue: convert.ToAPIIssue(comment.Issue),
|
||||
Comment: convert.ToComment(comment),
|
||||
Repository: convert.ToRepo(comment.Issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
IsPull: true,
|
||||
})
|
||||
} else {
|
||||
|
@ -462,7 +462,7 @@ func (m *webhookNotifier) NotifyDeleteComment(doer *models.User, comment *models
|
|||
Issue: convert.ToAPIIssue(comment.Issue),
|
||||
Comment: convert.ToComment(comment),
|
||||
Repository: convert.ToRepo(comment.Issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
IsPull: false,
|
||||
})
|
||||
}
|
||||
|
@ -502,7 +502,7 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(doer *models.User, issue *mode
|
|||
Index: issue.Index,
|
||||
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
|
||||
Repository: convert.ToRepo(issue.Repo, models.AccessModeNone),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
})
|
||||
} else {
|
||||
err = webhook_services.PrepareWebhooks(issue.Repo, models.HookEventIssueLabel, &api.IssuePayload{
|
||||
|
@ -510,7 +510,7 @@ func (m *webhookNotifier) NotifyIssueChangeLabels(doer *models.User, issue *mode
|
|||
Index: issue.Index,
|
||||
Issue: convert.ToAPIIssue(issue),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -544,7 +544,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *m
|
|||
Index: issue.Index,
|
||||
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
})
|
||||
} else {
|
||||
err = webhook_services.PrepareWebhooks(issue.Repo, models.HookEventIssueMilestone, &api.IssuePayload{
|
||||
|
@ -552,7 +552,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *m
|
|||
Index: issue.Index,
|
||||
Issue: convert.ToAPIIssue(issue),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
|
@ -561,7 +561,7 @@ func (m *webhookNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *m
|
|||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
apiPusher := convert.ToUser(pusher, false, false)
|
||||
apiPusher := convert.ToUser(pusher, nil)
|
||||
apiCommits, err := commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL())
|
||||
if err != nil {
|
||||
log.Error("commits.ToAPIPayloadCommits failed: %v", err)
|
||||
|
@ -610,7 +610,7 @@ func (*webhookNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mod
|
|||
Index: pr.Issue.Index,
|
||||
PullRequest: convert.ToAPIPullRequest(pr),
|
||||
Repository: convert.ToRepo(pr.Issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
Action: api.HookIssueClosed,
|
||||
}
|
||||
|
||||
|
@ -643,7 +643,7 @@ func (m *webhookNotifier) NotifyPullRequestChangeTargetBranch(doer *models.User,
|
|||
},
|
||||
PullRequest: convert.ToAPIPullRequest(issue.PullRequest),
|
||||
Repository: convert.ToRepo(issue.Repo, mode),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
@ -682,7 +682,7 @@ func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
|
|||
Index: review.Issue.Index,
|
||||
PullRequest: convert.ToAPIPullRequest(pr),
|
||||
Repository: convert.ToRepo(review.Issue.Repo, mode),
|
||||
Sender: convert.ToUser(review.Reviewer, false, false),
|
||||
Sender: convert.ToUser(review.Reviewer, nil),
|
||||
Review: &api.ReviewPayload{
|
||||
Type: string(reviewHookType),
|
||||
Content: review.Content,
|
||||
|
@ -693,7 +693,7 @@ func (m *webhookNotifier) NotifyPullRequestReview(pr *models.PullRequest, review
|
|||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyCreateRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
|
||||
apiPusher := convert.ToUser(pusher, false, false)
|
||||
apiPusher := convert.ToUser(pusher, nil)
|
||||
apiRepo := convert.ToRepo(repo, models.AccessModeNone)
|
||||
refName := git.RefEndName(refFullName)
|
||||
|
||||
|
@ -737,14 +737,14 @@ func (m *webhookNotifier) NotifyPullRequestSynchronized(doer *models.User, pr *m
|
|||
Index: pr.Issue.Index,
|
||||
PullRequest: convert.ToAPIPullRequest(pr),
|
||||
Repository: convert.ToRepo(pr.Issue.Repo, models.AccessModeNone),
|
||||
Sender: convert.ToUser(doer, false, false),
|
||||
Sender: convert.ToUser(doer, nil),
|
||||
}); err != nil {
|
||||
log.Error("PrepareWebhooks [pull_id: %v]: %v", pr.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *webhookNotifier) NotifyDeleteRef(pusher *models.User, repo *models.Repository, refType, refFullName string) {
|
||||
apiPusher := convert.ToUser(pusher, false, false)
|
||||
apiPusher := convert.ToUser(pusher, nil)
|
||||
apiRepo := convert.ToRepo(repo, models.AccessModeNone)
|
||||
refName := git.RefEndName(refFullName)
|
||||
|
||||
|
@ -770,7 +770,7 @@ func sendReleaseHook(doer *models.User, rel *models.Release, action api.HookRele
|
|||
Action: action,
|
||||
Release: convert.ToRelease(rel),
|
||||
Repository: convert.ToRepo(rel.Repo, mode),
|
||||
Sender: convert.ToUser(rel.Publisher, false, false),
|
||||
Sender: convert.ToUser(rel.Publisher, nil),
|
||||
}); err != nil {
|
||||
log.Error("PrepareWebhooks: %v", err)
|
||||
}
|
||||
|
@ -789,7 +789,7 @@ func (m *webhookNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Rel
|
|||
}
|
||||
|
||||
func (m *webhookNotifier) NotifySyncPushCommits(pusher *models.User, repo *models.Repository, opts *repository.PushUpdateOptions, commits *repository.PushCommits) {
|
||||
apiPusher := convert.ToUser(pusher, false, false)
|
||||
apiPusher := convert.ToUser(pusher, nil)
|
||||
apiCommits, err := commits.ToAPIPayloadCommits(repo.RepoPath(), repo.HTMLURL())
|
||||
if err != nil {
|
||||
log.Error("commits.ToAPIPayloadCommits failed: %v", err)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1083,7 +1083,7 @@ func TestWebhook(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
apiUser := convert.ToUser(ctx.User, true, true)
|
||||
apiUser := convert.ToUserWithAccessMode(ctx.User, models.AccessModeNone)
|
||||
p := &api.PushPayload{
|
||||
Ref: git.BranchPrefix + ctx.Repo.Repository.DefaultBranch,
|
||||
Before: commit.ID.String(),
|
||||
|
|
Reference in a new issue