Skip to content

Commit b677d04

Browse files
committed
rename some functions
1 parent 861b3b2 commit b677d04

File tree

8 files changed

+17
-69
lines changed

8 files changed

+17
-69
lines changed

models/repo.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,6 @@ func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) strin
607607
return fmt.Sprintf("%s/%s/compare/%s...%s", repo.MustOwner().Name, repo.Name, oldCommitID, newCommitID)
608608
}
609609

610-
// HasAccess returns true when user has access to this repository
611-
/*func (repo *Repository) HasAccess(u *User) bool {
612-
has, _ := HasAccess(u.ID, repo, AccessModeRead)
613-
return has
614-
}*/
615-
616610
// UpdateDefaultBranch updates the default branch
617611
func (repo *Repository) UpdateDefaultBranch() error {
618612
_, err := x.ID(repo.ID).Cols("default_branch").Update(repo)

modules/lfs/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ func authenticate(ctx *context.Context, repository *models.Repository, authoriza
502502
return false
503503
}
504504
if ctx.IsSigned {
505-
return perm.UnitAccessMode(models.UnitTypeCode) >= accessMode
505+
return perm.CanAccess(accessMode, models.UnitTypeCode)
506506
}
507507

508508
user, repo, opStr, err := parseToken(authorization)
@@ -515,7 +515,7 @@ func authenticate(ctx *context.Context, repository *models.Repository, authoriza
515515
if err != nil {
516516
return false
517517
}
518-
return perm.UnitAccessMode(models.UnitTypeCode) >= accessMode
518+
return perm.CanAccess(accessMode, models.UnitTypeCode)
519519
}
520520
if repository.ID == repo.ID {
521521
if requireWrite && opStr != "upload" {

modules/private/internal.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,30 +73,6 @@ func CheckUnitUser(userID, repoID int64, isAdmin bool, unitType models.UnitType)
7373
return &a, nil
7474
}
7575

76-
// AccessLevel returns the Access a user has to a repository. Will return NoneAccess if the
77-
// user does not have access.
78-
/*func AccessLevel(userID, repoID int64) (*models.AccessMode, error) {
79-
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/repositories/%d/user/%d/accesslevel", repoID, userID)
80-
log.GitLogger.Trace("AccessLevel: %s", reqURL)
81-
82-
resp, err := newInternalRequest(reqURL, "GET").Response()
83-
if err != nil {
84-
return nil, err
85-
}
86-
defer resp.Body.Close()
87-
88-
if resp.StatusCode != 200 {
89-
return nil, fmt.Errorf("Failed to get user access level: %s", decodeJSONError(resp).Err)
90-
}
91-
92-
var a models.AccessMode
93-
if err := json.NewDecoder(resp.Body).Decode(&a); err != nil {
94-
return nil, err
95-
}
96-
97-
return &a, nil
98-
}*/
99-
10076
// GetRepositoryByOwnerAndName returns the repository by given ownername and reponame.
10177
func GetRepositoryByOwnerAndName(ownerName, repoName string) (*models.Repository, error) {
10278
reqURL := setting.LocalURL + fmt.Sprintf("api/internal/repo/%s/%s", ownerName, repoName)

routers/api/v1/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ func RegisterRoutes(m *macaron.Macaron) {
509509
Post(bind(api.CreateKeyOption{}), repo.CreateDeployKey)
510510
m.Combo("/:id").Get(repo.GetDeployKey).
511511
Delete(repo.DeleteDeploykey)
512-
}, reqToken(), reqRepoWriter(models.UnitTypeCode))
512+
}, reqToken(), reqAdmin())
513513
m.Group("/times", func() {
514514
m.Combo("").Get(repo.ListTrackedTimesByRepository)
515515
m.Combo("/:timetrackingusername").Get(repo.ListTrackedTimesByUser)

routers/private/internal.go

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,6 @@ func GetRepositoryByOwnerAndName(ctx *macaron.Context) {
3838
ctx.JSON(200, repo)
3939
}
4040

41-
//AccessLevel chainload to models.AccessLevel
42-
/*func AccessLevel(ctx *macaron.Context) {
43-
repoID := ctx.ParamsInt64(":repoid")
44-
userID := ctx.ParamsInt64(":userid")
45-
repo, err := models.GetRepositoryByID(repoID)
46-
if err != nil {
47-
ctx.JSON(500, map[string]interface{}{
48-
"err": err.Error(),
49-
})
50-
return
51-
}
52-
al, err := models.AccessLevel(userID, repo)
53-
if err != nil {
54-
ctx.JSON(500, map[string]interface{}{
55-
"err": err.Error(),
56-
})
57-
return
58-
}
59-
ctx.JSON(200, al)
60-
}*/
61-
6241
//CheckUnitUser chainload to models.CheckUnitUser
6342
func CheckUnitUser(ctx *macaron.Context) {
6443
repoID := ctx.ParamsInt64(":repoid")
@@ -71,12 +50,15 @@ func CheckUnitUser(ctx *macaron.Context) {
7150
return
7251
}
7352

74-
user, err := models.GetUserByID(userID)
75-
if err != nil {
76-
ctx.JSON(500, map[string]interface{}{
77-
"err": err.Error(),
78-
})
79-
return
53+
var user *models.User
54+
if userID > 0 {
55+
user, err = models.GetUserByID(userID)
56+
if err != nil {
57+
ctx.JSON(500, map[string]interface{}{
58+
"err": err.Error(),
59+
})
60+
return
61+
}
8062
}
8163

8264
perm, err := models.GetUserRepoPermission(repo, user)
@@ -98,7 +80,6 @@ func RegisterRoutes(m *macaron.Macaron) {
9880
m.Get("/ssh/:id/user", GetUserByKeyID)
9981
m.Post("/ssh/:id/update", UpdatePublicKey)
10082
m.Post("/repositories/:repoid/keys/:keyid/update", UpdateDeployKey)
101-
//m.Get("/repositories/:repoid/user/:userid/accesslevel", AccessLevel)
10283
m.Get("/repositories/:repoid/user/:userid/checkunituser", CheckUnitUser)
10384
m.Get("/repositories/:repoid/has-keys/:keyid", HasDeployKey)
10485
m.Post("/push/update", PushUpdate)

routers/repo/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func HTTP(ctx *context.Context) {
188188
return
189189
}
190190

191-
if perm.UnitAccessMode(unitType) < accessMode {
191+
if !perm.CanAccess(accessMode, unitType) {
192192
ctx.HandleText(http.StatusForbidden, "User permission denied")
193193
return
194194
}

routers/repo/issue.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,6 @@ func ValidateRepoMetas(ctx *context.Context, form auth.CreateIssueForm, isPull b
381381
return nil, nil, 0
382382
}
383383

384-
if !ctx.Repo.CanWrite(models.UnitTypeIssues) {
385-
return nil, nil, 0
386-
}
387-
388384
var labelIDs []int64
389385
hasSelected := false
390386
// Check labels.

routers/routes/routes.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,9 @@ func RegisterRoutes(m *macaron.Macaron) {
398398
reqRepoReleaseWriter := context.RequireRepoWriter(models.UnitTypeReleases)
399399
reqRepoReleaseReader := context.RequireRepoReader(models.UnitTypeReleases)
400400
reqRepoWikiWriter := context.RequireRepoWriter(models.UnitTypeWiki)
401-
reqRepoIssueWriter := context.RequireRepoWriter(models.UnitTypeIssues)
401+
reqRepoIssueReader := context.RequireRepoReader(models.UnitTypeIssues)
402402
reqRepoPullsWriter := context.RequireRepoWriter(models.UnitTypePullRequests)
403+
reqRepoPullsReader := context.RequireRepoReader(models.UnitTypePullRequests)
403404
reqRepoIssuesOrPullsWriter := context.RequireRepoWriterOr(models.UnitTypeIssues, models.UnitTypePullRequests)
404405
reqRepoIssuesOrPullsReader := context.RequireRepoReaderOr(models.UnitTypeIssues, models.UnitTypePullRequests)
405406

@@ -530,7 +531,7 @@ func RegisterRoutes(m *macaron.Macaron) {
530531
m.Group("/issues", func() {
531532
m.Combo("/new").Get(context.RepoRef(), repo.NewIssue).
532533
Post(bindIgnErr(auth.CreateIssueForm{}), repo.NewIssuePost)
533-
}, reqRepoIssueWriter)
534+
}, reqRepoIssueReader)
534535
// FIXME: should use different URLs but mostly same logic for comments of issue and pull reuqest.
535536
// So they can apply their own enable/disable logic on routers.
536537
m.Group("/issues", func() {
@@ -578,7 +579,7 @@ func RegisterRoutes(m *macaron.Macaron) {
578579
m.Post("/delete", repo.DeleteMilestone)
579580
}, reqRepoIssuesOrPullsWriter, context.RepoRef())
580581

581-
m.Combo("/compare/*", reqRepoCodeReader, repo.MustAllowPulls, repo.SetEditorconfigIfExists).
582+
m.Combo("/compare/*", reqRepoCodeReader, reqRepoPullsReader, repo.MustAllowPulls, repo.SetEditorconfigIfExists).
582583
Get(repo.SetDiffViewStyle, repo.CompareAndPullRequest).
583584
Post(bindIgnErr(auth.CreateIssueForm{}), repo.CompareAndPullRequestPost)
584585

0 commit comments

Comments
 (0)