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