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