aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorEthan Koenig <ethantkoenig@gmail.com>2016-12-05 18:48:51 -0500
committerKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2016-12-07 12:55:24 +0100
commit04b9a7e7a22d968790aeee9c316391252b0aaf67 (patch)
treeeb7af4ff5dbe06439511779331aac0b2de3a8c04 /models
parent08b9af9ad8861352d1b68d15b33ef265352a2f4a (diff)
downloadgitea-04b9a7e7a22d968790aeee9c316391252b0aaf67.tar.gz
gitea-04b9a7e7a22d968790aeee9c316391252b0aaf67.zip
Bug fixes for repo permissions in API
Also move duplicated code into repo.APIFormat(..)
Diffstat (limited to 'models')
-rw-r--r--models/action.go2
-rw-r--r--models/issue.go12
-rw-r--r--models/pull.go12
-rw-r--r--models/repo.go7
4 files changed, 19 insertions, 14 deletions
diff --git a/models/action.go b/models/action.go
index e2ac1756ab..9c79dc5df0 100644
--- a/models/action.go
+++ b/models/action.go
@@ -539,7 +539,7 @@ func CommitRepoAction(opts CommitRepoActionOptions) error {
}()
apiPusher := pusher.APIFormat()
- apiRepo := repo.APIFormat(nil)
+ apiRepo := repo.APIFormat(AccessModeNone)
var shaSum string
switch opType {
diff --git a/models/issue.go b/models/issue.go
index 7ef3d00e41..4937bf1b56 100644
--- a/models/issue.go
+++ b/models/issue.go
@@ -265,7 +265,7 @@ func (issue *Issue) sendLabelUpdatedWebhook(doer *User) {
Action: api.HookIssueLabelUpdated,
Index: issue.Index,
PullRequest: issue.PullRequest.APIFormat(),
- Repository: issue.Repo.APIFormat(nil),
+ Repository: issue.Repo.APIFormat(AccessModeNone),
Sender: doer.APIFormat(),
})
}
@@ -371,7 +371,7 @@ func (issue *Issue) ClearLabels(doer *User) (err error) {
Action: api.HookIssueLabelCleared,
Index: issue.Index,
PullRequest: issue.PullRequest.APIFormat(),
- Repository: issue.Repo.APIFormat(nil),
+ Repository: issue.Repo.APIFormat(AccessModeNone),
Sender: doer.APIFormat(),
})
}
@@ -493,7 +493,7 @@ func (issue *Issue) ChangeStatus(doer *User, repo *Repository, isClosed bool) (e
apiPullRequest := &api.PullRequestPayload{
Index: issue.Index,
PullRequest: issue.PullRequest.APIFormat(),
- Repository: repo.APIFormat(nil),
+ Repository: repo.APIFormat(AccessModeNone),
Sender: doer.APIFormat(),
}
if isClosed {
@@ -531,7 +531,7 @@ func (issue *Issue) ChangeTitle(doer *User, title string) (err error) {
},
},
PullRequest: issue.PullRequest.APIFormat(),
- Repository: issue.Repo.APIFormat(nil),
+ Repository: issue.Repo.APIFormat(AccessModeNone),
Sender: doer.APIFormat(),
})
}
@@ -563,7 +563,7 @@ func (issue *Issue) ChangeContent(doer *User, content string) (err error) {
},
},
PullRequest: issue.PullRequest.APIFormat(),
- Repository: issue.Repo.APIFormat(nil),
+ Repository: issue.Repo.APIFormat(AccessModeNone),
Sender: doer.APIFormat(),
})
}
@@ -596,7 +596,7 @@ func (issue *Issue) ChangeAssignee(doer *User, assigneeID int64) (err error) {
apiPullRequest := &api.PullRequestPayload{
Index: issue.Index,
PullRequest: issue.PullRequest.APIFormat(),
- Repository: issue.Repo.APIFormat(nil),
+ Repository: issue.Repo.APIFormat(AccessModeNone),
Sender: doer.APIFormat(),
}
if isRemoveAssignee {
diff --git a/models/pull.go b/models/pull.go
index d149a142d0..b7a1ce5d2e 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -160,14 +160,14 @@ func (pr *PullRequest) APIFormat() *api.PullRequest {
Ref: pr.BaseBranch,
Sha: baseCommit.ID.String(),
RepoID: pr.BaseRepoID,
- Repository: pr.BaseRepo.APIFormat(nil),
+ Repository: pr.BaseRepo.APIFormat(AccessModeNone),
}
apiHeadBranchInfo := &api.PRBranchInfo{
Name: pr.HeadBranch,
Ref: pr.HeadBranch,
Sha: headCommit.ID.String(),
RepoID: pr.HeadRepoID,
- Repository: pr.HeadRepo.APIFormat(nil),
+ Repository: pr.HeadRepo.APIFormat(AccessModeNone),
}
apiPullRequest := &api.PullRequest{
ID: pr.ID,
@@ -355,7 +355,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error
Action: api.HookIssueClosed,
Index: pr.Index,
PullRequest: pr.APIFormat(),
- Repository: pr.Issue.Repo.APIFormat(nil),
+ Repository: pr.Issue.Repo.APIFormat(AccessModeNone),
Sender: doer.APIFormat(),
}); err != nil {
log.Error(4, "PrepareWebhooks: %v", err)
@@ -385,7 +385,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository) (err error
After: pr.MergedCommitID,
CompareURL: setting.AppURL + pr.BaseRepo.ComposeCompareURL(pr.MergeBase, pr.MergedCommitID),
Commits: ListToPushCommits(l).ToAPIPayloadCommits(pr.BaseRepo.HTMLURL()),
- Repo: pr.BaseRepo.APIFormat(nil),
+ Repo: pr.BaseRepo.APIFormat(AccessModeNone),
Pusher: pr.HeadRepo.MustOwner().APIFormat(),
Sender: doer.APIFormat(),
}
@@ -514,7 +514,7 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str
Action: api.HookIssueOpened,
Index: pull.Index,
PullRequest: pr.APIFormat(),
- Repository: repo.APIFormat(nil),
+ Repository: repo.APIFormat(AccessModeNone),
Sender: pull.Poster.APIFormat(),
}); err != nil {
log.Error(4, "PrepareWebhooks: %v", err)
@@ -840,7 +840,7 @@ func AddTestPullRequestTask(doer *User, repoID int64, branch string, isSync bool
Action: api.HookIssueSynchronized,
Index: pr.Issue.Index,
PullRequest: pr.Issue.PullRequest.APIFormat(),
- Repository: pr.Issue.Repo.APIFormat(nil),
+ Repository: pr.Issue.Repo.APIFormat(AccessModeNone),
Sender: doer.APIFormat(),
}); err != nil {
log.Error(4, "PrepareWebhooks [pull_id: %v]: %v", pr.ID, err)
diff --git a/models/repo.go b/models/repo.go
index af74e6c8fc..f339234fb4 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -277,8 +277,13 @@ func (repo *Repository) HTMLURL() string {
// APIFormat converts a Repository to api.Repository
// Arguments that are allowed to be nil: permission
-func (repo *Repository) APIFormat(permission *api.Permission) *api.Repository {
+func (repo *Repository) APIFormat(mode AccessMode) *api.Repository {
cloneLink := repo.CloneLink()
+ permission := &api.Permission{
+ Admin: mode >= AccessModeAdmin,
+ Push: mode >= AccessModeWrite,
+ Pull: mode >= AccessModeRead,
+ }
return &api.Repository{
ID: repo.ID,
Owner: repo.Owner.APIFormat(),