Skip to content

Commit

Permalink
Fix permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty287 committed Jan 12, 2022
1 parent 2663781 commit dde1c05
Showing 1 changed file with 84 additions and 1 deletion.
85 changes: 84 additions & 1 deletion routers/api/v1/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,22 @@ func GetIssueDependencies(ctx *context.APIContext) {
if i < skip || i >= max {
continue
}

perm, err := models.GetUserRepoPermission(&depMeta.Repository, ctx.User)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
return
}
if depMeta.Issue.IsPull {
if !perm.CanRead(unit.TypePullRequests) {
continue
}
} else {
if !perm.CanRead(unit.TypeIssues) {
continue
}
}

depMeta.Issue.Repo = &depMeta.Repository
issues = append(issues, &depMeta.Issue)
}
Expand Down Expand Up @@ -1127,6 +1143,22 @@ func GetIssueBlocks(ctx *context.APIContext) {
if i < skip || i >= max {
continue
}

perm, err := models.GetUserRepoPermission(&depMeta.Repository, ctx.User)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
return
}
if depMeta.Issue.IsPull {
if !perm.CanRead(unit.TypePullRequests) {
continue
}
} else {
if !perm.CanRead(unit.TypeIssues) {
continue
}
}

depMeta.Issue.Repo = &depMeta.Repository
issues = append(issues, &depMeta.Issue)
}
Expand Down Expand Up @@ -1210,7 +1242,7 @@ func createIssueDependency(ctx *context.APIContext, t models.DependencyType) {
return
}

dep, err := models.GetIssueWithAttrsByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
dep, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
if models.IsErrIssueNotExist(err) {
ctx.NotFound("IsErrIssueNotExist", err)
Expand Down Expand Up @@ -1242,8 +1274,42 @@ func createIssueDependency(ctx *context.APIContext, t models.DependencyType) {
}

if t == models.DependencyTypeBlockedBy {
perm, err := models.GetUserRepoPermission(ctx.Repo.Repository, ctx.User)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
return
}
if issue.IsPull {
if !perm.CanRead(unit.TypePullRequests) {
ctx.NotFound()
return
}
} else {
if !perm.CanRead(unit.TypeIssues) {
ctx.NotFound()
return
}
}

err = models.CreateIssueDependency(ctx.User, issue, dep)
} else {
perm, err := models.GetUserRepoPermission(repo, ctx.User)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
return
}
if issue.IsPull {
if !perm.CanRead(unit.TypePullRequests) {
ctx.NotFound()
return
}
} else {
if !perm.CanRead(unit.TypeIssues) {
ctx.NotFound()
return
}
}

err = models.CreateIssueDependency(ctx.User, dep, issue)
}
if err != nil {
Expand Down Expand Up @@ -1291,6 +1357,23 @@ func removeIssueDependency(ctx *context.APIContext, t models.DependencyType) {
return
}

perm, err := models.GetUserRepoPermission(repo, ctx.User)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err)
return
}
if issue.IsPull {
if !perm.CanRead(unit.TypePullRequests) {
ctx.NotFound("IsErrRepoNotExist", err)
return
}
} else {
if !perm.CanRead(unit.TypeIssues) {
ctx.NotFound("IsErrRepoNotExist", err)
return
}
}

err = models.RemoveIssueDependency(ctx.User, issue, dep, t)
if err != nil {
ctx.Error(http.StatusInternalServerError, "CreateIssueDependency", err)
Expand Down

0 comments on commit dde1c05

Please sign in to comment.