mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-01-06 23:52:18 +01:00
(refs #533)Add remove user checking for the last one administrator.
This commit is contained in:
@@ -155,7 +155,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
get("/:userName/_edit")(oneselfOnly {
|
||||
val userName = params("userName")
|
||||
getAccountByUserName(userName).map { x =>
|
||||
html.edit(x, flash.get("info"))
|
||||
html.edit(x, flash.get("info"), flash.get("error"))
|
||||
} getOrElse NotFound
|
||||
})
|
||||
|
||||
@@ -178,7 +178,11 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
get("/:userName/_delete")(oneselfOnly {
|
||||
val userName = params("userName")
|
||||
|
||||
getAccountByUserName(userName, true).foreach { account =>
|
||||
getAccountByUserName(userName, true).map { account =>
|
||||
if(isLastAdministrator(userName)){
|
||||
flash += "error" -> "Account can't be removed because this is the last administrator."
|
||||
redirect(s"/${userName}/_edit")
|
||||
} else {
|
||||
// // Remove repositories
|
||||
// getRepositoryNamesOfUser(userName).foreach { repositoryName =>
|
||||
// deleteRepository(userName, repositoryName)
|
||||
@@ -187,14 +191,12 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
// FileUtils.deleteDirectory(getTemporaryDir(userName, repositoryName))
|
||||
// }
|
||||
// // Remove from GROUP_MEMBER, COLLABORATOR and REPOSITORY
|
||||
// removeUserRelatedData(userName)
|
||||
|
||||
removeUserRelatedData(userName)
|
||||
updateAccount(account.copy(isRemoved = true))
|
||||
}
|
||||
|
||||
session.invalidate
|
||||
redirect("/")
|
||||
removeUserRelatedData(userName)
|
||||
updateAccount(account.copy(isRemoved = true))
|
||||
session.invalidate
|
||||
redirect("/")
|
||||
}
|
||||
} getOrElse NotFound
|
||||
})
|
||||
|
||||
get("/:userName/_ssh")(oneselfOnly {
|
||||
|
||||
@@ -97,6 +97,12 @@ trait AccountService {
|
||||
Accounts filter (_.removed === false.bind) sortBy(_.userName) list
|
||||
}
|
||||
|
||||
def isLastAdministrator(userName: String)(implicit s: Session): Boolean = {
|
||||
getAccountByUserName(userName).collect { case account if account.isAdmin =>
|
||||
(Accounts filter (_.removed === false.bind) filter (_.isAdmin === true.bind) map (_.userName.length)).first == 1
|
||||
} getOrElse false
|
||||
}
|
||||
|
||||
def createAccount(userName: String, password: String, fullName: String, mailAddress: String, isAdmin: Boolean, url: Option[String])
|
||||
(implicit s: Session): Unit =
|
||||
Accounts insert Account(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@(account: gitbucket.core.model.Account, info: Option[Any])(implicit context: gitbucket.core.controller.Context)
|
||||
@(account: gitbucket.core.model.Account, info: Option[Any], error: Option[Any])(implicit context: gitbucket.core.controller.Context)
|
||||
@import gitbucket.core.util.LDAPUtil
|
||||
@import context._
|
||||
@import gitbucket.core.view.helpers._
|
||||
@@ -6,6 +6,7 @@
|
||||
<div class="container body">
|
||||
@menu("profile", settings.ssh){
|
||||
@helper.html.information(info)
|
||||
@helper.html.error(error)
|
||||
@if(LDAPUtil.isDummyMailAddress(account)){<div class="alert alert-danger">Please register your mail address.</div>}
|
||||
<form action="@url(account.userName)/_edit" method="POST" validate="true">
|
||||
<div class="panel panel-default">
|
||||
|
||||
Reference in New Issue
Block a user