mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-05 04:56:02 +01:00
Fix warnings in controllers (#3674)
This commit is contained in:
@@ -42,7 +42,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
GpgKeyService & OneselfAuthenticator & UsersAuthenticator & GroupManagerAuthenticator & ReadableUsersAuthenticator &
|
GpgKeyService & OneselfAuthenticator & UsersAuthenticator & GroupManagerAuthenticator & ReadableUsersAuthenticator &
|
||||||
AccessTokenService & WebHookService & PrioritiesService & RepositoryCreationService =>
|
AccessTokenService & WebHookService & PrioritiesService & RepositoryCreationService =>
|
||||||
|
|
||||||
case class AccountNewForm(
|
private case class AccountNewForm(
|
||||||
userName: String,
|
userName: String,
|
||||||
password: String,
|
password: String,
|
||||||
fullName: String,
|
fullName: String,
|
||||||
@@ -53,7 +53,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
fileId: Option[String]
|
fileId: Option[String]
|
||||||
)
|
)
|
||||||
|
|
||||||
case class AccountEditForm(
|
private case class AccountEditForm(
|
||||||
password: Option[String],
|
password: Option[String],
|
||||||
fullName: String,
|
fullName: String,
|
||||||
mailAddress: String,
|
mailAddress: String,
|
||||||
@@ -64,15 +64,15 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
clearImage: Boolean
|
clearImage: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
case class SshKeyForm(title: String, publicKey: String)
|
private case class SshKeyForm(title: String, publicKey: String)
|
||||||
|
|
||||||
case class GpgKeyForm(title: String, publicKey: String)
|
private case class GpgKeyForm(title: String, publicKey: String)
|
||||||
|
|
||||||
case class PersonalTokenForm(note: String)
|
private case class PersonalTokenForm(note: String)
|
||||||
|
|
||||||
case class SyntaxHighlighterThemeForm(theme: String)
|
private case class SyntaxHighlighterThemeForm(theme: String)
|
||||||
|
|
||||||
val newForm = mapping(
|
private val newForm = mapping(
|
||||||
"userName" -> trim(label("User name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
"userName" -> trim(label("User name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
||||||
"password" -> trim(label("Password", text(required, maxlength(40)))),
|
"password" -> trim(label("Password", text(required, maxlength(40)))),
|
||||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||||
@@ -85,7 +85,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
"fileId" -> trim(label("File ID", optional(text())))
|
"fileId" -> trim(label("File ID", optional(text())))
|
||||||
)(AccountNewForm.apply)
|
)(AccountNewForm.apply)
|
||||||
|
|
||||||
val editForm = mapping(
|
private val editForm = mapping(
|
||||||
"password" -> trim(label("Password", optional(text(maxlength(40))))),
|
"password" -> trim(label("Password", optional(text(maxlength(40))))),
|
||||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||||
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress("userName")))),
|
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress("userName")))),
|
||||||
@@ -98,41 +98,41 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
"clearImage" -> trim(label("Clear image", boolean()))
|
"clearImage" -> trim(label("Clear image", boolean()))
|
||||||
)(AccountEditForm.apply)
|
)(AccountEditForm.apply)
|
||||||
|
|
||||||
val sshKeyForm = mapping(
|
private val sshKeyForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
||||||
"publicKey" -> trim2(label("Key", text(required, validPublicKey)))
|
"publicKey" -> trim2(label("Key", text(required, validPublicKey)))
|
||||||
)(SshKeyForm.apply)
|
)(SshKeyForm.apply)
|
||||||
|
|
||||||
val gpgKeyForm = mapping(
|
private val gpgKeyForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
||||||
"publicKey" -> label("Key", text(required, validGpgPublicKey))
|
"publicKey" -> label("Key", text(required, validGpgPublicKey))
|
||||||
)(GpgKeyForm.apply)
|
)(GpgKeyForm.apply)
|
||||||
|
|
||||||
val personalTokenForm = mapping(
|
private val personalTokenForm = mapping(
|
||||||
"note" -> trim(label("Token", text(required, maxlength(100))))
|
"note" -> trim(label("Token", text(required, maxlength(100))))
|
||||||
)(PersonalTokenForm.apply)
|
)(PersonalTokenForm.apply)
|
||||||
|
|
||||||
val syntaxHighlighterThemeForm = mapping(
|
private val syntaxHighlighterThemeForm = mapping(
|
||||||
"highlighterTheme" -> trim(label("Theme", text(required)))
|
"highlighterTheme" -> trim(label("Theme", text(required)))
|
||||||
)(SyntaxHighlighterThemeForm.apply)
|
)(SyntaxHighlighterThemeForm.apply)
|
||||||
|
|
||||||
val resetPasswordEmailForm = mapping(
|
private val resetPasswordEmailForm = mapping(
|
||||||
"mailAddress" -> trim(label("Email", text(required)))
|
"mailAddress" -> trim(label("Email", text(required)))
|
||||||
)(ResetPasswordEmailForm.apply)
|
)(ResetPasswordEmailForm.apply)
|
||||||
|
|
||||||
val resetPasswordForm = mapping(
|
private val resetPasswordForm = mapping(
|
||||||
"token" -> trim(label("Token", text(required))),
|
"token" -> trim(label("Token", text(required))),
|
||||||
"password" -> trim(label("Password", text(required, maxlength(40))))
|
"password" -> trim(label("Password", text(required, maxlength(40))))
|
||||||
)(ResetPasswordForm.apply)
|
)(ResetPasswordForm.apply)
|
||||||
|
|
||||||
case class NewGroupForm(
|
private case class NewGroupForm(
|
||||||
groupName: String,
|
groupName: String,
|
||||||
description: Option[String],
|
description: Option[String],
|
||||||
url: Option[String],
|
url: Option[String],
|
||||||
fileId: Option[String],
|
fileId: Option[String],
|
||||||
members: String
|
members: String
|
||||||
)
|
)
|
||||||
case class EditGroupForm(
|
private case class EditGroupForm(
|
||||||
groupName: String,
|
groupName: String,
|
||||||
description: Option[String],
|
description: Option[String],
|
||||||
url: Option[String],
|
url: Option[String],
|
||||||
@@ -140,15 +140,15 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
members: String,
|
members: String,
|
||||||
clearImage: Boolean
|
clearImage: Boolean
|
||||||
)
|
)
|
||||||
case class ResetPasswordEmailForm(
|
private case class ResetPasswordEmailForm(
|
||||||
mailAddress: String
|
mailAddress: String
|
||||||
)
|
)
|
||||||
case class ResetPasswordForm(
|
private case class ResetPasswordForm(
|
||||||
token: String,
|
token: String,
|
||||||
password: String
|
password: String
|
||||||
)
|
)
|
||||||
|
|
||||||
val newGroupForm = mapping(
|
private val newGroupForm = mapping(
|
||||||
"groupName" -> trim(label("Group name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
"groupName" -> trim(label("Group name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
||||||
"description" -> trim(label("Group description", optional(text()))),
|
"description" -> trim(label("Group description", optional(text()))),
|
||||||
"url" -> trim(label("URL", optional(text(maxlength(200))))),
|
"url" -> trim(label("URL", optional(text(maxlength(200))))),
|
||||||
@@ -156,7 +156,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
"members" -> trim(label("Members", text(required, members)))
|
"members" -> trim(label("Members", text(required, members)))
|
||||||
)(NewGroupForm.apply)
|
)(NewGroupForm.apply)
|
||||||
|
|
||||||
val editGroupForm = mapping(
|
private val editGroupForm = mapping(
|
||||||
"groupName" -> trim(label("Group name", text(required, maxlength(100), identifier))),
|
"groupName" -> trim(label("Group name", text(required, maxlength(100), identifier))),
|
||||||
"description" -> trim(label("Group description", optional(text()))),
|
"description" -> trim(label("Group description", optional(text()))),
|
||||||
"url" -> trim(label("URL", optional(text(maxlength(200))))),
|
"url" -> trim(label("URL", optional(text(maxlength(200))))),
|
||||||
@@ -165,7 +165,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
"clearImage" -> trim(label("Clear image", boolean()))
|
"clearImage" -> trim(label("Clear image", boolean()))
|
||||||
)(EditGroupForm.apply)
|
)(EditGroupForm.apply)
|
||||||
|
|
||||||
case class RepositoryCreationForm(
|
private case class RepositoryCreationForm(
|
||||||
owner: String,
|
owner: String,
|
||||||
name: String,
|
name: String,
|
||||||
description: Option[String],
|
description: Option[String],
|
||||||
@@ -174,7 +174,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
sourceUrl: Option[String]
|
sourceUrl: Option[String]
|
||||||
)
|
)
|
||||||
|
|
||||||
val newRepositoryForm = mapping(
|
private val newRepositoryForm = mapping(
|
||||||
"owner" -> trim(label("Owner", text(required, maxlength(100), identifier, existsAccount))),
|
"owner" -> trim(label("Owner", text(required, maxlength(100), identifier, existsAccount))),
|
||||||
"name" -> trim(label("Repository name", text(required, maxlength(100), repository, uniqueRepository))),
|
"name" -> trim(label("Repository name", text(required, maxlength(100), repository, uniqueRepository))),
|
||||||
"description" -> trim(label("Description", optional(text()))),
|
"description" -> trim(label("Description", optional(text()))),
|
||||||
@@ -183,21 +183,21 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
"sourceUrl" -> trim(label("Source URL", optionalRequired(_.value("initOption") == "COPY", text())))
|
"sourceUrl" -> trim(label("Source URL", optionalRequired(_.value("initOption") == "COPY", text())))
|
||||||
)(RepositoryCreationForm.apply)
|
)(RepositoryCreationForm.apply)
|
||||||
|
|
||||||
case class AccountForm(accountName: String)
|
private case class AccountForm(accountName: String)
|
||||||
|
|
||||||
val accountForm = mapping(
|
private val accountForm = mapping(
|
||||||
"account" -> trim(label("Group/User name", text(required, validAccountName)))
|
"account" -> trim(label("Group/User name", text(required, validAccountName)))
|
||||||
)(AccountForm.apply)
|
)(AccountForm.apply)
|
||||||
|
|
||||||
// for account web hook url addition.
|
// for account web hook url addition.
|
||||||
case class AccountWebHookForm(
|
private case class AccountWebHookForm(
|
||||||
url: String,
|
url: String,
|
||||||
events: Set[WebHook.Event],
|
events: Set[WebHook.Event],
|
||||||
ctype: WebHookContentType,
|
ctype: WebHookContentType,
|
||||||
token: Option[String]
|
token: Option[String]
|
||||||
)
|
)
|
||||||
|
|
||||||
def accountWebHookForm(update: Boolean) =
|
private def accountWebHookForm(update: Boolean) =
|
||||||
mapping(
|
mapping(
|
||||||
"url" -> trim(label("url", text(required, accountWebHook(update)))),
|
"url" -> trim(label("url", text(required, accountWebHook(update)))),
|
||||||
"events" -> accountWebhookEvents,
|
"events" -> accountWebhookEvents,
|
||||||
@@ -253,7 +253,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Members
|
// Members
|
||||||
case "members" if (account.isGroupAccount) => {
|
case "members" if account.isGroupAccount =>
|
||||||
val members = getGroupMembers(account.userName)
|
val members = getGroupMembers(account.userName)
|
||||||
gitbucket.core.account.html.members(
|
gitbucket.core.account.html.members(
|
||||||
account,
|
account,
|
||||||
@@ -261,10 +261,9 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
extraMailAddresses,
|
extraMailAddresses,
|
||||||
isGroupManager(context.loginAccount, members)
|
isGroupManager(context.loginAccount, members)
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
// Repositories
|
// Repositories
|
||||||
case _ => {
|
case _ =>
|
||||||
val members = getGroupMembers(account.userName)
|
val members = getGroupMembers(account.userName)
|
||||||
gitbucket.core.account.html.repositories(
|
gitbucket.core.account.html.repositories(
|
||||||
account,
|
account,
|
||||||
@@ -273,7 +272,6 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
extraMailAddresses,
|
extraMailAddresses,
|
||||||
isGroupManager(context.loginAccount, members)
|
isGroupManager(context.loginAccount, members)
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
}
|
||||||
@@ -281,7 +279,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
get("/:userName.atom") {
|
get("/:userName.atom") {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
contentType = "application/atom+xml; type=feed"
|
contentType = "application/atom+xml; type=feed"
|
||||||
helper.xml.feed(getActivitiesByUser(userName, true))
|
helper.xml.feed(getActivitiesByUser(userName, publicOnly = true))
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/:userName.keys") {
|
get("/:userName.keys") {
|
||||||
@@ -340,7 +338,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
updateImage(userName, form.fileId, form.clearImage)
|
updateImage(userName, form.fileId, form.clearImage)
|
||||||
updateAccountExtraMailAddresses(userName, form.extraMailAddresses.filter(_ != ""))
|
updateAccountExtraMailAddresses(userName, form.extraMailAddresses.filter(_ != ""))
|
||||||
flash.update("info", "Account information has been updated.")
|
flash.update("info", "Account information has been updated.")
|
||||||
redirect(s"/${userName}/_edit")
|
redirect(s"/$userName/_edit")
|
||||||
|
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
@@ -348,10 +346,10 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
get("/:userName/_delete")(oneselfOnly {
|
get("/:userName/_delete")(oneselfOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
|
|
||||||
getAccountByUserName(userName, true).map { account =>
|
getAccountByUserName(userName, includeRemoved = true).map { account =>
|
||||||
if (isLastAdministrator(account)) {
|
if (isLastAdministrator(account)) {
|
||||||
flash.update("error", "Account can't be removed because this is last one administrator.")
|
flash.update("error", "Account can't be removed because this is last one administrator.")
|
||||||
redirect(s"/${userName}/_edit")
|
redirect(s"/$userName/_edit")
|
||||||
} else {
|
} else {
|
||||||
// // Remove repositories
|
// // Remove repositories
|
||||||
// getRepositoryNamesOfUser(userName).foreach { repositoryName =>
|
// getRepositoryNamesOfUser(userName).foreach { repositoryName =>
|
||||||
@@ -361,7 +359,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
// FileUtils.deleteDirectory(getTemporaryDir(userName, repositoryName))
|
// FileUtils.deleteDirectory(getTemporaryDir(userName, repositoryName))
|
||||||
// }
|
// }
|
||||||
suspendAccount(account)
|
suspendAccount(account)
|
||||||
session.invalidate
|
session.invalidate()
|
||||||
redirect("/")
|
redirect("/")
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
@@ -377,14 +375,14 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
post("/:userName/_ssh", sshKeyForm)(oneselfOnly { form =>
|
post("/:userName/_ssh", sshKeyForm)(oneselfOnly { form =>
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
addPublicKey(userName, form.title, form.publicKey)
|
addPublicKey(userName, form.title, form.publicKey)
|
||||||
redirect(s"/${userName}/_ssh")
|
redirect(s"/$userName/_ssh")
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:userName/_ssh/delete/:id")(oneselfOnly {
|
get("/:userName/_ssh/delete/:id")(oneselfOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
val sshKeyId = params("id").toInt
|
val sshKeyId = params("id").toInt
|
||||||
deletePublicKey(userName, sshKeyId)
|
deletePublicKey(userName, sshKeyId)
|
||||||
redirect(s"/${userName}/_ssh")
|
redirect(s"/$userName/_ssh")
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:userName/_gpg")(oneselfOnly {
|
get("/:userName/_gpg")(oneselfOnly {
|
||||||
@@ -398,14 +396,14 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
post("/:userName/_gpg", gpgKeyForm)(oneselfOnly { form =>
|
post("/:userName/_gpg", gpgKeyForm)(oneselfOnly { form =>
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
addGpgPublicKey(userName, form.title, form.publicKey)
|
addGpgPublicKey(userName, form.title, form.publicKey)
|
||||||
redirect(s"/${userName}/_gpg")
|
redirect(s"/$userName/_gpg")
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:userName/_gpg/delete/:id")(oneselfOnly {
|
get("/:userName/_gpg/delete/:id")(oneselfOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
val keyId = params("id").toInt
|
val keyId = params("id").toInt
|
||||||
deleteGpgPublicKey(userName, keyId)
|
deleteGpgPublicKey(userName, keyId)
|
||||||
redirect(s"/${userName}/_gpg")
|
redirect(s"/$userName/_gpg")
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:userName/_application")(oneselfOnly {
|
get("/:userName/_application")(oneselfOnly {
|
||||||
@@ -413,13 +411,12 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
getAccountByUserName(userName).map { x =>
|
getAccountByUserName(userName).map { x =>
|
||||||
var tokens = getAccessTokens(x.userName)
|
var tokens = getAccessTokens(x.userName)
|
||||||
val generatedToken = flash.get("generatedToken") match {
|
val generatedToken = flash.get("generatedToken") match {
|
||||||
case Some((tokenId: Int, token: String)) => {
|
case Some((tokenId: Int, token: String)) =>
|
||||||
val gt = tokens.find(_.accessTokenId == tokenId)
|
val gt = tokens.find(_.accessTokenId == tokenId)
|
||||||
gt.map { t =>
|
gt.map { t =>
|
||||||
tokens = tokens.filterNot(_ == t)
|
tokens = tokens.filterNot(_ == t)
|
||||||
(t, token)
|
(t, token)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
case _ => None
|
case _ => None
|
||||||
}
|
}
|
||||||
html.application(x, tokens, generatedToken)
|
html.application(x, tokens, generatedToken)
|
||||||
@@ -428,18 +425,18 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
post("/:userName/_personalToken", personalTokenForm)(oneselfOnly { form =>
|
post("/:userName/_personalToken", personalTokenForm)(oneselfOnly { form =>
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName).foreach { x =>
|
getAccountByUserName(userName).foreach { _ =>
|
||||||
val (tokenId, token) = generateAccessToken(userName, form.note)
|
val (tokenId, token) = generateAccessToken(userName, form.note)
|
||||||
flash.update("generatedToken", (tokenId, token))
|
flash.update("generatedToken", (tokenId, token))
|
||||||
}
|
}
|
||||||
redirect(s"/${userName}/_application")
|
redirect(s"/$userName/_application")
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:userName/_personalToken/delete/:id")(oneselfOnly {
|
get("/:userName/_personalToken/delete/:id")(oneselfOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
val tokenId = params("id").toInt
|
val tokenId = params("id").toInt
|
||||||
deleteAccessToken(userName, tokenId)
|
deleteAccessToken(userName, tokenId)
|
||||||
redirect(s"/${userName}/_application")
|
redirect(s"/$userName/_application")
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -462,7 +459,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
post("/:userName/_preferences/highlighter", syntaxHighlighterThemeForm)(oneselfOnly { form =>
|
post("/:userName/_preferences/highlighter", syntaxHighlighterThemeForm)(oneselfOnly { form =>
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
addOrUpdateAccountPreference(userName, form.theme)
|
addOrUpdateAccountPreference(userName, form.theme)
|
||||||
redirect(s"/${userName}/_preferences")
|
redirect(s"/$userName/_preferences")
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:userName/_hooks")(managersOnly {
|
get("/:userName/_hooks")(managersOnly {
|
||||||
@@ -479,7 +476,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName).map { account =>
|
getAccountByUserName(userName).map { account =>
|
||||||
val webhook = AccountWebHook(userName, "", WebHookContentType.FORM, None)
|
val webhook = AccountWebHook(userName, "", WebHookContentType.FORM, None)
|
||||||
html.edithook(webhook, Set(WebHook.Push), account, true)
|
html.edithook(webhook, Set(WebHook.Push), account, create = true)
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -490,7 +487,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
addAccountWebHook(userName, form.url, form.events, form.ctype, form.token)
|
addAccountWebHook(userName, form.url, form.events, form.ctype, form.token)
|
||||||
flash.update("info", s"Webhook ${form.url} created")
|
flash.update("info", s"Webhook ${form.url} created")
|
||||||
redirect(s"/${userName}/_hooks")
|
redirect(s"/$userName/_hooks")
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -500,7 +497,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
deleteAccountWebHook(userName, params("url"))
|
deleteAccountWebHook(userName, params("url"))
|
||||||
flash.update("info", s"Webhook ${params("url")} deleted")
|
flash.update("info", s"Webhook ${params("url")} deleted")
|
||||||
redirect(s"/${userName}/_hooks")
|
redirect(s"/$userName/_hooks")
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -510,7 +507,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName).flatMap { account =>
|
getAccountByUserName(userName).flatMap { account =>
|
||||||
getAccountWebHook(userName, params("url")).map { case (webhook, events) =>
|
getAccountWebHook(userName, params("url")).map { case (webhook, events) =>
|
||||||
html.edithook(webhook, events, account, false)
|
html.edithook(webhook, events, account, create = false)
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
@@ -522,7 +519,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
updateAccountWebHook(userName, form.url, form.events, form.ctype, form.token)
|
updateAccountWebHook(userName, form.url, form.events, form.ctype, form.token)
|
||||||
flash.update("info", s"webhook ${form.url} updated")
|
flash.update("info", s"webhook ${form.url} updated")
|
||||||
redirect(s"/${userName}/_hooks")
|
redirect(s"/$userName/_hooks")
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -530,8 +527,8 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
*/
|
*/
|
||||||
ajaxPost("/:userName/_hooks/test")(managersOnly {
|
ajaxPost("/:userName/_hooks/test")(managersOnly {
|
||||||
// TODO Is it possible to merge with [[RepositorySettingsController.ajaxPost]]?
|
// TODO Is it possible to merge with [[RepositorySettingsController.ajaxPost]]?
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration.*
|
||||||
import scala.concurrent._
|
import scala.concurrent.*
|
||||||
import scala.util.control.NonFatal
|
import scala.util.control.NonFatal
|
||||||
import org.apache.http.util.EntityUtils
|
import org.apache.http.util.EntityUtils
|
||||||
import scala.concurrent.ExecutionContext.Implicits.global
|
import scala.concurrent.ExecutionContext.Implicits.global
|
||||||
@@ -555,10 +552,10 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
callWebHook(WebHook.Push, List(dummyWebHookInfo), dummyPayload, context.settings).head
|
callWebHook(WebHook.Push, List(dummyWebHookInfo), dummyPayload, context.settings).head
|
||||||
|
|
||||||
val toErrorMap: PartialFunction[Throwable, Map[String, String]] = {
|
val toErrorMap: PartialFunction[Throwable, Map[String, String]] = {
|
||||||
case e: java.net.UnknownHostException => Map("error" -> ("Unknown host " + e.getMessage))
|
case e: java.net.UnknownHostException => Map("error" -> s"Unknown host ${e.getMessage}")
|
||||||
case e: java.lang.IllegalArgumentException => Map("error" -> ("invalid url"))
|
case _: java.lang.IllegalArgumentException => Map("error" -> "invalid url")
|
||||||
case e: org.apache.http.client.ClientProtocolException => Map("error" -> ("invalid url"))
|
case _: org.apache.http.client.ClientProtocolException => Map("error" -> "invalid url")
|
||||||
case NonFatal(e) => Map("error" -> (s"${e.getClass} ${e.getMessage}"))
|
case NonFatal(e) => Map("error" -> s"${e.getClass} ${e.getMessage}")
|
||||||
}
|
}
|
||||||
|
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
@@ -580,9 +577,9 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
resFuture
|
resFuture
|
||||||
.map(res =>
|
.map(res =>
|
||||||
Map(
|
Map(
|
||||||
"status" -> res.getStatusLine(),
|
"status" -> res.getStatusLine,
|
||||||
"body" -> EntityUtils.toString(res.getEntity()),
|
"body" -> EntityUtils.toString(res.getEntity),
|
||||||
"headers" -> _headers(res.getAllHeaders())
|
"headers" -> _headers(res.getAllHeaders)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.recover(toErrorMap),
|
.recover(toErrorMap),
|
||||||
@@ -609,11 +606,11 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
pbkdf2_sha256(form.password),
|
pbkdf2_sha256(form.password),
|
||||||
form.fullName,
|
form.fullName,
|
||||||
form.mailAddress,
|
form.mailAddress,
|
||||||
false,
|
isAdmin = false,
|
||||||
form.description,
|
form.description,
|
||||||
form.url
|
form.url
|
||||||
)
|
)
|
||||||
updateImage(form.userName, form.fileId, false)
|
updateImage(form.userName, form.fileId, clearImage = false)
|
||||||
updateAccountExtraMailAddresses(form.userName, form.extraMailAddresses.filter(_ != ""))
|
updateAccountExtraMailAddresses(form.userName, form.extraMailAddresses.filter(_ != ""))
|
||||||
redirect("/signin")
|
redirect("/signin")
|
||||||
} else NotFound()
|
} else NotFound()
|
||||||
@@ -638,7 +635,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|You requested to reset the password for your GitBucket account.
|
|You requested to reset the password for your GitBucket account.
|
||||||
|If you are not sure about the request, you can ignore this email.
|
|If you are not sure about the request, you can ignore this email.
|
||||||
|Otherwise, click the following link to set the new password:
|
|Otherwise, click the following link to set the new password:
|
||||||
|${context.baseUrl}/reset/form/${token}
|
|${context.baseUrl}/reset/form/$token
|
||||||
|""".stripMargin
|
|""".stripMargin
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -678,7 +675,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
get("/groups/new")(usersOnly {
|
get("/groups/new")(usersOnly {
|
||||||
context.withLoginAccount { loginAccount =>
|
context.withLoginAccount { loginAccount =>
|
||||||
html.creategroup(List(GroupMember("", loginAccount.userName, true)))
|
html.creategroup(List(GroupMember("", loginAccount.userName, isManager = true)))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -695,13 +692,13 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
}
|
}
|
||||||
.toList
|
.toList
|
||||||
)
|
)
|
||||||
updateImage(form.groupName, form.fileId, false)
|
updateImage(form.groupName, form.fileId, clearImage = false)
|
||||||
redirect(s"/${form.groupName}")
|
redirect(s"/${form.groupName}")
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:groupName/_editgroup")(managersOnly {
|
get("/:groupName/_editgroup")(managersOnly {
|
||||||
val groupName = params("groupName")
|
val groupName = params("groupName")
|
||||||
getAccountByUserName(groupName, true).map { account =>
|
getAccountByUserName(groupName, includeRemoved = true).map { account =>
|
||||||
html.editgroup(account, getGroupMembers(groupName), flash.get("info"))
|
html.editgroup(account, getGroupMembers(groupName), flash.get("info"))
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
@@ -711,8 +708,8 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
// Remove from GROUP_MEMBER
|
// Remove from GROUP_MEMBER
|
||||||
updateGroupMembers(groupName, Nil)
|
updateGroupMembers(groupName, Nil)
|
||||||
// Disable group
|
// Disable group
|
||||||
getAccountByUserName(groupName, false).foreach { account =>
|
getAccountByUserName(groupName, includeRemoved = false).foreach { account =>
|
||||||
updateGroup(groupName, account.description, account.url, true)
|
updateGroup(groupName, account.description, account.url, removed = true)
|
||||||
}
|
}
|
||||||
// // Remove repositories
|
// // Remove repositories
|
||||||
// getRepositoryNamesOfUser(groupName).foreach { repositoryName =>
|
// getRepositoryNamesOfUser(groupName).foreach { repositoryName =>
|
||||||
@@ -735,8 +732,8 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
}
|
}
|
||||||
.toList
|
.toList
|
||||||
|
|
||||||
getAccountByUserName(groupName, true).map { account =>
|
getAccountByUserName(groupName, includeRemoved = true).map { _ =>
|
||||||
updateGroup(groupName, form.description, form.url, false)
|
updateGroup(groupName, form.description, form.url, removed = false)
|
||||||
|
|
||||||
// Update GROUP_MEMBER
|
// Update GROUP_MEMBER
|
||||||
updateGroupMembers(form.groupName, members)
|
updateGroupMembers(form.groupName, members)
|
||||||
@@ -751,7 +748,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
updateImage(form.groupName, form.fileId, form.clearImage)
|
updateImage(form.groupName, form.fileId, form.clearImage)
|
||||||
|
|
||||||
flash.update("info", "Account information has been updated.")
|
flash.update("info", "Account information has been updated.")
|
||||||
redirect(s"/${groupName}/_editgroup")
|
redirect(s"/$groupName/_editgroup")
|
||||||
|
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
@@ -819,7 +816,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
repository,
|
repository,
|
||||||
(groups zip managerPermissions).sortBy(_._1)
|
(groups zip managerPermissions).sortBy(_._1)
|
||||||
)
|
)
|
||||||
case _ => redirect(s"/${loginUserName}")
|
case _ => redirect(s"/$loginUserName")
|
||||||
}
|
}
|
||||||
} else BadRequest()
|
} else BadRequest()
|
||||||
}
|
}
|
||||||
@@ -835,7 +832,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
if (getRepository(accountName, repository.name).isDefined) {
|
if (getRepository(accountName, repository.name).isDefined) {
|
||||||
// redirect to the repository if repository already exists
|
// redirect to the repository if repository already exists
|
||||||
redirect(s"/${accountName}/${repository.name}")
|
redirect(s"/$accountName/${repository.name}")
|
||||||
} else if (!canCreateRepository(accountName, loginAccount)) {
|
} else if (!canCreateRepository(accountName, loginAccount)) {
|
||||||
// Permission error
|
// Permission error
|
||||||
Forbidden()
|
Forbidden()
|
||||||
@@ -843,7 +840,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
// fork repository asynchronously
|
// fork repository asynchronously
|
||||||
forkRepository(accountName, repository, loginUserName)
|
forkRepository(accountName, repository, loginUserName)
|
||||||
// redirect to the repository
|
// redirect to the repository
|
||||||
redirect(s"/${accountName}/${repository.name}")
|
redirect(s"/$accountName/${repository.name}")
|
||||||
}
|
}
|
||||||
} else Forbidden()
|
} else Forbidden()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import gitbucket.core.api._
|
import gitbucket.core.api.*
|
||||||
import gitbucket.core.controller.api._
|
import gitbucket.core.controller.api.*
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service.*
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits.*
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util.*
|
||||||
import gitbucket.core.plugin.PluginRegistry
|
import gitbucket.core.plugin.PluginRegistry
|
||||||
|
|
||||||
class ApiController
|
class ApiController
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package gitbucket.core.controller
|
|||||||
|
|
||||||
import gitbucket.core.dashboard.html
|
import gitbucket.core.dashboard.html
|
||||||
import gitbucket.core.model.Account
|
import gitbucket.core.model.Account
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service.*
|
||||||
import gitbucket.core.util.{Keys, UsersAuthenticator}
|
import gitbucket.core.util.UsersAuthenticator
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits.*
|
||||||
import gitbucket.core.service.IssuesService._
|
import gitbucket.core.service.IssuesService.*
|
||||||
import gitbucket.core.service.ActivityService._
|
import gitbucket.core.service.ActivityService.*
|
||||||
|
|
||||||
class DashboardController
|
class DashboardController
|
||||||
extends DashboardControllerBase
|
extends DashboardControllerBase
|
||||||
@@ -91,7 +91,7 @@ trait DashboardControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
private def getOrCreateCondition(key: String, filter: String, userName: String) = {
|
private def getOrCreateCondition(filter: String, userName: String) = {
|
||||||
val condition = IssueSearchCondition(request)
|
val condition = IssueSearchCondition(request)
|
||||||
|
|
||||||
filter match {
|
filter match {
|
||||||
@@ -102,11 +102,11 @@ trait DashboardControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def searchIssues(loginAccount: Account, filter: String) = {
|
private def searchIssues(loginAccount: Account, filter: String) = {
|
||||||
import IssuesService._
|
import IssuesService.*
|
||||||
|
|
||||||
val userName = loginAccount.userName
|
val userName = loginAccount.userName
|
||||||
val condition = getOrCreateCondition(Keys.Session.DashboardIssues, filter, userName)
|
val condition = getOrCreateCondition(filter, userName)
|
||||||
val userRepos = getUserRepositories(userName, true).map(repo => repo.owner -> repo.name)
|
val userRepos = getUserRepositories(userName, withoutPhysicalInfo = true).map(repo => repo.owner -> repo.name)
|
||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
val issues = searchIssue(condition, IssueSearchOption.Issues, (page - 1) * IssueLimit, IssueLimit, userRepos*)
|
val issues = searchIssue(condition, IssueSearchOption.Issues, (page - 1) * IssueLimit, IssueLimit, userRepos*)
|
||||||
|
|
||||||
@@ -133,11 +133,11 @@ trait DashboardControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def searchPullRequests(loginAccount: Account, filter: String) = {
|
private def searchPullRequests(loginAccount: Account, filter: String) = {
|
||||||
import IssuesService._
|
import IssuesService.*
|
||||||
import PullRequestService._
|
import PullRequestService.*
|
||||||
|
|
||||||
val userName = loginAccount.userName
|
val userName = loginAccount.userName
|
||||||
val condition = getOrCreateCondition(Keys.Session.DashboardPulls, filter, userName)
|
val condition = getOrCreateCondition(filter, userName)
|
||||||
val allRepos = getAllRepositories(userName)
|
val allRepos = getAllRepositories(userName)
|
||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
val issues = searchIssue(
|
val issues = searchIssue(
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class FileUploadController
|
|||||||
execute(
|
execute(
|
||||||
{ (file, fileId) =>
|
{ (file, fileId) =>
|
||||||
val fileName = file.getName
|
val fileName = file.getName
|
||||||
LockUtil.lock(s"${owner}/${repository}/wiki") {
|
LockUtil.lock(s"$owner/$repository/wiki") {
|
||||||
Using.resource(Git.open(Directory.getWikiRepositoryDir(owner, repository))) { git =>
|
Using.resource(Git.open(Directory.getWikiRepositoryDir(owner, repository))) { git =>
|
||||||
val builder = DirCache.newInCore.builder()
|
val builder = DirCache.newInCore.builder()
|
||||||
val inserter = git.getRepository.newObjectInserter()
|
val inserter = git.getRepository.newObjectInserter()
|
||||||
@@ -108,7 +108,7 @@ class FileUploadController
|
|||||||
)
|
)
|
||||||
builder.finish()
|
builder.finish()
|
||||||
|
|
||||||
val newHeadId = JGitUtil.createNewCommit(
|
JGitUtil.createNewCommit(
|
||||||
git,
|
git,
|
||||||
inserter,
|
inserter,
|
||||||
headId,
|
headId,
|
||||||
@@ -116,7 +116,7 @@ class FileUploadController
|
|||||||
Constants.HEAD,
|
Constants.HEAD,
|
||||||
loginAccount.fullName,
|
loginAccount.fullName,
|
||||||
loginAccount.mailAddress,
|
loginAccount.mailAddress,
|
||||||
s"Uploaded ${fileName}"
|
s"Uploaded $fileName"
|
||||||
)
|
)
|
||||||
|
|
||||||
fileName
|
fileName
|
||||||
@@ -151,7 +151,7 @@ class FileUploadController
|
|||||||
}
|
}
|
||||||
|
|
||||||
post("/import") {
|
post("/import") {
|
||||||
import JDBCUtil._
|
import JDBCUtil.*
|
||||||
setMultipartConfig()
|
setMultipartConfig()
|
||||||
session.get(Keys.Session.LoginAccount).collect {
|
session.get(Keys.Session.LoginAccount).collect {
|
||||||
case loginAccount: Account if loginAccount.isAdmin =>
|
case loginAccount: Account if loginAccount.isAdmin =>
|
||||||
@@ -168,13 +168,13 @@ class FileUploadController
|
|||||||
private def setMultipartConfig(): Unit = {
|
private def setMultipartConfig(): Unit = {
|
||||||
val settings = loadSystemSettings()
|
val settings = loadSystemSettings()
|
||||||
val config = MultipartConfig(maxFileSize = Some(settings.upload.maxFileSize))
|
val config = MultipartConfig(maxFileSize = Some(settings.upload.maxFileSize))
|
||||||
config.apply(request.getServletContext())
|
config.apply(request.getServletContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
private def setMultipartConfigForLargeFile(): Unit = {
|
private def setMultipartConfigForLargeFile(): Unit = {
|
||||||
val settings = loadSystemSettings()
|
val settings = loadSystemSettings()
|
||||||
val config = MultipartConfig(maxFileSize = Some(settings.upload.largeMaxFileSize))
|
val config = MultipartConfig(maxFileSize = Some(settings.upload.largeMaxFileSize))
|
||||||
config.apply(request.getServletContext())
|
config.apply(request.getServletContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
private def onlyWikiEditable(owner: String, repository: String, loginAccount: Account)(action: => Any): Any = {
|
private def onlyWikiEditable(owner: String, repository: String, loginAccount: Account)(action: => Any): Any = {
|
||||||
@@ -191,7 +191,7 @@ class FileUploadController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def execute(f: (FileItem, String) => Unit, mimeTypeChecker: (String) => Boolean) =
|
private def execute(f: (FileItem, String) => Unit, mimeTypeChecker: String => Boolean) =
|
||||||
fileParams.get("file") match {
|
fileParams.get("file") match {
|
||||||
case Some(file) if mimeTypeChecker(file.name) =>
|
case Some(file) if mimeTypeChecker(file.name) =>
|
||||||
val fileId = FileUtil.generateFileId
|
val fileId = FileUtil.generateFileId
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ import com.nimbusds.oauth2.sdk.id.State
|
|||||||
import com.nimbusds.openid.connect.sdk.Nonce
|
import com.nimbusds.openid.connect.sdk.Nonce
|
||||||
import gitbucket.core.helper.xml
|
import gitbucket.core.helper.xml
|
||||||
import gitbucket.core.model.Account
|
import gitbucket.core.model.Account
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service.*
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits.*
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util.*
|
||||||
import gitbucket.core.view.helpers._
|
import gitbucket.core.view.helpers.*
|
||||||
import org.scalatra.Ok
|
import org.scalatra.Ok
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms.*
|
||||||
|
|
||||||
import gitbucket.core.service.ActivityService._
|
import gitbucket.core.service.ActivityService.*
|
||||||
|
|
||||||
class IndexController
|
class IndexController
|
||||||
extends IndexControllerBase
|
extends IndexControllerBase
|
||||||
@@ -37,9 +37,9 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
self: RepositoryService & ActivityService & AccountService & RepositorySearchService & UsersAuthenticator &
|
self: RepositoryService & ActivityService & AccountService & RepositorySearchService & UsersAuthenticator &
|
||||||
ReferrerAuthenticator & AccessTokenService & AccountFederationService & OpenIDConnectService =>
|
ReferrerAuthenticator & AccessTokenService & AccountFederationService & OpenIDConnectService =>
|
||||||
|
|
||||||
case class SignInForm(userName: String, password: String, hash: Option[String])
|
private case class SignInForm(userName: String, password: String, hash: Option[String])
|
||||||
|
|
||||||
val signinForm = mapping(
|
private val signinForm = mapping(
|
||||||
"userName" -> trim(label("Username", text(required))),
|
"userName" -> trim(label("Username", text(required))),
|
||||||
"password" -> trim(label("Password", text(required))),
|
"password" -> trim(label("Password", text(required))),
|
||||||
"hash" -> trim(optional(text()))
|
"hash" -> trim(optional(text()))
|
||||||
@@ -53,13 +53,13 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
//
|
//
|
||||||
// case class SearchForm(query: String, owner: String, repository: String)
|
// case class SearchForm(query: String, owner: String, repository: String)
|
||||||
|
|
||||||
case class OidcAuthContext(state: State, nonce: Nonce, redirectBackURI: String)
|
private case class OidcAuthContext(state: State, nonce: Nonce, redirectBackURI: String)
|
||||||
case class OidcSessionContext(token: JWT)
|
private case class OidcSessionContext(token: JWT)
|
||||||
|
|
||||||
get("/") {
|
get("/") {
|
||||||
context.loginAccount
|
context.loginAccount
|
||||||
.map { account =>
|
.map { account =>
|
||||||
val visibleOwnerSet: Set[String] = Set(account.userName) ++ getGroupsByUserName(account.userName)
|
// val visibleOwnerSet: Set[String] = Set(account.userName) ++ getGroupsByUserName(account.userName)
|
||||||
if (!isNewsFeedEnabled) {
|
if (!isNewsFeedEnabled) {
|
||||||
redirect("/dashboard/repos")
|
redirect("/dashboard/repos")
|
||||||
} else {
|
} else {
|
||||||
@@ -232,7 +232,7 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
val group = params("group").toBoolean
|
val group = params("group").toBoolean
|
||||||
org.json4s.jackson.Serialization.write(
|
org.json4s.jackson.Serialization.write(
|
||||||
Map(
|
Map(
|
||||||
"options" -> (
|
"options" ->
|
||||||
getAllUsers(includeRemoved = false)
|
getAllUsers(includeRemoved = false)
|
||||||
.withFilter { t =>
|
.withFilter { t =>
|
||||||
(user, group) match {
|
(user, group) match {
|
||||||
@@ -251,7 +251,6 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
"value" -> t.userName
|
"value" -> t.userName
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ package gitbucket.core.controller
|
|||||||
|
|
||||||
import gitbucket.core.issues.html
|
import gitbucket.core.issues.html
|
||||||
import gitbucket.core.model.{Account, CustomFieldBehavior}
|
import gitbucket.core.model.{Account, CustomFieldBehavior}
|
||||||
import gitbucket.core.service.IssuesService._
|
import gitbucket.core.service.IssuesService.*
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service.*
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits.*
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util.*
|
||||||
import gitbucket.core.view
|
import gitbucket.core.view
|
||||||
import gitbucket.core.view.Markdown
|
import gitbucket.core.view.Markdown
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms.*
|
||||||
import org.scalatra.{BadRequest, Ok}
|
import org.scalatra.{BadRequest, Ok}
|
||||||
|
|
||||||
class IssuesController
|
class IssuesController
|
||||||
@@ -39,7 +39,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
ReferrerAuthenticator & WritableUsersAuthenticator & PullRequestService & WebHookIssueCommentService &
|
ReferrerAuthenticator & WritableUsersAuthenticator & PullRequestService & WebHookIssueCommentService &
|
||||||
PrioritiesService =>
|
PrioritiesService =>
|
||||||
|
|
||||||
case class IssueCreateForm(
|
private case class IssueCreateForm(
|
||||||
title: String,
|
title: String,
|
||||||
content: Option[String],
|
content: Option[String],
|
||||||
assigneeUserNames: Option[String],
|
assigneeUserNames: Option[String],
|
||||||
@@ -47,10 +47,10 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
priorityId: Option[Int],
|
priorityId: Option[Int],
|
||||||
labelNames: Option[String]
|
labelNames: Option[String]
|
||||||
)
|
)
|
||||||
case class CommentForm(issueId: Int, content: String)
|
private case class CommentForm(issueId: Int, content: String)
|
||||||
case class IssueStateForm(issueId: Int, content: Option[String])
|
private case class IssueStateForm(issueId: Int, content: Option[String])
|
||||||
|
|
||||||
val issueCreateForm = mapping(
|
private val issueCreateForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required))),
|
"title" -> trim(label("Title", text(required))),
|
||||||
"content" -> trim(optional(text())),
|
"content" -> trim(optional(text())),
|
||||||
"assigneeUserNames" -> trim(optional(text())),
|
"assigneeUserNames" -> trim(optional(text())),
|
||||||
@@ -59,19 +59,19 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
"labelNames" -> trim(optional(text()))
|
"labelNames" -> trim(optional(text()))
|
||||||
)(IssueCreateForm.apply)
|
)(IssueCreateForm.apply)
|
||||||
|
|
||||||
val issueTitleEditForm = mapping(
|
private val issueTitleEditForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required)))
|
"title" -> trim(label("Title", text(required)))
|
||||||
)(x => x)
|
)(x => x)
|
||||||
val issueEditForm = mapping(
|
private val issueEditForm = mapping(
|
||||||
"content" -> trim(optional(text()))
|
"content" -> trim(optional(text()))
|
||||||
)(x => x)
|
)(x => x)
|
||||||
|
|
||||||
val commentForm = mapping(
|
private val commentForm = mapping(
|
||||||
"issueId" -> label("Issue Id", number()),
|
"issueId" -> label("Issue Id", number()),
|
||||||
"content" -> trim(label("Comment", text(required)))
|
"content" -> trim(label("Comment", text(required)))
|
||||||
)(CommentForm.apply)
|
)(CommentForm.apply)
|
||||||
|
|
||||||
val issueStateForm = mapping(
|
private val issueStateForm = mapping(
|
||||||
"issueId" -> label("Issue Id", number()),
|
"issueId" -> label("Issue Id", number()),
|
||||||
"content" -> trim(optional(text()))
|
"content" -> trim(optional(text()))
|
||||||
)(IssueStateForm.apply)
|
)(IssueStateForm.apply)
|
||||||
@@ -98,7 +98,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
val issueId = params("id")
|
val issueId = params("id")
|
||||||
getIssue(repository.owner, repository.name, issueId) map { issue =>
|
getIssue(repository.owner, repository.name, issueId) map { issue =>
|
||||||
if (issue.isPullRequest) {
|
if (issue.isPullRequest) {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
redirect(s"/${repository.owner}/${repository.name}/pull/$issueId")
|
||||||
} else {
|
} else {
|
||||||
html.issue(
|
html.issue(
|
||||||
issue,
|
issue,
|
||||||
@@ -219,7 +219,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
.filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName, loginAccount))
|
.filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName, loginAccount))
|
||||||
handleComment(issue, Some(form.content), repository, actionOpt) map { case (issue, id) =>
|
handleComment(issue, Some(form.content), repository, actionOpt) map { case (issue, id) =>
|
||||||
redirect(
|
redirect(
|
||||||
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-${id}"
|
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-$id"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
@@ -235,7 +235,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
.filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName, loginAccount))
|
.filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName, loginAccount))
|
||||||
handleComment(issue, form.content, repository, actionOpt) map { case (issue, id) =>
|
handleComment(issue, form.content, repository, actionOpt) map { case (issue, id) =>
|
||||||
redirect(
|
redirect(
|
||||||
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-${id}"
|
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-$id"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
@@ -330,30 +330,36 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/:id/label/new")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/label/new")(writableUsersOnly { repository =>
|
||||||
val issueId = params("id").toInt
|
val issueId = params("id").toInt
|
||||||
registerIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, true)
|
registerIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, insertComment = true)
|
||||||
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/:id/label/delete")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/label/delete")(writableUsersOnly { repository =>
|
||||||
val issueId = params("id").toInt
|
val issueId = params("id").toInt
|
||||||
deleteIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, true)
|
deleteIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, insertComment = true)
|
||||||
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/:id/assignee/new")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/assignee/new")(writableUsersOnly { repository =>
|
||||||
val issueId = params("id").toInt
|
val issueId = params("id").toInt
|
||||||
registerIssueAssignee(repository.owner, repository.name, issueId, params("assigneeUserName"), true)
|
registerIssueAssignee(repository.owner, repository.name, issueId, params("assigneeUserName"), insertComment = true)
|
||||||
Ok()
|
Ok()
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/:id/assignee/delete")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/assignee/delete")(writableUsersOnly { repository =>
|
||||||
val issueId = params("id").toInt
|
val issueId = params("id").toInt
|
||||||
deleteIssueAssignee(repository.owner, repository.name, issueId, params("assigneeUserName"), true)
|
deleteIssueAssignee(repository.owner, repository.name, issueId, params("assigneeUserName"), insertComment = true)
|
||||||
Ok()
|
Ok()
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/:id/milestone")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/milestone")(writableUsersOnly { repository =>
|
||||||
updateMilestoneId(repository.owner, repository.name, params("id").toInt, milestoneId("milestoneId"), true)
|
updateMilestoneId(
|
||||||
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
params("id").toInt,
|
||||||
|
milestoneId("milestoneId"),
|
||||||
|
insertComment = true
|
||||||
|
)
|
||||||
milestoneId("milestoneId").map { milestoneId =>
|
milestoneId("milestoneId").map { milestoneId =>
|
||||||
getMilestonesWithIssueCount(repository.owner, repository.name)
|
getMilestonesWithIssueCount(repository.owner, repository.name)
|
||||||
.find(_._1.milestoneId == milestoneId)
|
.find(_._1.milestoneId == milestoneId)
|
||||||
@@ -365,7 +371,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/:id/priority")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/priority")(writableUsersOnly { repository =>
|
||||||
val priority = priorityId("priorityId")
|
val priority = priorityId("priorityId")
|
||||||
updatePriorityId(repository.owner, repository.name, params("id").toInt, priority, true)
|
updatePriorityId(repository.owner, repository.name, params("id").toInt, priority, insertComment = true)
|
||||||
Ok("updated")
|
Ok("updated")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -427,7 +433,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
params("value").toIntOpt.map { labelId =>
|
params("value").toIntOpt.map { labelId =>
|
||||||
executeBatch(repository) { issueId =>
|
executeBatch(repository) { issueId =>
|
||||||
getIssueLabel(repository.owner, repository.name, issueId, labelId) getOrElse {
|
getIssueLabel(repository.owner, repository.name, issueId, labelId) getOrElse {
|
||||||
registerIssueLabel(repository.owner, repository.name, issueId, labelId, true)
|
registerIssueLabel(repository.owner, repository.name, issueId, labelId, insertComment = true)
|
||||||
if (params("uri").nonEmpty) {
|
if (params("uri").nonEmpty) {
|
||||||
redirect(params("uri"))
|
redirect(params("uri"))
|
||||||
}
|
}
|
||||||
@@ -442,9 +448,9 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
// updateAssignedUserName(repository.owner, repository.name, _, value, true)
|
// updateAssignedUserName(repository.owner, repository.name, _, value, true)
|
||||||
value match {
|
value match {
|
||||||
case Some(assignedUserName) =>
|
case Some(assignedUserName) =>
|
||||||
registerIssueAssignee(repository.owner, repository.name, _, assignedUserName, true)
|
registerIssueAssignee(repository.owner, repository.name, _, assignedUserName, insertComment = true)
|
||||||
case None =>
|
case None =>
|
||||||
deleteAllIssueAssignees(repository.owner, repository.name, _, true)
|
deleteAllIssueAssignees(repository.owner, repository.name, _, insertComment = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (params("uri").nonEmpty) {
|
if (params("uri").nonEmpty) {
|
||||||
@@ -455,20 +461,20 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
post("/:owner/:repository/issues/batchedit/milestone")(writableUsersOnly { repository =>
|
post("/:owner/:repository/issues/batchedit/milestone")(writableUsersOnly { repository =>
|
||||||
val value = milestoneId("value")
|
val value = milestoneId("value")
|
||||||
executeBatch(repository) {
|
executeBatch(repository) {
|
||||||
updateMilestoneId(repository.owner, repository.name, _, value, true)
|
updateMilestoneId(repository.owner, repository.name, _, value, insertComment = true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issues/batchedit/priority")(writableUsersOnly { repository =>
|
post("/:owner/:repository/issues/batchedit/priority")(writableUsersOnly { repository =>
|
||||||
val value = priorityId("value")
|
val value = priorityId("value")
|
||||||
executeBatch(repository) {
|
executeBatch(repository) {
|
||||||
updatePriorityId(repository.owner, repository.name, _, value, true)
|
updatePriorityId(repository.owner, repository.name, _, value, insertComment = true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/_attached/:file")(referrersOnly { repository =>
|
get("/:owner/:repository/_attached/:file")(referrersOnly { repository =>
|
||||||
(Directory.getAttachedDir(repository.owner, repository.name) match {
|
(Directory.getAttachedDir(repository.owner, repository.name) match {
|
||||||
case dir if (dir.exists && dir.isDirectory) =>
|
case dir if dir.exists && dir.isDirectory =>
|
||||||
dir.listFiles.find(_.getName.startsWith(params("file") + ".")).map { file =>
|
dir.listFiles.find(_.getName.startsWith(params("file") + ".")).map { file =>
|
||||||
response.setHeader("Content-Disposition", f"""inline; filename=${file.getName}""")
|
response.setHeader("Content-Disposition", f"""inline; filename=${file.getName}""")
|
||||||
RawData(FileUtil.getSafeMimeType(file.getName), file)
|
RawData(FileUtil.getSafeMimeType(file.getName), file)
|
||||||
@@ -484,7 +490,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
org.json4s.jackson.Serialization.write(
|
org.json4s.jackson.Serialization.write(
|
||||||
Map(
|
Map(
|
||||||
"options" -> (
|
"options" ->
|
||||||
getOpenIssues(repository.owner, repository.name)
|
getOpenIssues(repository.owner, repository.name)
|
||||||
.map { t =>
|
.map { t =>
|
||||||
Map(
|
Map(
|
||||||
@@ -495,16 +501,15 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
"value" -> t.issueId.toString
|
"value" -> t.issueId.toString
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
val assignedUserName = (key: String) => params.get(key) filter (_.trim != "")
|
private val assignedUserName = (key: String) => params.get(key) filter (_.trim != "")
|
||||||
val milestoneId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
private val milestoneId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
||||||
val priorityId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
private val priorityId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
||||||
|
|
||||||
private def executeBatch(repository: RepositoryService.RepositoryInfo)(execute: Int => Unit) = {
|
private def executeBatch(repository: RepositoryService.RepositoryInfo)(execute: Int => Unit): Unit = {
|
||||||
params("checked").split(',') map (_.toInt) foreach execute
|
params("checked").split(',') map (_.toInt) foreach execute
|
||||||
params("from") match {
|
params("from") match {
|
||||||
case "issues" => redirect(s"/${repository.owner}/${repository.name}/issues")
|
case "issues" => redirect(s"/${repository.owner}/${repository.name}/issues")
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ import gitbucket.core.service.{
|
|||||||
PrioritiesService
|
PrioritiesService
|
||||||
}
|
}
|
||||||
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits.*
|
||||||
import gitbucket.core.util.SyntaxSugars._
|
import gitbucket.core.util.SyntaxSugars.*
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms.*
|
||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
import org.scalatra.Ok
|
import org.scalatra.Ok
|
||||||
|
|
||||||
@@ -30,9 +30,9 @@ class LabelsController
|
|||||||
trait LabelsControllerBase extends ControllerBase {
|
trait LabelsControllerBase extends ControllerBase {
|
||||||
self: LabelsService & IssuesService & RepositoryService & ReferrerAuthenticator & WritableUsersAuthenticator =>
|
self: LabelsService & IssuesService & RepositoryService & ReferrerAuthenticator & WritableUsersAuthenticator =>
|
||||||
|
|
||||||
case class LabelForm(labelName: String, color: String)
|
private case class LabelForm(labelName: String, color: String)
|
||||||
|
|
||||||
val labelForm = mapping(
|
private val labelForm = mapping(
|
||||||
"labelName" -> trim(label("Label name", text(required, labelName, uniqueLabelName, maxlength(100)))),
|
"labelName" -> trim(label("Label name", text(required, labelName, uniqueLabelName, maxlength(100)))),
|
||||||
"labelColor" -> trim(label("Color", text(required, color)))
|
"labelColor" -> trim(label("Color", text(required, color)))
|
||||||
)(LabelForm.apply)
|
)(LabelForm.apply)
|
||||||
@@ -89,9 +89,9 @@ trait LabelsControllerBase extends ControllerBase {
|
|||||||
private def labelName: Constraint = new Constraint() {
|
private def labelName: Constraint = new Constraint() {
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||||
if (value.contains(',')) {
|
if (value.contains(',')) {
|
||||||
Some(s"${name} contains invalid character.")
|
Some(s"$name contains invalid character.")
|
||||||
} else if (value.startsWith("_") || value.startsWith("-")) {
|
} else if (value.startsWith("_") || value.startsWith("-")) {
|
||||||
Some(s"${name} starts with invalid character.")
|
Some(s"$name starts with invalid character.")
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ import gitbucket.core.service.{
|
|||||||
MilestonesService,
|
MilestonesService,
|
||||||
RepositoryService
|
RepositoryService
|
||||||
}
|
}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits.*
|
||||||
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
||||||
import gitbucket.core.util.SyntaxSugars._
|
import gitbucket.core.util.SyntaxSugars.*
|
||||||
import gitbucket.core.view.helpers.{getAssignableUserNames, getLabels, getPriorities, searchIssue}
|
import gitbucket.core.view.helpers.{getAssignableUserNames, getLabels, getPriorities, searchIssue}
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms.*
|
||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
|
|
||||||
class MilestonesController
|
class MilestonesController
|
||||||
@@ -29,9 +29,9 @@ trait MilestonesControllerBase extends ControllerBase {
|
|||||||
self: MilestonesService & RepositoryService & CommitStatusService & ReferrerAuthenticator &
|
self: MilestonesService & RepositoryService & CommitStatusService & ReferrerAuthenticator &
|
||||||
WritableUsersAuthenticator =>
|
WritableUsersAuthenticator =>
|
||||||
|
|
||||||
case class MilestoneForm(title: String, description: Option[String], dueDate: Option[java.util.Date])
|
private case class MilestoneForm(title: String, description: Option[String], dueDate: Option[java.util.Date])
|
||||||
|
|
||||||
val milestoneForm = mapping(
|
private val milestoneForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required, maxlength(100), uniqueMilestone))),
|
"title" -> trim(label("Title", text(required, maxlength(100), uniqueMilestone))),
|
||||||
"description" -> trim(label("Description", optional(text()))),
|
"description" -> trim(label("Description", optional(text()))),
|
||||||
"dueDate" -> trim(label("Due Date", optional(date())))
|
"dueDate" -> trim(label("Due Date", optional(date())))
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ class PrioritiesController
|
|||||||
trait PrioritiesControllerBase extends ControllerBase {
|
trait PrioritiesControllerBase extends ControllerBase {
|
||||||
self: PrioritiesService & IssuesService & RepositoryService & ReferrerAuthenticator & WritableUsersAuthenticator =>
|
self: PrioritiesService & IssuesService & RepositoryService & ReferrerAuthenticator & WritableUsersAuthenticator =>
|
||||||
|
|
||||||
case class PriorityForm(priorityName: String, description: Option[String], color: String)
|
private case class PriorityForm(priorityName: String, description: Option[String], color: String)
|
||||||
|
|
||||||
val priorityForm = mapping(
|
private val priorityForm = mapping(
|
||||||
"priorityName" -> trim(label("Priority name", text(required, priorityName, uniquePriorityName, maxlength(100)))),
|
"priorityName" -> trim(label("Priority name", text(required, priorityName, uniquePriorityName, maxlength(100)))),
|
||||||
"description" -> trim(label("Description", optional(text(maxlength(255))))),
|
"description" -> trim(label("Description", optional(text(maxlength(255))))),
|
||||||
"priorityColor" -> trim(label("Color", text(required, color)))
|
"priorityColor" -> trim(label("Color", text(required, color)))
|
||||||
@@ -86,7 +86,7 @@ trait PrioritiesControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/priorities/reorder")(writableUsersOnly { (repository) =>
|
ajaxPost("/:owner/:repository/issues/priorities/reorder")(writableUsersOnly { repository =>
|
||||||
reorderPriorities(
|
reorderPriorities(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
repository.name,
|
repository.name,
|
||||||
@@ -100,7 +100,7 @@ trait PrioritiesControllerBase extends ControllerBase {
|
|||||||
Ok()
|
Ok()
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/priorities/default")(writableUsersOnly { (repository) =>
|
ajaxPost("/:owner/:repository/issues/priorities/default")(writableUsersOnly { repository =>
|
||||||
setDefaultPriority(repository.owner, repository.name, priorityId("priorityId"))
|
setDefaultPriority(repository.owner, repository.name, priorityId("priorityId"))
|
||||||
Ok()
|
Ok()
|
||||||
})
|
})
|
||||||
@@ -118,9 +118,9 @@ trait PrioritiesControllerBase extends ControllerBase {
|
|||||||
private def priorityName: Constraint = new Constraint() {
|
private def priorityName: Constraint = new Constraint() {
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||||
if (value.contains(',')) {
|
if (value.contains(',')) {
|
||||||
Some(s"${name} contains invalid character.")
|
Some(s"$name contains invalid character.")
|
||||||
} else if (value.startsWith("_") || value.startsWith("-")) {
|
} else if (value.startsWith("_") || value.startsWith("-")) {
|
||||||
Some(s"${name} starts with invalid character.")
|
Some(s"$name starts with invalid character.")
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import gitbucket.core.model.activity.DeleteBranchInfo
|
|||||||
import gitbucket.core.pulls.html
|
import gitbucket.core.pulls.html
|
||||||
import gitbucket.core.service.CommitStatusService
|
import gitbucket.core.service.CommitStatusService
|
||||||
import gitbucket.core.service.MergeService
|
import gitbucket.core.service.MergeService
|
||||||
import gitbucket.core.service.IssuesService._
|
import gitbucket.core.service.IssuesService.*
|
||||||
import gitbucket.core.service.PullRequestService._
|
import gitbucket.core.service.PullRequestService.*
|
||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service.*
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory.*
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits.*
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util.*
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms.*
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.scalatra.BadRequest
|
import org.scalatra.BadRequest
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
ReferrerAuthenticator & WritableUsersAuthenticator & CommitStatusService & MergeService & ProtectedBranchService &
|
ReferrerAuthenticator & WritableUsersAuthenticator & CommitStatusService & MergeService & ProtectedBranchService &
|
||||||
PrioritiesService =>
|
PrioritiesService =>
|
||||||
|
|
||||||
val pullRequestForm = mapping(
|
private val pullRequestForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required))),
|
"title" -> trim(label("Title", text(required))),
|
||||||
"content" -> trim(label("Content", optional(text()))),
|
"content" -> trim(label("Content", optional(text()))),
|
||||||
"targetUserName" -> trim(text(required, maxlength(100))),
|
"targetUserName" -> trim(text(required, maxlength(100))),
|
||||||
@@ -62,13 +62,13 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
"labelNames" -> trim(optional(text()))
|
"labelNames" -> trim(optional(text()))
|
||||||
)(PullRequestForm.apply)
|
)(PullRequestForm.apply)
|
||||||
|
|
||||||
val mergeForm = mapping(
|
private val mergeForm = mapping(
|
||||||
"message" -> trim(label("Message", text(required))),
|
"message" -> trim(label("Message", text(required))),
|
||||||
"strategy" -> trim(label("Strategy", text(required))),
|
"strategy" -> trim(label("Strategy", text(required))),
|
||||||
"isDraft" -> trim(boolean(required))
|
"isDraft" -> trim(boolean(required))
|
||||||
)(MergeForm.apply)
|
)(MergeForm.apply)
|
||||||
|
|
||||||
case class PullRequestForm(
|
private case class PullRequestForm(
|
||||||
title: String,
|
title: String,
|
||||||
content: Option[String],
|
content: Option[String],
|
||||||
targetUserName: String,
|
targetUserName: String,
|
||||||
@@ -85,7 +85,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
labelNames: Option[String]
|
labelNames: Option[String]
|
||||||
)
|
)
|
||||||
|
|
||||||
case class MergeForm(message: String, strategy: String, isDraft: Boolean)
|
private case class MergeForm(message: String, strategy: String, isDraft: Boolean)
|
||||||
|
|
||||||
get("/:owner/:repository/pulls")(referrersOnly { repository =>
|
get("/:owner/:repository/pulls")(referrersOnly { repository =>
|
||||||
val q = request.getParameter("q")
|
val q = request.getParameter("q")
|
||||||
@@ -250,7 +250,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
(for {
|
(for {
|
||||||
issueId <- params("id").toIntOpt
|
issueId <- params("id").toIntOpt
|
||||||
loginAccount <- context.loginAccount
|
loginAccount <- context.loginAccount
|
||||||
(issue, pullreq) <- getPullRequest(baseRepository.owner, baseRepository.name, issueId)
|
case (issue, pullreq) <- getPullRequest(baseRepository.owner, baseRepository.name, issueId)
|
||||||
owner = pullreq.requestUserName
|
owner = pullreq.requestUserName
|
||||||
name = pullreq.requestRepositoryName
|
name = pullreq.requestRepositoryName
|
||||||
if hasDeveloperRole(owner, name, context.loginAccount)
|
if hasDeveloperRole(owner, name, context.loginAccount)
|
||||||
@@ -288,7 +288,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
(for {
|
(for {
|
||||||
issueId <- params("id").toIntOpt
|
issueId <- params("id").toIntOpt
|
||||||
loginAccount <- context.loginAccount
|
loginAccount <- context.loginAccount
|
||||||
(issue, pullreq) <- getPullRequest(baseRepository.owner, baseRepository.name, issueId)
|
case (issue, pullreq) <- getPullRequest(baseRepository.owner, baseRepository.name, issueId)
|
||||||
repository <- getRepository(pullreq.requestUserName, pullreq.requestRepositoryName)
|
repository <- getRepository(pullreq.requestUserName, pullreq.requestRepositoryName)
|
||||||
remoteRepository <- getRepository(pullreq.userName, pullreq.repositoryName)
|
remoteRepository <- getRepository(pullreq.userName, pullreq.repositoryName)
|
||||||
owner = pullreq.requestUserName
|
owner = pullreq.requestUserName
|
||||||
@@ -299,7 +299,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
if (branchProtection.needStatusCheck(loginAccount.userName)) {
|
if (branchProtection.needStatusCheck(loginAccount.userName)) {
|
||||||
flash.update("error", s"branch ${pullreq.requestBranch} is protected need status check.")
|
flash.update("error", s"branch ${pullreq.requestBranch} is protected need status check.")
|
||||||
} else {
|
} else {
|
||||||
LockUtil.lock(s"${owner}/${name}") {
|
LockUtil.lock(s"$owner/$name") {
|
||||||
val alias =
|
val alias =
|
||||||
if (
|
if (
|
||||||
pullreq.repositoryName == pullreq.requestRepositoryName && pullreq.userName == pullreq.requestUserName
|
pullreq.repositoryName == pullreq.requestRepositoryName && pullreq.userName == pullreq.requestUserName
|
||||||
@@ -308,27 +308,27 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
} else {
|
} else {
|
||||||
s"${pullreq.userName}:${pullreq.branch}"
|
s"${pullreq.userName}:${pullreq.branch}"
|
||||||
}
|
}
|
||||||
val existIds = Using
|
// val existIds = Using
|
||||||
.resource(Git.open(Directory.getRepositoryDir(owner, name))) { git =>
|
// .resource(Git.open(Directory.getRepositoryDir(owner, name))) { git =>
|
||||||
JGitUtil.getAllCommitIds(git)
|
// JGitUtil.getAllCommitIds(git)
|
||||||
}
|
// }
|
||||||
.toSet
|
// .toSet
|
||||||
pullRemote(
|
pullRemote(
|
||||||
repository,
|
repository,
|
||||||
pullreq.requestBranch,
|
pullreq.requestBranch,
|
||||||
remoteRepository,
|
remoteRepository,
|
||||||
pullreq.branch,
|
pullreq.branch,
|
||||||
loginAccount,
|
loginAccount,
|
||||||
s"Merge branch '${alias}' into ${pullreq.requestBranch}",
|
s"Merge branch '$alias' into ${pullreq.requestBranch}",
|
||||||
Some(pullreq),
|
Some(pullreq),
|
||||||
context.settings
|
context.settings
|
||||||
) match {
|
) match {
|
||||||
case None => // conflict
|
case None => // conflict
|
||||||
flash.update("error", s"Can't automatic merging branch '${alias}' into ${pullreq.requestBranch}.")
|
flash.update("error", s"Can't automatic merging branch '$alias' into ${pullreq.requestBranch}.")
|
||||||
case Some(oldId) =>
|
case Some(oldId) =>
|
||||||
// update pull request
|
// update pull request
|
||||||
updatePullRequests(owner, name, pullreq.requestBranch, loginAccount, "synchronize", context.settings)
|
updatePullRequests(owner, name, pullreq.requestBranch, loginAccount, "synchronize", context.settings)
|
||||||
flash.update("info", s"Merge branch '${alias}' into ${pullreq.requestBranch}")
|
flash.update("info", s"Merge branch '$alias' into ${pullreq.requestBranch}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -340,7 +340,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
post("/:owner/:repository/pull/:id/update_draft")(readableUsersOnly { baseRepository =>
|
post("/:owner/:repository/pull/:id/update_draft")(readableUsersOnly { baseRepository =>
|
||||||
(for {
|
(for {
|
||||||
issueId <- params("id").toIntOpt
|
issueId <- params("id").toIntOpt
|
||||||
(_, pullreq) <- getPullRequest(baseRepository.owner, baseRepository.name, issueId)
|
case (_, pullreq) <- getPullRequest(baseRepository.owner, baseRepository.name, issueId)
|
||||||
owner = pullreq.requestUserName
|
owner = pullreq.requestUserName
|
||||||
name = pullreq.requestRepositoryName
|
name = pullreq.requestRepositoryName
|
||||||
if hasDeveloperRole(owner, name, context.loginAccount)
|
if hasDeveloperRole(owner, name, context.loginAccount)
|
||||||
@@ -361,7 +361,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
form.isDraft,
|
form.isDraft,
|
||||||
context.settings
|
context.settings
|
||||||
) match {
|
) match {
|
||||||
case Right(objectId) => redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
case Right(objectId) => redirect(s"/${repository.owner}/${repository.name}/pull/$issueId")
|
||||||
case Left(message) => Some(BadRequest(message))
|
case Left(message) => Some(BadRequest(message))
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
@@ -383,7 +383,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
.getOrElse(JGitUtil.getDefaultBranch(oldGit, originRepository).get._2)
|
.getOrElse(JGitUtil.getDefaultBranch(oldGit, originRepository).get._2)
|
||||||
|
|
||||||
redirect(
|
redirect(
|
||||||
s"/${forkedRepository.owner}/${forkedRepository.name}/compare/${originUserName}:${oldBranch}...${newBranch}"
|
s"/${forkedRepository.owner}/${forkedRepository.name}/compare/$originUserName:$oldBranch...$newBranch"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
@@ -391,7 +391,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
Using.resource(Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))) { git =>
|
||||||
JGitUtil.getDefaultBranch(git, forkedRepository).map { case (_, defaultBranch) =>
|
JGitUtil.getDefaultBranch(git, forkedRepository).map { case (_, defaultBranch) =>
|
||||||
redirect(
|
redirect(
|
||||||
s"/${forkedRepository.owner}/${forkedRepository.name}/compare/${defaultBranch}...${headBranch.getOrElse(defaultBranch)}"
|
s"/${forkedRepository.owner}/${forkedRepository.name}/compare/$defaultBranch...${headBranch.getOrElse(defaultBranch)}"
|
||||||
)
|
)
|
||||||
} getOrElse {
|
} getOrElse {
|
||||||
redirect(s"/${forkedRepository.owner}/${forkedRepository.name}")
|
redirect(s"/${forkedRepository.owner}/${forkedRepository.name}")
|
||||||
@@ -413,7 +413,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
getForkedRepositories(forkedRepository.owner, forkedRepository.name)
|
getForkedRepositories(forkedRepository.owner, forkedRepository.name)
|
||||||
.find(_.userName == originOwner)
|
.find(_.userName == originOwner)
|
||||||
.map(_.repositoryName)
|
.map(_.repositoryName)
|
||||||
} else if (Some(originOwner) == forkedRepository.repository.originUserName) {
|
} else if (forkedRepository.repository.originUserName.contains(originOwner)) {
|
||||||
// Original repository
|
// Original repository
|
||||||
forkedRepository.repository.originRepositoryName
|
forkedRepository.repository.originRepositoryName
|
||||||
} else {
|
} else {
|
||||||
@@ -474,7 +474,9 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
(repository.userName, repository.repositoryName, repository.defaultBranch)
|
(repository.userName, repository.repositoryName, repository.defaultBranch)
|
||||||
},
|
},
|
||||||
commits.flatten
|
commits.flatten
|
||||||
.flatMap(commit => getCommitComments(forkedRepository.owner, forkedRepository.name, commit.id, false))
|
.flatMap(commit =>
|
||||||
|
getCommitComments(forkedRepository.owner, forkedRepository.name, commit.id, includePullRequest = false)
|
||||||
|
)
|
||||||
.toList,
|
.toList,
|
||||||
originId,
|
originId,
|
||||||
forkedId,
|
forkedId,
|
||||||
@@ -495,8 +497,8 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
case (oldId, newId) =>
|
case (oldId, newId) =>
|
||||||
redirect(
|
redirect(
|
||||||
s"/${forkedRepository.owner}/${forkedRepository.name}/compare/" +
|
s"/${forkedRepository.owner}/${forkedRepository.name}/compare/" +
|
||||||
s"${originOwner}:${oldId.map(_ => originId).getOrElse(originRepository.repository.defaultBranch)}..." +
|
s"$originOwner:${oldId.map(_ => originId).getOrElse(originRepository.repository.defaultBranch)}..." +
|
||||||
s"${forkedOwner}:${newId.map(_ => forkedId).getOrElse(forkedRepository.repository.defaultBranch)}"
|
s"$forkedOwner:${newId.map(_ => forkedId).getOrElse(forkedRepository.repository.defaultBranch)}"
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -637,7 +639,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
redirect(s"/${repository.owner}/${repository.name}/pull/$issueId")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ import gitbucket.core.service.{
|
|||||||
RepositoryService,
|
RepositoryService,
|
||||||
RequestCache
|
RequestCache
|
||||||
}
|
}
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util.*
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory.*
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits.*
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms.*
|
||||||
import gitbucket.core.releases.html
|
import gitbucket.core.releases.html
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
@@ -36,12 +36,12 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
self: RepositoryService & AccountService & ReleaseService & ReadableUsersAuthenticator & ReferrerAuthenticator &
|
self: RepositoryService & AccountService & ReleaseService & ReadableUsersAuthenticator & ReferrerAuthenticator &
|
||||||
WritableUsersAuthenticator & ActivityService =>
|
WritableUsersAuthenticator & ActivityService =>
|
||||||
|
|
||||||
case class ReleaseForm(
|
private case class ReleaseForm(
|
||||||
name: String,
|
name: String,
|
||||||
content: Option[String]
|
content: Option[String]
|
||||||
)
|
)
|
||||||
|
|
||||||
val releaseForm = mapping(
|
private val releaseForm = mapping(
|
||||||
"name" -> trim(text(required)),
|
"name" -> trim(text(required)),
|
||||||
"content" -> trim(optional(text()))
|
"content" -> trim(optional(text()))
|
||||||
)(ReleaseForm.apply)
|
)(ReleaseForm.apply)
|
||||||
@@ -125,7 +125,7 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
val releaseInfo = ReleaseInfo(repository.owner, repository.name, loginAccount.userName, form.name, tagName)
|
val releaseInfo = ReleaseInfo(repository.owner, repository.name, loginAccount.userName, form.name, tagName)
|
||||||
recordActivity(releaseInfo)
|
recordActivity(releaseInfo)
|
||||||
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/releases/${tagName}")
|
redirect(s"/${repository.owner}/${repository.name}/releases/$tagName")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect(s"/${release.userName}/${release.repositoryName}/releases/${tagName}")
|
redirect(s"/${release.userName}/${release.repositoryName}/releases/$tagName")
|
||||||
}
|
}
|
||||||
.getOrElse(NotFound())
|
.getOrElse(NotFound())
|
||||||
}
|
}
|
||||||
@@ -217,7 +217,7 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
private def fetchReleases(repository: RepositoryService.RepositoryInfo, page: Int) = {
|
private def fetchReleases(repository: RepositoryService.RepositoryInfo, page: Int) = {
|
||||||
import gitbucket.core.service.ReleaseService._
|
import gitbucket.core.service.ReleaseService.*
|
||||||
|
|
||||||
val (offset, limit) = ((page - 1) * ReleaseLimit, ReleaseLimit)
|
val (offset, limit) = ((page - 1) * ReleaseLimit, ReleaseLimit)
|
||||||
val tagsToDisplay = repository.tags.reverse.slice(offset, offset + limit)
|
val tagsToDisplay = repository.tags.reverse.slice(offset, offset + limit)
|
||||||
|
|||||||
@@ -4,16 +4,16 @@ import java.time.{LocalDateTime, ZoneOffset}
|
|||||||
import java.util.Date
|
import java.util.Date
|
||||||
import gitbucket.core.settings.html
|
import gitbucket.core.settings.html
|
||||||
import gitbucket.core.model.{RepositoryWebHook, WebHook}
|
import gitbucket.core.model.{RepositoryWebHook, WebHook}
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service.*
|
||||||
import gitbucket.core.service.WebHookService._
|
import gitbucket.core.service.WebHookService.*
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util.*
|
||||||
import gitbucket.core.util.JGitUtil._
|
import gitbucket.core.util.JGitUtil.*
|
||||||
import gitbucket.core.util.SyntaxSugars._
|
import gitbucket.core.util.SyntaxSugars.*
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits.*
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory.*
|
||||||
import gitbucket.core.model.WebHookContentType
|
import gitbucket.core.model.WebHookContentType
|
||||||
import gitbucket.core.model.activity.RenameRepositoryInfo
|
import gitbucket.core.model.activity.RenameRepositoryInfo
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms.*
|
||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.lib.Constants
|
import org.eclipse.jgit.lib.Constants
|
||||||
@@ -41,7 +41,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
DeployKeyService & CustomFieldsService & ActivityService & OwnerAuthenticator & UsersAuthenticator =>
|
DeployKeyService & CustomFieldsService & ActivityService & OwnerAuthenticator & UsersAuthenticator =>
|
||||||
|
|
||||||
// for repository options
|
// for repository options
|
||||||
case class OptionsForm(
|
private case class OptionsForm(
|
||||||
description: Option[String],
|
description: Option[String],
|
||||||
isPrivate: Boolean,
|
isPrivate: Boolean,
|
||||||
issuesOption: String,
|
issuesOption: String,
|
||||||
@@ -54,7 +54,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
safeMode: Boolean
|
safeMode: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
val optionsForm = mapping(
|
private val optionsForm = mapping(
|
||||||
"description" -> trim(label("Description", optional(text()))),
|
"description" -> trim(label("Description", optional(text()))),
|
||||||
"isPrivate" -> trim(label("Repository Type", boolean())),
|
"isPrivate" -> trim(label("Repository Type", boolean())),
|
||||||
"issuesOption" -> trim(label("Issues Option", text(required, featureOption))),
|
"issuesOption" -> trim(label("Issues Option", text(required, featureOption))),
|
||||||
@@ -72,25 +72,30 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// for default branch
|
// for default branch
|
||||||
case class DefaultBranchForm(defaultBranch: String)
|
private case class DefaultBranchForm(defaultBranch: String)
|
||||||
|
|
||||||
val defaultBranchForm = mapping(
|
private val defaultBranchForm = mapping(
|
||||||
"defaultBranch" -> trim(label("Default Branch", text(required, maxlength(100))))
|
"defaultBranch" -> trim(label("Default Branch", text(required, maxlength(100))))
|
||||||
)(DefaultBranchForm.apply)
|
)(DefaultBranchForm.apply)
|
||||||
|
|
||||||
// for deploy key
|
// for deploy key
|
||||||
case class DeployKeyForm(title: String, publicKey: String, allowWrite: Boolean)
|
private case class DeployKeyForm(title: String, publicKey: String, allowWrite: Boolean)
|
||||||
|
|
||||||
val deployKeyForm = mapping(
|
private val deployKeyForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
||||||
"publicKey" -> trim2(label("Key", text(required))), // TODO duplication check in the repository?
|
"publicKey" -> trim2(label("Key", text(required))), // TODO duplication check in the repository?
|
||||||
"allowWrite" -> trim(label("Key", boolean()))
|
"allowWrite" -> trim(label("Key", boolean()))
|
||||||
)(DeployKeyForm.apply)
|
)(DeployKeyForm.apply)
|
||||||
|
|
||||||
// for web hook url addition
|
// for web hook url addition
|
||||||
case class WebHookForm(url: String, events: Set[WebHook.Event], ctype: WebHookContentType, token: Option[String])
|
private case class WebHookForm(
|
||||||
|
url: String,
|
||||||
|
events: Set[WebHook.Event],
|
||||||
|
ctype: WebHookContentType,
|
||||||
|
token: Option[String]
|
||||||
|
)
|
||||||
|
|
||||||
def webHookForm(update: Boolean) =
|
private def webHookForm(update: Boolean) =
|
||||||
mapping(
|
mapping(
|
||||||
"url" -> trim(label("url", text(required, webHook(update)))),
|
"url" -> trim(label("url", text(required, webHook(update)))),
|
||||||
"events" -> webhookEvents,
|
"events" -> webhookEvents,
|
||||||
@@ -99,23 +104,23 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
)((url, events, ctype, token) => WebHookForm(url, events, WebHookContentType.valueOf(ctype), token))
|
)((url, events, ctype, token) => WebHookForm(url, events, WebHookContentType.valueOf(ctype), token))
|
||||||
|
|
||||||
// for rename repository
|
// for rename repository
|
||||||
case class RenameRepositoryForm(repositoryName: String)
|
private case class RenameRepositoryForm(repositoryName: String)
|
||||||
|
|
||||||
val renameForm = mapping(
|
private val renameForm = mapping(
|
||||||
"repositoryName" -> trim(
|
"repositoryName" -> trim(
|
||||||
label("New repository name", text(required, maxlength(100), repository, renameRepositoryName))
|
label("New repository name", text(required, maxlength(100), repository, renameRepositoryName))
|
||||||
)
|
)
|
||||||
)(RenameRepositoryForm.apply)
|
)(RenameRepositoryForm.apply)
|
||||||
|
|
||||||
// for transfer ownership
|
// for transfer ownership
|
||||||
case class TransferOwnerShipForm(newOwner: String)
|
private case class TransferOwnerShipForm(newOwner: String)
|
||||||
|
|
||||||
val transferForm = mapping(
|
private val transferForm = mapping(
|
||||||
"newOwner" -> trim(label("New owner", text(required, transferUser)))
|
"newOwner" -> trim(label("New owner", text(required, transferUser)))
|
||||||
)(TransferOwnerShipForm.apply)
|
)(TransferOwnerShipForm.apply)
|
||||||
|
|
||||||
// for custom field
|
// for custom field
|
||||||
case class CustomFieldForm(
|
private case class CustomFieldForm(
|
||||||
fieldName: String,
|
fieldName: String,
|
||||||
fieldType: String,
|
fieldType: String,
|
||||||
constraints: Option[String],
|
constraints: Option[String],
|
||||||
@@ -123,7 +128,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
enableForPullRequests: Boolean
|
enableForPullRequests: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
val customFieldForm = mapping(
|
private val customFieldForm = mapping(
|
||||||
"fieldName" -> trim(label("Field name", text(required, maxlength(100)))),
|
"fieldName" -> trim(label("Field name", text(required, maxlength(100)))),
|
||||||
"fieldType" -> trim(label("Field type", text(required))),
|
"fieldType" -> trim(label("Field type", text(required))),
|
||||||
"constraints" -> trim(label("Constraints", optional(text()))),
|
"constraints" -> trim(label("Constraints", optional(text()))),
|
||||||
@@ -192,7 +197,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/** Branch protection for branch */
|
/** Branch protection for branch */
|
||||||
get("/:owner/:repository/settings/branches/*")(ownerOnly { repository =>
|
get("/:owner/:repository/settings/branches/*")(ownerOnly { repository =>
|
||||||
import gitbucket.core.api._
|
import gitbucket.core.api.*
|
||||||
val branch = params("splat")
|
val branch = params("splat")
|
||||||
|
|
||||||
if (!repository.branchList.contains(branch)) {
|
if (!repository.branchList.contains(branch)) {
|
||||||
@@ -248,7 +253,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
ctype = WebHookContentType.FORM,
|
ctype = WebHookContentType.FORM,
|
||||||
token = None
|
token = None
|
||||||
)
|
)
|
||||||
html.edithook(webhook, Set(WebHook.Push), repository, true)
|
html.edithook(webhook, Set(WebHook.Push), repository, create = true)
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -279,9 +284,9 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration.*
|
||||||
import scala.concurrent._
|
import scala.concurrent.*
|
||||||
import scala.jdk.CollectionConverters._
|
import scala.jdk.CollectionConverters.*
|
||||||
import scala.util.control.NonFatal
|
import scala.util.control.NonFatal
|
||||||
import org.apache.http.util.EntityUtils
|
import org.apache.http.util.EntityUtils
|
||||||
import scala.concurrent.ExecutionContext.Implicits.global
|
import scala.concurrent.ExecutionContext.Implicits.global
|
||||||
@@ -327,10 +332,10 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
callWebHook(WebHook.Push, List(dummyWebHookInfo), dummyPayload, context.settings).head
|
callWebHook(WebHook.Push, List(dummyWebHookInfo), dummyPayload, context.settings).head
|
||||||
|
|
||||||
val toErrorMap: PartialFunction[Throwable, Map[String, String]] = {
|
val toErrorMap: PartialFunction[Throwable, Map[String, String]] = {
|
||||||
case e: java.net.UnknownHostException => Map("error" -> ("Unknown host " + e.getMessage))
|
case e: java.net.UnknownHostException => Map("error" -> s"Unknown host ${e.getMessage}")
|
||||||
case e: java.lang.IllegalArgumentException => Map("error" -> ("invalid url"))
|
case _: java.lang.IllegalArgumentException => Map("error" -> "invalid url")
|
||||||
case e: org.apache.http.client.ClientProtocolException => Map("error" -> ("invalid url"))
|
case _: org.apache.http.client.ClientProtocolException => Map("error" -> "invalid url")
|
||||||
case NonFatal(e) => Map("error" -> (s"${e.getClass} ${e.getMessage}"))
|
case NonFatal(e) => Map("error" -> s"${e.getClass} ${e.getMessage}")
|
||||||
}
|
}
|
||||||
|
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
@@ -353,8 +358,8 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
.map(res =>
|
.map(res =>
|
||||||
Map(
|
Map(
|
||||||
"status" -> res.getStatusLine.getStatusCode,
|
"status" -> res.getStatusLine.getStatusCode,
|
||||||
"body" -> EntityUtils.toString(res.getEntity()),
|
"body" -> EntityUtils.toString(res.getEntity),
|
||||||
"headers" -> _headers(res.getAllHeaders())
|
"headers" -> _headers(res.getAllHeaders)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.recover(toErrorMap),
|
.recover(toErrorMap),
|
||||||
@@ -370,7 +375,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
get("/:owner/:repository/settings/hooks/edit")(ownerOnly { repository =>
|
get("/:owner/:repository/settings/hooks/edit")(ownerOnly { repository =>
|
||||||
getWebHook(repository.owner, repository.name, params("url")).map { case (webhook, events) =>
|
getWebHook(repository.owner, repository.name, params("url")).map { case (webhook, events) =>
|
||||||
html.edithook(webhook, events, repository, false)
|
html.edithook(webhook, events, repository, create = false)
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
|
|||||||
import gitbucket.core.repo.html
|
import gitbucket.core.repo.html
|
||||||
import gitbucket.core.helper
|
import gitbucket.core.helper
|
||||||
import gitbucket.core.model.activity.DeleteBranchInfo
|
import gitbucket.core.model.activity.DeleteBranchInfo
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service.*
|
||||||
import gitbucket.core.service.RepositoryCommitFileService.CommitFile
|
import gitbucket.core.service.RepositoryCommitFileService.CommitFile
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util.*
|
||||||
import gitbucket.core.util.StringUtil._
|
import gitbucket.core.util.StringUtil.*
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits.*
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory.*
|
||||||
import gitbucket.core.model.{Account, WebHook}
|
import gitbucket.core.model.{Account, WebHook}
|
||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
import gitbucket.core.service.WebHookService.{WebHookCreatePayload, WebHookPushPayload}
|
import gitbucket.core.service.WebHookService.{WebHookCreatePayload, WebHookPushPayload}
|
||||||
@@ -25,11 +25,11 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream
|
|||||||
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream
|
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream
|
||||||
import org.apache.commons.compress.utils.IOUtils
|
import org.apache.commons.compress.utils.IOUtils
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms.*
|
||||||
import org.eclipse.jgit.api.{ArchiveCommand, Git}
|
import org.eclipse.jgit.api.{ArchiveCommand, Git}
|
||||||
import org.eclipse.jgit.archive.{TgzFormat, ZipFormat}
|
import org.eclipse.jgit.archive.{TgzFormat, ZipFormat}
|
||||||
import org.eclipse.jgit.errors.MissingObjectException
|
import org.eclipse.jgit.errors.MissingObjectException
|
||||||
import org.eclipse.jgit.lib._
|
import org.eclipse.jgit.lib.*
|
||||||
import org.eclipse.jgit.treewalk.{TreeWalk, WorkingTreeOptions}
|
import org.eclipse.jgit.treewalk.{TreeWalk, WorkingTreeOptions}
|
||||||
import org.eclipse.jgit.treewalk.TreeWalk.OperationType
|
import org.eclipse.jgit.treewalk.TreeWalk.OperationType
|
||||||
import org.eclipse.jgit.treewalk.filter.PathFilter
|
import org.eclipse.jgit.treewalk.filter.PathFilter
|
||||||
@@ -73,7 +73,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
ArchiveCommand.registerFormat("zip", new ZipFormat)
|
ArchiveCommand.registerFormat("zip", new ZipFormat)
|
||||||
ArchiveCommand.registerFormat("tar.gz", new TgzFormat)
|
ArchiveCommand.registerFormat("tar.gz", new TgzFormat)
|
||||||
|
|
||||||
case class UploadForm(
|
private case class UploadForm(
|
||||||
branch: String,
|
branch: String,
|
||||||
path: String,
|
path: String,
|
||||||
uploadFiles: String,
|
uploadFiles: String,
|
||||||
@@ -82,7 +82,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
newBranch: Boolean
|
newBranch: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
case class EditorForm(
|
private case class EditorForm(
|
||||||
branch: String,
|
branch: String,
|
||||||
path: String,
|
path: String,
|
||||||
content: String,
|
content: String,
|
||||||
@@ -95,7 +95,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
newBranch: Boolean
|
newBranch: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
case class DeleteForm(
|
private case class DeleteForm(
|
||||||
branch: String,
|
branch: String,
|
||||||
path: String,
|
path: String,
|
||||||
message: Option[String],
|
message: Option[String],
|
||||||
@@ -104,7 +104,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
newBranch: Boolean
|
newBranch: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
case class CommentForm(
|
private case class CommentForm(
|
||||||
fileName: Option[String],
|
fileName: Option[String],
|
||||||
oldLineNumber: Option[Int],
|
oldLineNumber: Option[Int],
|
||||||
newLineNumber: Option[Int],
|
newLineNumber: Option[Int],
|
||||||
@@ -113,13 +113,13 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
diff: Option[String]
|
diff: Option[String]
|
||||||
)
|
)
|
||||||
|
|
||||||
case class TagForm(
|
private case class TagForm(
|
||||||
commitId: String,
|
commitId: String,
|
||||||
tagName: String,
|
tagName: String,
|
||||||
message: Option[String]
|
message: Option[String]
|
||||||
)
|
)
|
||||||
|
|
||||||
val uploadForm = mapping(
|
private val uploadForm = mapping(
|
||||||
"branch" -> trim(label("Branch", text(required))),
|
"branch" -> trim(label("Branch", text(required))),
|
||||||
"path" -> trim(label("Path", text())),
|
"path" -> trim(label("Path", text())),
|
||||||
"uploadFiles" -> trim(label("Upload files", text(required))),
|
"uploadFiles" -> trim(label("Upload files", text(required))),
|
||||||
@@ -128,7 +128,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
"newBranch" -> trim(label("New Branch", boolean()))
|
"newBranch" -> trim(label("New Branch", boolean()))
|
||||||
)(UploadForm.apply)
|
)(UploadForm.apply)
|
||||||
|
|
||||||
val editorForm = mapping(
|
private val editorForm = mapping(
|
||||||
"branch" -> trim(label("Branch", text(required))),
|
"branch" -> trim(label("Branch", text(required))),
|
||||||
"path" -> trim(label("Path", text())),
|
"path" -> trim(label("Path", text())),
|
||||||
"content" -> trim(label("Content", text(required))),
|
"content" -> trim(label("Content", text(required))),
|
||||||
@@ -141,7 +141,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
"newBranch" -> trim(label("New Branch", boolean()))
|
"newBranch" -> trim(label("New Branch", boolean()))
|
||||||
)(EditorForm.apply)
|
)(EditorForm.apply)
|
||||||
|
|
||||||
val deleteForm = mapping(
|
private val deleteForm = mapping(
|
||||||
"branch" -> trim(label("Branch", text(required))),
|
"branch" -> trim(label("Branch", text(required))),
|
||||||
"path" -> trim(label("Path", text())),
|
"path" -> trim(label("Path", text())),
|
||||||
"message" -> trim(label("Message", optional(text()))),
|
"message" -> trim(label("Message", optional(text()))),
|
||||||
@@ -150,7 +150,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
"newBranch" -> trim(label("New Branch", boolean()))
|
"newBranch" -> trim(label("New Branch", boolean()))
|
||||||
)(DeleteForm.apply)
|
)(DeleteForm.apply)
|
||||||
|
|
||||||
val commentForm = mapping(
|
private val commentForm = mapping(
|
||||||
"fileName" -> trim(label("Filename", optional(text()))),
|
"fileName" -> trim(label("Filename", optional(text()))),
|
||||||
"oldLineNumber" -> trim(label("Old line number", optional(number()))),
|
"oldLineNumber" -> trim(label("Old line number", optional(number()))),
|
||||||
"newLineNumber" -> trim(label("New line number", optional(number()))),
|
"newLineNumber" -> trim(label("New line number", optional(number()))),
|
||||||
@@ -159,7 +159,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
"diff" -> optional(text())
|
"diff" -> optional(text())
|
||||||
)(CommentForm.apply)
|
)(CommentForm.apply)
|
||||||
|
|
||||||
val tagForm = mapping(
|
private val tagForm = mapping(
|
||||||
"commitId" -> trim(label("Commit id", text(required))),
|
"commitId" -> trim(label("Commit id", text(required))),
|
||||||
"tagName" -> trim(label("Tag name", text(required))),
|
"tagName" -> trim(label("Tag name", text(required))),
|
||||||
"message" -> trim(label("Message", optional(text())))
|
"message" -> trim(label("Message", optional(text())))
|
||||||
@@ -285,7 +285,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
html.editor(
|
html.editor(
|
||||||
branch = branch,
|
branch = branch,
|
||||||
repository = repository,
|
repository = repository,
|
||||||
pathList = if (path.length == 0) Nil else path.split("/").toList,
|
pathList = if (path.isEmpty) Nil else path.split("/").toList,
|
||||||
fileName = None,
|
fileName = None,
|
||||||
content = JGitUtil.ContentInfo("text", None, None, Some("UTF-8")),
|
content = JGitUtil.ContentInfo("text", None, None, Some("UTF-8")),
|
||||||
protectedBranch = protectedBranch,
|
protectedBranch = protectedBranch,
|
||||||
@@ -305,7 +305,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
html.upload(
|
html.upload(
|
||||||
branch,
|
branch,
|
||||||
repository,
|
repository,
|
||||||
if (path.length == 0) Nil else path.split("/").toList,
|
if (path.isEmpty) Nil else path.split("/").toList,
|
||||||
protectedBranch,
|
protectedBranch,
|
||||||
revCommit.name
|
revCommit.name
|
||||||
)
|
)
|
||||||
@@ -353,7 +353,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
.toSeq
|
.toSeq
|
||||||
|
|
||||||
val newFiles = files.map { file =>
|
val newFiles = files.map { file =>
|
||||||
file.copy(name = if (form.path.length == 0) file.name else s"${form.path}/${file.name}")
|
file.copy(name = if (form.path.isEmpty) file.name else s"${form.path}/${file.name}")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (form.newBranch) {
|
if (form.newBranch) {
|
||||||
@@ -370,13 +370,13 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
form.message,
|
form.message,
|
||||||
loginAccount
|
loginAccount
|
||||||
)
|
)
|
||||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
redirect(s"/${repository.owner}/${repository.name}/pull/$issueId")
|
||||||
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_commit(form.branch, newFiles, loginAccount) match {
|
_commit(form.branch, newFiles, loginAccount) match {
|
||||||
case Right(_) =>
|
case Right(_) =>
|
||||||
if (form.path.length == 0) {
|
if (form.path.isEmpty) {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/tree/${encodeRefName(form.branch)}")
|
redirect(s"/${repository.owner}/${repository.name}/tree/${encodeRefName(form.branch)}")
|
||||||
} else {
|
} else {
|
||||||
redirect(
|
redirect(
|
||||||
@@ -471,13 +471,13 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
form.message,
|
form.message,
|
||||||
loginAccount
|
loginAccount
|
||||||
)
|
)
|
||||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
redirect(s"/${repository.owner}/${repository.name}/pull/$issueId")
|
||||||
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_commit(form.branch, loginAccount) match {
|
_commit(form.branch, loginAccount) match {
|
||||||
case Right(_) =>
|
case Right(_) =>
|
||||||
if (form.path.length == 0) {
|
if (form.path.isEmpty) {
|
||||||
redirect(
|
redirect(
|
||||||
s"/${repository.owner}/${repository.name}/blob/${encodeRefName(form.branch)}/${urlEncode(form.newFileName)}"
|
s"/${repository.owner}/${repository.name}/blob/${encodeRefName(form.branch)}/${urlEncode(form.newFileName)}"
|
||||||
)
|
)
|
||||||
@@ -528,13 +528,13 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
form.message,
|
form.message,
|
||||||
loginAccount
|
loginAccount
|
||||||
)
|
)
|
||||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
redirect(s"/${repository.owner}/${repository.name}/pull/$issueId")
|
||||||
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_commit(form.branch, loginAccount) match {
|
_commit(form.branch, loginAccount) match {
|
||||||
case Right(_) =>
|
case Right(_) =>
|
||||||
if (form.path.length == 0) {
|
if (form.path.isEmpty) {
|
||||||
redirect(
|
redirect(
|
||||||
s"/${repository.owner}/${repository.name}/blob/${encodeRefName(form.branch)}/${urlEncode(form.newFileName)}"
|
s"/${repository.owner}/${repository.name}/blob/${encodeRefName(form.branch)}/${urlEncode(form.newFileName)}"
|
||||||
)
|
)
|
||||||
@@ -581,7 +581,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
form.message,
|
form.message,
|
||||||
loginAccount
|
loginAccount
|
||||||
)
|
)
|
||||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
redirect(s"/${repository.owner}/${repository.name}/pull/$issueId")
|
||||||
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -629,7 +629,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
sender,
|
sender,
|
||||||
repository,
|
repository,
|
||||||
owner,
|
owner,
|
||||||
ref = s"refs/heads/${newBranchName}",
|
ref = s"refs/heads/$newBranchName",
|
||||||
refType = "branch"
|
refType = "branch"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -686,7 +686,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
/**
|
/**
|
||||||
* Displays the file content of the specified branch or commit.
|
* Displays the file content of the specified branch or commit.
|
||||||
*/
|
*/
|
||||||
val blobRoute = get("/:owner/:repository/blob/*")(referrersOnly { repository =>
|
private val blobRoute = get("/:owner/:repository/blob/*")(referrersOnly { repository =>
|
||||||
val (id, path) = repository.splitPath(multiParams("splat").head)
|
val (id, path) = repository.splitPath(multiParams("splat").head)
|
||||||
val raw = params.get("raw").getOrElse("false").toBoolean
|
val raw = params.get("raw").getOrElse("false").toBoolean
|
||||||
val highlighterTheme = getSyntaxHighlighterTheme()
|
val highlighterTheme = getSyntaxHighlighterTheme()
|
||||||
@@ -792,7 +792,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
JGitUtil.getBranchesOfCommit(git, revCommit.getName),
|
JGitUtil.getBranchesOfCommit(git, revCommit.getName),
|
||||||
JGitUtil.getTagsOfCommit(git, revCommit.getName),
|
JGitUtil.getTagsOfCommit(git, revCommit.getName),
|
||||||
getCommitStatusWithSummary(repository.owner, repository.name, revCommit.getName),
|
getCommitStatusWithSummary(repository.owner, repository.name, revCommit.getName),
|
||||||
getCommitComments(repository.owner, repository.name, id, true),
|
getCommitComments(repository.owner, repository.name, id, includePullRequest = true),
|
||||||
repository,
|
repository,
|
||||||
diffs,
|
diffs,
|
||||||
oldCommitId,
|
oldCommitId,
|
||||||
@@ -802,7 +802,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
case e: MissingObjectException => NotFound()
|
case _: MissingObjectException => NotFound()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -814,7 +814,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
diff
|
diff
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
case e: MissingObjectException => NotFound()
|
case _: MissingObjectException => NotFound()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -827,7 +827,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
diff
|
diff
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
case e: MissingObjectException => NotFound()
|
case _: MissingObjectException => NotFound()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -846,7 +846,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
form.issueId
|
form.issueId
|
||||||
)
|
)
|
||||||
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/commit/${id}")
|
redirect(s"/${repository.owner}/${repository.name}/commit/$id")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -1006,7 +1006,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
case Right(message) =>
|
case Right(message) =>
|
||||||
flash.update("info", message)
|
flash.update("info", message)
|
||||||
val settings = loadSystemSettings()
|
val settings = loadSystemSettings()
|
||||||
val newCommitId = git.getRepository.resolve(s"refs/heads/${newBranchName}")
|
val newCommitId = git.getRepository.resolve(s"refs/heads/$newBranchName")
|
||||||
val oldCommitId = ObjectId.fromString("0" * 40)
|
val oldCommitId = ObjectId.fromString("0" * 40)
|
||||||
// call push webhook
|
// call push webhook
|
||||||
callWebHookOf(repository.owner, repository.name, WebHook.Push, settings) {
|
callWebHookOf(repository.owner, repository.name, WebHook.Push, settings) {
|
||||||
@@ -1017,7 +1017,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
WebHookPushPayload(
|
WebHookPushPayload(
|
||||||
git,
|
git,
|
||||||
pusherAccount,
|
pusherAccount,
|
||||||
s"refs/heads/${newBranchName}",
|
s"refs/heads/$newBranchName",
|
||||||
repository,
|
repository,
|
||||||
List(),
|
List(),
|
||||||
ownerAccount,
|
ownerAccount,
|
||||||
@@ -1036,7 +1036,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
sender,
|
sender,
|
||||||
repository,
|
repository,
|
||||||
owner,
|
owner,
|
||||||
ref = s"refs/heads/${newBranchName}",
|
ref = s"refs/heads/$newBranchName",
|
||||||
refType = "branch"
|
refType = "branch"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1046,7 +1046,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
case Left(message) =>
|
case Left(message) =>
|
||||||
flash.update("error", message)
|
flash.update("error", message)
|
||||||
redirect(s"/${repository.owner}/${repository.name}/tree/${fromBranchName}")
|
redirect(s"/${repository.owner}/${repository.name}/tree/$fromBranchName")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -1132,9 +1132,9 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
case class UploadFiles(branch: String, path: String, fileIds: Map[String, String], message: String) {
|
// case class UploadFiles(branch: String, path: String, fileIds: Map[String, String], message: String) {
|
||||||
lazy val isValid: Boolean = fileIds.nonEmpty
|
// lazy val isValid: Boolean = fileIds.nonEmpty
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides HTML of the file list.
|
* Provides HTML of the file list.
|
||||||
@@ -1174,7 +1174,11 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val path = (file.name :: parentPath.reverse).reverse
|
val path = (file.name :: parentPath.reverse).reverse
|
||||||
path -> StringUtil.convertFromByteArray(
|
path -> StringUtil.convertFromByteArray(
|
||||||
JGitUtil
|
JGitUtil
|
||||||
.getContentFromId(Git.open(getRepositoryDir(repository.owner, repository.name)), file.id, true)
|
.getContentFromId(
|
||||||
|
Git.open(getRepositoryDir(repository.owner, repository.name)),
|
||||||
|
file.id,
|
||||||
|
fetchLargeFile = true
|
||||||
|
)
|
||||||
.get
|
.get
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1215,7 +1219,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val oid = git.getRepository.resolve(revision)
|
val oid = git.getRepository.resolve(revision)
|
||||||
val commit = JGitUtil.getRevCommitFromId(git, oid)
|
val commit = JGitUtil.getRevCommitFromId(git, oid)
|
||||||
val date = commit.getCommitterIdent.getWhen
|
val date = commit.getCommitterIdent.getWhen
|
||||||
val sha1 = oid.getName()
|
val sha1 = oid.getName
|
||||||
val repositorySuffix = (if (sha1.startsWith(revision)) sha1 else revision).replace('/', '-')
|
val repositorySuffix = (if (sha1.startsWith(revision)) sha1 else revision).replace('/', '-')
|
||||||
val pathSuffix = if (path.isEmpty) "" else s"-${path.replace('/', '-')}"
|
val pathSuffix = if (path.isEmpty) "" else s"-${path.replace('/', '-')}"
|
||||||
val baseName = repository.name + "-" + repositorySuffix + pathSuffix
|
val baseName = repository.name + "-" + repositorySuffix + pathSuffix
|
||||||
@@ -1223,7 +1227,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
Using.resource(new TreeWalk(git.getRepository)) { treeWalk =>
|
Using.resource(new TreeWalk(git.getRepository)) { treeWalk =>
|
||||||
treeWalk.addTree(commit.getTree)
|
treeWalk.addTree(commit.getTree)
|
||||||
treeWalk.setRecursive(true)
|
treeWalk.setRecursive(true)
|
||||||
if (!path.isEmpty) {
|
if (path.nonEmpty) {
|
||||||
treeWalk.setFilter(PathFilter.create(path))
|
treeWalk.setFilter(PathFilter.create(path))
|
||||||
}
|
}
|
||||||
if (treeWalk != null) {
|
if (treeWalk != null) {
|
||||||
@@ -1267,7 +1271,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val suffix =
|
val suffix =
|
||||||
path.split("/").lastOption.collect { case x if x.length > 0 => "-" + x.replace('/', '_') }.getOrElse("")
|
path.split("/").lastOption.collect { case x if x.nonEmpty => "-" + x.replace('/', '_') }.getOrElse("")
|
||||||
val zipRe = """(.+)\.zip$""".r
|
val zipRe = """(.+)\.zip$""".r
|
||||||
val tarRe = """(.+)\.tar\.(gz|bz2|xz)$""".r
|
val tarRe = """(.+)\.tar\.(gz|bz2|xz)$""".r
|
||||||
|
|
||||||
@@ -1275,7 +1279,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
case zipRe(revision) =>
|
case zipRe(revision) =>
|
||||||
response.setHeader(
|
response.setHeader(
|
||||||
"Content-Disposition",
|
"Content-Disposition",
|
||||||
s"attachment; filename=${repository.name}-${revision}${suffix}.zip"
|
s"attachment; filename=${repository.name}-$revision$suffix.zip"
|
||||||
)
|
)
|
||||||
contentType = "application/octet-stream"
|
contentType = "application/octet-stream"
|
||||||
response.setBufferSize(1024 * 1024)
|
response.setBufferSize(1024 * 1024)
|
||||||
@@ -1292,7 +1296,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
case tarRe(revision, compressor) =>
|
case tarRe(revision, compressor) =>
|
||||||
response.setHeader(
|
response.setHeader(
|
||||||
"Content-Disposition",
|
"Content-Disposition",
|
||||||
s"attachment; filename=${repository.name}-${revision}${suffix}.tar.${compressor}"
|
s"attachment; filename=${repository.name}-$revision$suffix.tar.$compressor"
|
||||||
)
|
)
|
||||||
contentType = "application/octet-stream"
|
contentType = "application/octet-stream"
|
||||||
response.setBufferSize(1024 * 1024)
|
response.setBufferSize(1024 * 1024)
|
||||||
@@ -1330,9 +1334,9 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
val branch = params("branch")
|
val branch = params("branch")
|
||||||
|
|
||||||
LockUtil.lock(s"${owner}/${repository}") {
|
LockUtil.lock(s"$owner/$repository") {
|
||||||
Using.resource(Git.open(getRepositoryDir(owner, repository))) { git =>
|
Using.resource(Git.open(getRepositoryDir(owner, repository))) { git =>
|
||||||
val headName = s"refs/heads/${branch}"
|
val headName = s"refs/heads/$branch"
|
||||||
val headTip = git.getRepository.resolve(headName)
|
val headTip = git.getRepository.resolve(headName)
|
||||||
if (headTip.getName != value) {
|
if (headTip.getName != value) {
|
||||||
Some("Someone pushed new commits before you. Please reload this page and re-apply your changes.")
|
Some("Someone pushed new commits before you. Please reload this page and re-apply your changes.")
|
||||||
|
|||||||
@@ -3,17 +3,17 @@ package gitbucket.core.controller
|
|||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import gitbucket.core.admin.html
|
import gitbucket.core.admin.html
|
||||||
import gitbucket.core.plugin.PluginRegistry
|
import gitbucket.core.plugin.PluginRegistry
|
||||||
import gitbucket.core.service.SystemSettingsService._
|
import gitbucket.core.service.SystemSettingsService.*
|
||||||
import gitbucket.core.service.{AccountService, RepositoryService}
|
import gitbucket.core.service.{AccountService, RepositoryService}
|
||||||
import gitbucket.core.ssh.SshServer
|
import gitbucket.core.ssh.SshServer
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits.*
|
||||||
import gitbucket.core.util.StringUtil._
|
import gitbucket.core.util.StringUtil.*
|
||||||
import gitbucket.core.util.{AdminAuthenticator, Mailer}
|
import gitbucket.core.util.{AdminAuthenticator, Mailer}
|
||||||
import org.apache.commons.io.IOUtils
|
import org.apache.commons.io.IOUtils
|
||||||
import org.apache.commons.mail.EmailException
|
import org.apache.commons.mail.EmailException
|
||||||
import org.json4s.jackson.Serialization
|
import org.json4s.jackson.Serialization
|
||||||
import org.scalatra._
|
import org.scalatra.*
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms.*
|
||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
|
|
||||||
import scala.collection.mutable.ListBuffer
|
import scala.collection.mutable.ListBuffer
|
||||||
@@ -151,11 +151,11 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
"testAddress" -> trim(label("", text(required)))
|
"testAddress" -> trim(label("", text(required)))
|
||||||
)(SendMailForm.apply)
|
)(SendMailForm.apply)
|
||||||
|
|
||||||
case class SendMailForm(smtp: Smtp, testAddress: String)
|
private case class SendMailForm(smtp: Smtp, testAddress: String)
|
||||||
|
|
||||||
case class DataExportForm(tableNames: List[String])
|
// case class DataExportForm(tableNames: List[String])
|
||||||
|
|
||||||
case class NewUserForm(
|
private case class NewUserForm(
|
||||||
userName: String,
|
userName: String,
|
||||||
password: String,
|
password: String,
|
||||||
fullName: String,
|
fullName: String,
|
||||||
@@ -167,7 +167,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
fileId: Option[String]
|
fileId: Option[String]
|
||||||
)
|
)
|
||||||
|
|
||||||
case class EditUserForm(
|
private case class EditUserForm(
|
||||||
userName: String,
|
userName: String,
|
||||||
password: Option[String],
|
password: Option[String],
|
||||||
fullName: String,
|
fullName: String,
|
||||||
@@ -181,7 +181,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
isRemoved: Boolean
|
isRemoved: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
case class NewGroupForm(
|
private case class NewGroupForm(
|
||||||
groupName: String,
|
groupName: String,
|
||||||
description: Option[String],
|
description: Option[String],
|
||||||
url: Option[String],
|
url: Option[String],
|
||||||
@@ -189,7 +189,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
members: String
|
members: String
|
||||||
)
|
)
|
||||||
|
|
||||||
case class EditGroupForm(
|
private case class EditGroupForm(
|
||||||
groupName: String,
|
groupName: String,
|
||||||
description: Option[String],
|
description: Option[String],
|
||||||
url: Option[String],
|
url: Option[String],
|
||||||
@@ -199,7 +199,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
isRemoved: Boolean
|
isRemoved: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
val newUserForm = mapping(
|
private val newUserForm = mapping(
|
||||||
"userName" -> trim(label("Username", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
"userName" -> trim(label("Username", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
||||||
"password" -> trim(label("Password", text(required, maxlength(40)))),
|
"password" -> trim(label("Password", text(required, maxlength(40)))),
|
||||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||||
@@ -213,7 +213,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
"fileId" -> trim(label("File ID", optional(text())))
|
"fileId" -> trim(label("File ID", optional(text())))
|
||||||
)(NewUserForm.apply)
|
)(NewUserForm.apply)
|
||||||
|
|
||||||
val editUserForm = mapping(
|
private val editUserForm = mapping(
|
||||||
"userName" -> trim(label("Username", text(required, maxlength(100), identifier))),
|
"userName" -> trim(label("Username", text(required, maxlength(100), identifier))),
|
||||||
"password" -> trim(label("Password", optional(text(maxlength(40))))),
|
"password" -> trim(label("Password", optional(text(maxlength(40))))),
|
||||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||||
@@ -229,7 +229,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
"removed" -> trim(label("Disable", boolean(disableByNotYourself("userName"))))
|
"removed" -> trim(label("Disable", boolean(disableByNotYourself("userName"))))
|
||||||
)(EditUserForm.apply)
|
)(EditUserForm.apply)
|
||||||
|
|
||||||
val newGroupForm = mapping(
|
private val newGroupForm = mapping(
|
||||||
"groupName" -> trim(label("Group name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
"groupName" -> trim(label("Group name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
||||||
"description" -> trim(label("Group description", optional(text()))),
|
"description" -> trim(label("Group description", optional(text()))),
|
||||||
"url" -> trim(label("URL", optional(text(maxlength(200))))),
|
"url" -> trim(label("URL", optional(text(maxlength(200))))),
|
||||||
@@ -237,7 +237,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
"members" -> trim(label("Members", text(required, members)))
|
"members" -> trim(label("Members", text(required, members)))
|
||||||
)(NewGroupForm.apply)
|
)(NewGroupForm.apply)
|
||||||
|
|
||||||
val editGroupForm = mapping(
|
private val editGroupForm = mapping(
|
||||||
"groupName" -> trim(label("Group name", text(required, maxlength(100), identifier))),
|
"groupName" -> trim(label("Group name", text(required, maxlength(100), identifier))),
|
||||||
"description" -> trim(label("Group description", optional(text()))),
|
"description" -> trim(label("Group description", optional(text()))),
|
||||||
"url" -> trim(label("URL", optional(text(maxlength(200))))),
|
"url" -> trim(label("URL", optional(text(maxlength(200))))),
|
||||||
@@ -363,7 +363,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/admin/plugins/_reload")(adminOnly {
|
post("/admin/plugins/_reload")(adminOnly {
|
||||||
PluginRegistry.reload(request.getServletContext(), loadSystemSettings(), request2Session(request).conn)
|
PluginRegistry.reload(request.getServletContext, loadSystemSettings(), request2Session(request).conn)
|
||||||
flash.update("info", "All plugins were reloaded.")
|
flash.update("info", "All plugins were reloaded.")
|
||||||
redirect("/admin/plugins")
|
redirect("/admin/plugins")
|
||||||
})
|
})
|
||||||
@@ -385,7 +385,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
val includeGroups = params.get("includeGroups").exists(_.toBoolean)
|
val includeGroups = params.get("includeGroups").exists(_.toBoolean)
|
||||||
val users = getAllUsers(includeRemoved, includeGroups)
|
val users = getAllUsers(includeRemoved, includeGroups)
|
||||||
val members = users.collect {
|
val members = users.collect {
|
||||||
case account if (account.isGroupAccount) =>
|
case account if account.isGroupAccount =>
|
||||||
account.userName -> getGroupMembers(account.userName).map(_.userName)
|
account.userName -> getGroupMembers(account.userName).map(_.userName)
|
||||||
}.toMap
|
}.toMap
|
||||||
|
|
||||||
@@ -406,7 +406,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
form.description,
|
form.description,
|
||||||
form.url
|
form.url
|
||||||
)
|
)
|
||||||
updateImage(form.userName, form.fileId, false)
|
updateImage(form.userName, form.fileId, clearImage = false)
|
||||||
updateAccountExtraMailAddresses(form.userName, form.extraMailAddresses.filter(_ != ""))
|
updateAccountExtraMailAddresses(form.userName, form.extraMailAddresses.filter(_ != ""))
|
||||||
redirect("/admin/users")
|
redirect("/admin/users")
|
||||||
})
|
})
|
||||||
@@ -414,12 +414,12 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
get("/admin/users/:userName/_edituser")(adminOnly {
|
get("/admin/users/:userName/_edituser")(adminOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
val extraMails = getAccountExtraMailAddresses(userName)
|
val extraMails = getAccountExtraMailAddresses(userName)
|
||||||
html.user(getAccountByUserName(userName, true), extraMails, flash.get("error"))
|
html.user(getAccountByUserName(userName, includeRemoved = true), extraMails, flash.get("error"))
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/admin/users/:name/_edituser", editUserForm)(adminOnly { form =>
|
post("/admin/users/:name/_edituser", editUserForm)(adminOnly { form =>
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName, true).map { account =>
|
getAccountByUserName(userName, includeRemoved = true).map { account =>
|
||||||
if (account.isAdmin && (form.isRemoved || !form.isAdmin) && isLastAdministrator(account)) {
|
if (account.isAdmin && (form.isRemoved || !form.isAdmin) && isLastAdministrator(account)) {
|
||||||
flash.update("error", "Account can't be turned off because this is last one administrator.")
|
flash.update("error", "Account can't be turned off because this is last one administrator.")
|
||||||
redirect(s"/admin/users/${userName}/_edituser")
|
redirect(s"/admin/users/${userName}/_edituser")
|
||||||
@@ -476,13 +476,13 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
}
|
}
|
||||||
.toList
|
.toList
|
||||||
)
|
)
|
||||||
updateImage(form.groupName, form.fileId, false)
|
updateImage(form.groupName, form.fileId, clearImage = false)
|
||||||
redirect("/admin/users")
|
redirect("/admin/users")
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/admin/users/:groupName/_editgroup")(adminOnly {
|
get("/admin/users/:groupName/_editgroup")(adminOnly {
|
||||||
val groupName = params("groupName")
|
val groupName = params("groupName")
|
||||||
html.usergroup(getAccountByUserName(groupName, true), getGroupMembers(groupName))
|
html.usergroup(getAccountByUserName(groupName, includeRemoved = true), getGroupMembers(groupName))
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/admin/users/:groupName/_editgroup", editGroupForm)(adminOnly { form =>
|
post("/admin/users/:groupName/_editgroup", editGroupForm)(adminOnly { form =>
|
||||||
@@ -496,7 +496,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
}
|
}
|
||||||
.toList
|
.toList
|
||||||
|
|
||||||
getAccountByUserName(groupName, true).map { account =>
|
getAccountByUserName(groupName, includeRemoved = true).map { account =>
|
||||||
updateGroup(groupName, form.description, form.url, form.isRemoved)
|
updateGroup(groupName, form.description, form.url, form.isRemoved)
|
||||||
|
|
||||||
if (form.isRemoved) {
|
if (form.isRemoved) {
|
||||||
@@ -528,13 +528,13 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/admin/data")(adminOnly {
|
get("/admin/data")(adminOnly {
|
||||||
import gitbucket.core.util.JDBCUtil._
|
import gitbucket.core.util.JDBCUtil.*
|
||||||
val session = request2Session(request)
|
val session = request2Session(request)
|
||||||
html.data(session.conn.allTableNames())
|
html.data(session.conn.allTableNames())
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/admin/export")(adminOnly {
|
post("/admin/export")(adminOnly {
|
||||||
import gitbucket.core.util.JDBCUtil._
|
import gitbucket.core.util.JDBCUtil.*
|
||||||
val file = request2Session(request).conn.exportAsSQL(request.getParameterValues("tableNames").toSeq)
|
val file = request2Session(request).conn.exportAsSQL(request.getParameterValues("tableNames").toSeq)
|
||||||
|
|
||||||
contentType = "application/octet-stream"
|
contentType = "application/octet-stream"
|
||||||
@@ -577,7 +577,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
for {
|
for {
|
||||||
userName <- params.get(paramName)
|
userName <- params.get(paramName)
|
||||||
loginAccount <- context.loginAccount
|
loginAccount <- context.loginAccount
|
||||||
if userName == loginAccount.userName && params.get("removed") == Some("true")
|
if userName == loginAccount.userName && params.get("removed").contains("true")
|
||||||
} yield "You can't disable your account yourself"
|
} yield "You can't disable your account yourself"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import org.json4s.{JField, JObject, JString}
|
import org.json4s.{JField, JObject, JString}
|
||||||
import org.scalatra._
|
import org.scalatra.*
|
||||||
import org.scalatra.json._
|
import org.scalatra.json.*
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms.*
|
||||||
import org.scalatra.i18n.I18nSupport
|
import org.scalatra.i18n.I18nSupport
|
||||||
import org.scalatra.servlet.ServletBase
|
import org.scalatra.servlet.ServletBase
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import gitbucket.core.model.activity.{CreateWikiPageInfo, DeleteWikiInfo, EditWi
|
|||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
import gitbucket.core.service.WebHookService.WebHookGollumPayload
|
import gitbucket.core.service.WebHookService.WebHookGollumPayload
|
||||||
import gitbucket.core.wiki.html
|
import gitbucket.core.wiki.html
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service.*
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util.*
|
||||||
import gitbucket.core.util.StringUtil._
|
import gitbucket.core.util.StringUtil.*
|
||||||
import gitbucket.core.util.SyntaxSugars._
|
import gitbucket.core.util.SyntaxSugars.*
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits.*
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory.*
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms.*
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
self: WikiService & RepositoryService & AccountService & ActivityService & WebHookService &
|
self: WikiService & RepositoryService & AccountService & ActivityService & WebHookService &
|
||||||
ReadableUsersAuthenticator & ReferrerAuthenticator =>
|
ReadableUsersAuthenticator & ReferrerAuthenticator =>
|
||||||
|
|
||||||
case class WikiPageEditForm(
|
private case class WikiPageEditForm(
|
||||||
pageName: String,
|
pageName: String,
|
||||||
content: String,
|
content: String,
|
||||||
message: Option[String],
|
message: Option[String],
|
||||||
@@ -40,7 +40,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
id: String
|
id: String
|
||||||
)
|
)
|
||||||
|
|
||||||
val newForm = mapping(
|
private val newForm = mapping(
|
||||||
"pageName" -> trim(label("Page name", text(required, maxlength(40), pageName, unique))),
|
"pageName" -> trim(label("Page name", text(required, maxlength(40), pageName, unique))),
|
||||||
"content" -> trim(label("Content", text(required, conflictForNew))),
|
"content" -> trim(label("Content", text(required, conflictForNew))),
|
||||||
"message" -> trim(label("Message", optional(text()))),
|
"message" -> trim(label("Message", optional(text()))),
|
||||||
@@ -48,7 +48,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
"id" -> trim(label("Latest commit id", text()))
|
"id" -> trim(label("Latest commit id", text()))
|
||||||
)(WikiPageEditForm.apply)
|
)(WikiPageEditForm.apply)
|
||||||
|
|
||||||
val editForm = mapping(
|
private val editForm = mapping(
|
||||||
"pageName" -> trim(label("Page name", text(required, maxlength(40), pageName))),
|
"pageName" -> trim(label("Page name", text(required, maxlength(40), pageName))),
|
||||||
"content" -> trim(label("Content", text(required, conflictForEdit))),
|
"content" -> trim(label("Content", text(required, conflictForEdit))),
|
||||||
"message" -> trim(label("Message", optional(text()))),
|
"message" -> trim(label("Message", optional(text()))),
|
||||||
@@ -170,7 +170,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
} else {
|
} else {
|
||||||
flash.update("info", "This patch was not able to be reversed.")
|
flash.update("info", "This patch was not able to be reversed.")
|
||||||
redirect(
|
redirect(
|
||||||
s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}/_compare/${from}...${to}"
|
s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}/_compare/$from...$to"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
@@ -187,7 +187,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||||
} else {
|
} else {
|
||||||
flash.update("info", "This patch was not able to be reversed.")
|
flash.update("info", "This patch was not able to be reversed.")
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki/_compare/${from}...${to}")
|
redirect(s"/${repository.owner}/${repository.name}/wiki/_compare/$from...$to")
|
||||||
}
|
}
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
}
|
}
|
||||||
@@ -283,7 +283,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
pageName,
|
pageName,
|
||||||
loginAccount.fullName,
|
loginAccount.fullName,
|
||||||
loginAccount.mailAddress,
|
loginAccount.mailAddress,
|
||||||
s"Destroyed ${pageName}"
|
s"Destroyed $pageName"
|
||||||
)
|
)
|
||||||
val deleteWikiInfo = DeleteWikiInfo(
|
val deleteWikiInfo = DeleteWikiInfo(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
@@ -344,9 +344,9 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
private def pageName: Constraint = new Constraint() {
|
private def pageName: Constraint = new Constraint() {
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||||
if (value.exists("\\/:*?\"<>|".contains(_))) {
|
if (value.exists("\\/:*?\"<>|".contains(_))) {
|
||||||
Some(s"${name} contains invalid character.")
|
Some(s"$name contains invalid character.")
|
||||||
} else if (notReservedPageName(value) && (value.startsWith("_") || value.startsWith("-"))) {
|
} else if (notReservedPageName(value) && (value.startsWith("_") || value.startsWith("-"))) {
|
||||||
Some(s"${name} starts with invalid character.")
|
Some(s"$name starts with invalid character.")
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user