mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-01-08 16:42:18 +01:00
Fixup
This commit is contained in:
@@ -336,8 +336,14 @@ trait ApiControllerBase extends ControllerBase {
|
||||
loginAccount <- context.loginAccount
|
||||
} yield {
|
||||
val milestone = data.milestone.flatMap(getMilestone(repository.owner, repository.name, _))
|
||||
val issue = createIssue(repository, data.title, data.body, data.assignees.headOption,
|
||||
milestone.map(_.milestoneId), data.labels)
|
||||
val issue = createIssue(
|
||||
repository,
|
||||
data.title,
|
||||
data.body,
|
||||
data.assignees.headOption,
|
||||
milestone.map(_.milestoneId),
|
||||
data.labels,
|
||||
loginAccount)
|
||||
JsonFormat(ApiIssue(issue, RepositoryName(repository), ApiUser(loginAccount)))
|
||||
}) getOrElse NotFound()
|
||||
} else Unauthorized()
|
||||
|
||||
@@ -10,7 +10,7 @@ import gitbucket.core.util._
|
||||
import gitbucket.core.view
|
||||
import gitbucket.core.view.Markdown
|
||||
import io.github.gitbucket.scalatra.forms._
|
||||
import org.scalatra.Ok
|
||||
import org.scalatra.{BadRequest, Ok}
|
||||
|
||||
|
||||
class IssuesController extends IssuesControllerBase
|
||||
@@ -115,8 +115,15 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
|
||||
post("/:owner/:repository/issues/new", issueCreateForm)(readableUsersOnly { (form, repository) =>
|
||||
if(isIssueEditable(repository)){ // TODO Should this check is provided by authenticator?
|
||||
val issue = createIssue(repository, form.title, form.content, form.assignedUserName,
|
||||
form.milestoneId, form.labelNames.toArray.flatMap(_.split(",")))
|
||||
val issue = createIssue(
|
||||
repository,
|
||||
form.title,
|
||||
form.content,
|
||||
form.assignedUserName,
|
||||
form.milestoneId,
|
||||
form.labelNames.toArray.flatMap(_.split(",")),
|
||||
context.loginAccount.get)
|
||||
|
||||
redirect(s"/${issue.userName}/${issue.repositoryName}/issues/${issue.issueId}")
|
||||
} else Unauthorized()
|
||||
})
|
||||
@@ -293,7 +300,7 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
handleComment(issue, None, repository, Some("close"))
|
||||
}
|
||||
}
|
||||
case _ => // TODO BadRequest
|
||||
case _ => BadRequest()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,27 +1,29 @@
|
||||
package gitbucket.core.service
|
||||
|
||||
import gitbucket.core.controller.Context
|
||||
import gitbucket.core.model.Issue
|
||||
import gitbucket.core.model.{Account, Issue}
|
||||
import gitbucket.core.model.Profile.profile.simple.Session
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.util.Notifier
|
||||
import gitbucket.core.util.Implicits._
|
||||
|
||||
// TODO: Merged with IssuesService?
|
||||
trait IssueCreationService {
|
||||
|
||||
self: RepositoryService with WebHookIssueCommentService with LabelsService with IssuesService with ActivityService =>
|
||||
|
||||
def createIssue(repository: RepositoryInfo, title:String, body:Option[String],
|
||||
assiginee: Option[String], milestoneId: Option[Int], labelNames:Seq[String])(implicit context: Context, s:Session) : Issue = {
|
||||
val name = repository.name
|
||||
assignee: Option[String], milestoneId: Option[Int], labelNames: Seq[String],
|
||||
loginAccount: Account)(implicit context: Context, s: Session) : Issue = {
|
||||
|
||||
val owner = repository.owner
|
||||
val loginAccount = context.loginAccount.get
|
||||
val userName = loginAccount.userName
|
||||
val name = repository.name
|
||||
val userName = loginAccount.userName
|
||||
val manageable = isManageable(repository)
|
||||
|
||||
// insert issue
|
||||
val issueId = insertIssue(owner, name, userName, title, body,
|
||||
if (manageable) assiginee else None,
|
||||
if (manageable) assignee else None,
|
||||
if (manageable) milestoneId else None)
|
||||
val issue: Issue = getIssue(owner, name, issueId.toString).get
|
||||
|
||||
@@ -54,14 +56,14 @@ trait IssueCreationService {
|
||||
/**
|
||||
* Tests whether an logged-in user can manage issues.
|
||||
*/
|
||||
protected def isManageable(repository: RepositoryInfo)(implicit context: Context, s:Session): Boolean = {
|
||||
protected def isManageable(repository: RepositoryInfo)(implicit context: Context, s: Session): Boolean = {
|
||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether an logged-in user can post issues.
|
||||
*/
|
||||
protected def isIssueEditable(repository: RepositoryInfo)(implicit context: Context, s:Session): Boolean = {
|
||||
protected def isIssueEditable(repository: RepositoryInfo)(implicit context: Context, s: Session): Boolean = {
|
||||
repository.repository.options.issuesOption match {
|
||||
case "ALL" => !repository.repository.isPrivate && context.loginAccount.isDefined
|
||||
case "PUBLIC" => hasGuestRole(repository.owner, repository.name, context.loginAccount)
|
||||
|
||||
Reference in New Issue
Block a user