diff --git a/src/main/scala/gitbucket/core/controller/AccountController.scala b/src/main/scala/gitbucket/core/controller/AccountController.scala index 0b71485..12ec24e 100644 --- a/src/main/scala/gitbucket/core/controller/AccountController.scala +++ b/src/main/scala/gitbucket/core/controller/AccountController.scala @@ -179,8 +179,8 @@ 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 diff --git a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala index ed578d0..ded55b3 100644 --- a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala +++ b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala @@ -179,36 +179,39 @@ 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 }) diff --git a/src/main/scala/gitbucket/core/service/AccountService.scala b/src/main/scala/gitbucket/core/service/AccountService.scala index 5325787..04d7a41 100644 --- a/src/main/scala/gitbucket/core/service/AccountService.scala +++ b/src/main/scala/gitbucket/core/service/AccountService.scala @@ -97,10 +97,10 @@ 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]) diff --git a/src/main/twirl/gitbucket/core/account/register.scala.html b/src/main/twirl/gitbucket/core/account/register.scala.html index 94f95ab..8dc7c59 100644 --- a/src/main/twirl/gitbucket/core/account/register.scala.html +++ b/src/main/twirl/gitbucket/core/account/register.scala.html @@ -2,36 +2,36 @@ @import context._ @import gitbucket.core.view.helpers._ @html.main("Create your account"){ -
+

Create your account

- +
- +
- +
- +
- +
diff --git a/src/main/twirl/gitbucket/core/admin/user.scala.html b/src/main/twirl/gitbucket/core/admin/user.scala.html index 3237545..6723524 100644 --- a/src/main/twirl/gitbucket/core/admin/user.scala.html +++ b/src/main/twirl/gitbucket/core/admin/user.scala.html @@ -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)
diff --git a/src/main/twirl/gitbucket/core/admin/usergroup.scala.html b/src/main/twirl/gitbucket/core/admin/usergroup.scala.html index ac8044d..eaf5a36 100644 --- a/src/main/twirl/gitbucket/core/admin/usergroup.scala.html +++ b/src/main/twirl/gitbucket/core/admin/usergroup.scala.html @@ -5,7 +5,7 @@ @admin.html.menu("users"){
-
+
@@ -31,7 +31,7 @@ @helper.html.uploadavatar(account)
-
+
    diff --git a/src/main/twirl/gitbucket/core/signinform.scala.html b/src/main/twirl/gitbucket/core/signinform.scala.html index bf14229..5b0ff74 100644 --- a/src/main/twirl/gitbucket/core/signinform.scala.html +++ b/src/main/twirl/gitbucket/core/signinform.scala.html @@ -1,14 +1,7 @@ @(systemSettings: gitbucket.core.service.SystemSettingsService.SystemSettings)(implicit context: gitbucket.core.controller.Context) @import context._
    -
    - @if(systemSettings.allowAccountRegistration){ - - } - Sign in -
    +
    Sign in
    • @@ -23,6 +16,9 @@
    + @if(systemSettings.allowAccountRegistration){ + or Create new account + }
diff --git a/src/main/webapp/assets/common/css/gitbucket.css b/src/main/webapp/assets/common/css/gitbucket.css index 32cc167..a2774c1 100644 --- a/src/main/webapp/assets/common/css/gitbucket.css +++ b/src/main/webapp/assets/common/css/gitbucket.css @@ -316,6 +316,11 @@ margin-bottom: 0px; } +div.row { + margin-left: 0px; + margin-right: 0px; +} + ul.nav-tabs { height: 42px; }