mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-13 08:55:50 +01:00
(refs #533)Add checking for the last one administrator.
This commit is contained in:
@@ -179,8 +179,8 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
val userName = params("userName")
|
||||
|
||||
getAccountByUserName(userName, true).map { account =>
|
||||
if(isLastAdministrator(userName)){
|
||||
flash += "error" -> "Account can't be removed because this is the last administrator."
|
||||
if(isLastAdministrator(account)){
|
||||
flash += "error" -> "Account can't be removed because this is last one administrator."
|
||||
redirect(s"/${userName}/_edit")
|
||||
} else {
|
||||
// // Remove repositories
|
||||
|
||||
@@ -179,36 +179,39 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
|
||||
get("/admin/users/:userName/_edituser")(adminOnly {
|
||||
val userName = params("userName")
|
||||
html.user(getAccountByUserName(userName, true))
|
||||
html.user(getAccountByUserName(userName, true), flash.get("error"))
|
||||
})
|
||||
|
||||
post("/admin/users/:name/_edituser", editUserForm)(adminOnly { form =>
|
||||
val userName = params("userName")
|
||||
getAccountByUserName(userName, true).map { account =>
|
||||
if(account.isAdmin && (form.isRemoved || !form.isAdmin) && isLastAdministrator(account)){
|
||||
flash += "error" -> "Account can't be turned off because this is last one administrator."
|
||||
redirect(s"/admin/users/${userName}/_edituser")
|
||||
} else {
|
||||
if(form.isRemoved){
|
||||
// Remove repositories
|
||||
// getRepositoryNamesOfUser(userName).foreach { repositoryName =>
|
||||
// deleteRepository(userName, repositoryName)
|
||||
// FileUtils.deleteDirectory(getRepositoryDir(userName, repositoryName))
|
||||
// FileUtils.deleteDirectory(getWikiRepositoryDir(userName, repositoryName))
|
||||
// FileUtils.deleteDirectory(getTemporaryDir(userName, repositoryName))
|
||||
// }
|
||||
// Remove from GROUP_MEMBER, COLLABORATOR and REPOSITORY
|
||||
removeUserRelatedData(userName)
|
||||
}
|
||||
|
||||
if(form.isRemoved){
|
||||
// Remove repositories
|
||||
// getRepositoryNamesOfUser(userName).foreach { repositoryName =>
|
||||
// deleteRepository(userName, repositoryName)
|
||||
// FileUtils.deleteDirectory(getRepositoryDir(userName, repositoryName))
|
||||
// FileUtils.deleteDirectory(getWikiRepositoryDir(userName, repositoryName))
|
||||
// FileUtils.deleteDirectory(getTemporaryDir(userName, repositoryName))
|
||||
// }
|
||||
// Remove from GROUP_MEMBER, COLLABORATOR and REPOSITORY
|
||||
removeUserRelatedData(userName)
|
||||
updateAccount(account.copy(
|
||||
password = form.password.map(sha1).getOrElse(account.password),
|
||||
fullName = form.fullName,
|
||||
mailAddress = form.mailAddress,
|
||||
isAdmin = form.isAdmin,
|
||||
url = form.url,
|
||||
isRemoved = form.isRemoved))
|
||||
|
||||
updateImage(userName, form.fileId, form.clearImage)
|
||||
redirect("/admin/users")
|
||||
}
|
||||
|
||||
updateAccount(account.copy(
|
||||
password = form.password.map(sha1).getOrElse(account.password),
|
||||
fullName = form.fullName,
|
||||
mailAddress = form.mailAddress,
|
||||
isAdmin = form.isAdmin,
|
||||
url = form.url,
|
||||
isRemoved = form.isRemoved))
|
||||
|
||||
updateImage(userName, form.fileId, form.clearImage)
|
||||
redirect("/admin/users")
|
||||
|
||||
} getOrElse NotFound
|
||||
})
|
||||
|
||||
|
||||
@@ -97,10 +97,10 @@ 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 =>
|
||||
def isLastAdministrator(account: Account)(implicit s: Session): Boolean = {
|
||||
if(account.isAdmin){
|
||||
(Accounts filter (_.removed === false.bind) filter (_.isAdmin === true.bind) map (_.userName.length)).first == 1
|
||||
} getOrElse false
|
||||
} else false
|
||||
}
|
||||
|
||||
def createAccount(userName: String, password: String, fullName: String, mailAddress: String, isAdmin: Boolean, url: Option[String])
|
||||
|
||||
@@ -2,36 +2,36 @@
|
||||
@import context._
|
||||
@import gitbucket.core.view.helpers._
|
||||
@html.main("Create your account"){
|
||||
<div class="container body">
|
||||
<div class="container body main-center">
|
||||
<h3>Create your account</h3>
|
||||
<form action="@path/register" method="POST" validate="true">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<fieldset>
|
||||
<label for="userName" class="strong">Username:</label>
|
||||
<input type="text" name="userName" id="userName" value="" autofocus/>
|
||||
<input type="text" name="userName" id="userName" value="" class="form-control" autofocus/>
|
||||
<span id="error-userName" class="error"></span>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="password" class="strong">
|
||||
Password:
|
||||
</label>
|
||||
<input type="password" name="password" id="password" value=""/>
|
||||
<input type="password" name="password" id="password" class="form-control" value=""/>
|
||||
<span id="error-password" class="error"></span>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="fullName" class="strong">Full Name:</label>
|
||||
<input type="text" name="fullName" id="fullName" value=""/>
|
||||
<input type="text" name="fullName" id="fullName" class="form-control" value=""/>
|
||||
<span id="error-fullName" class="error"></span>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="mailAddress" class="strong">Mail Address:</label>
|
||||
<input type="text" name="mailAddress" id="mailAddress" value=""/>
|
||||
<input type="text" name="mailAddress" id="mailAddress" class="form-control" value=""/>
|
||||
<span id="error-mailAddress" class="error"></span>
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<label for="url" class="strong">URL (optional):</label>
|
||||
<input type="text" name="url" id="url" style="width: 400px;" value=""/>
|
||||
<input type="text" name="url" id="url" class="form-control" value=""/>
|
||||
<span id="error-url" class="error"></span>
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
@(account: Option[gitbucket.core.model.Account])(implicit context: gitbucket.core.controller.Context)
|
||||
@(account: Option[gitbucket.core.model.Account], error: Option[Any] = None)(implicit context: gitbucket.core.controller.Context)
|
||||
@import context._
|
||||
@html.main(if(account.isEmpty) "New User" else "Update User"){
|
||||
@admin.html.menu("users"){
|
||||
@helper.html.error(error)
|
||||
<form method="POST" action="@if(account.isEmpty){@path/admin/users/_newuser} else {@path/admin/users/@account.get.userName/_edituser}" validate="true">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
@admin.html.menu("users"){
|
||||
<form method="POST" action="@if(account.isEmpty){@path/admin/users/_newgroup} else {@path/admin/users/@account.get.userName/_editgroup}" validate="true">
|
||||
<div class="row">
|
||||
<div class="col-md-5">
|
||||
<div class="col-md-6">
|
||||
<fieldset class="form-group">
|
||||
<label for="groupName" class="strong">Group name</label>
|
||||
<div>
|
||||
@@ -31,7 +31,7 @@
|
||||
@helper.html.uploadavatar(account)
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="col-md-7">
|
||||
<div class="col-md-6">
|
||||
<fieldset class="form-group">
|
||||
<label class="strong">Members</label>
|
||||
<ul id="member-list" class="collaborator">
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
@(systemSettings: gitbucket.core.service.SystemSettingsService.SystemSettings)(implicit context: gitbucket.core.controller.Context)
|
||||
@import context._
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading strong">
|
||||
@if(systemSettings.allowAccountRegistration){
|
||||
<div class="pull-right">
|
||||
<a href="@path/register" class="btn btn-mini">Create new account</a>
|
||||
</div>
|
||||
}
|
||||
Sign in
|
||||
</div>
|
||||
<div class="panel-heading strong">Sign in</div>
|
||||
<ul class="list-group list-group-flush">
|
||||
<li class="list-group-item">
|
||||
<form action="@path/signin" method="POST" validate="true">
|
||||
@@ -23,6 +16,9 @@
|
||||
<input type="password" name="password" id="password" class="form-control"/>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-success" value="Sign in"/>
|
||||
@if(systemSettings.allowAccountRegistration){
|
||||
or <a href="@path/register">Create new account</a>
|
||||
}
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@@ -316,6 +316,11 @@ div.box-header {
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
div.row {
|
||||
margin-left: 0px;
|
||||
margin-right: 0px;
|
||||
}
|
||||
|
||||
ul.nav-tabs {
|
||||
height: 42px;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user