mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 05:25:50 +01:00
(refs #114)Add remove option to user management.
This commit is contained in:
@@ -30,7 +30,7 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
get("/_user/proposals")(usersOnly {
|
get("/_user/proposals")(usersOnly {
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
org.json4s.jackson.Serialization.write(
|
org.json4s.jackson.Serialization.write(
|
||||||
Map("options" -> getAllUsers.filter(!_.isGroupAccount).map(_.userName).toArray)
|
Map("options" -> getAllUsers().filter(!_.isGroupAccount).map(_.userName).toArray)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
|||||||
url: Option[String], fileId: Option[String])
|
url: Option[String], fileId: Option[String])
|
||||||
|
|
||||||
case class EditUserForm(userName: String, password: Option[String], fullName: String,
|
case class EditUserForm(userName: String, password: Option[String], fullName: String,
|
||||||
mailAddress: String, isAdmin: Boolean,
|
mailAddress: String, isAdmin: Boolean, url: Option[String],
|
||||||
url: Option[String], fileId: Option[String], clearImage: Boolean)
|
fileId: Option[String], clearImage: Boolean, isRemoved: Boolean)
|
||||||
|
|
||||||
case class NewGroupForm(groupName: String, url: Option[String], fileId: Option[String],
|
case class NewGroupForm(groupName: String, url: Option[String], fileId: Option[String],
|
||||||
memberNames: Option[String])
|
memberNames: Option[String])
|
||||||
@@ -44,7 +44,8 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
|||||||
"isAdmin" -> trim(label("User Type" ,boolean())),
|
"isAdmin" -> trim(label("User Type" ,boolean())),
|
||||||
"url" -> trim(label("URL" ,optional(text(maxlength(200))))),
|
"url" -> trim(label("URL" ,optional(text(maxlength(200))))),
|
||||||
"fileId" -> trim(label("File ID" ,optional(text()))),
|
"fileId" -> trim(label("File ID" ,optional(text()))),
|
||||||
"clearImage" -> trim(label("Clear image" , boolean()))
|
"clearImage" -> trim(label("Clear image" ,boolean())),
|
||||||
|
"removed" -> trim(label("Disable" ,boolean()))
|
||||||
)(EditUserForm.apply)
|
)(EditUserForm.apply)
|
||||||
|
|
||||||
val newGroupForm = mapping(
|
val newGroupForm = mapping(
|
||||||
@@ -63,11 +64,13 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
|||||||
)(EditGroupForm.apply)
|
)(EditGroupForm.apply)
|
||||||
|
|
||||||
get("/admin/users")(adminOnly {
|
get("/admin/users")(adminOnly {
|
||||||
val users = getAllUsers()
|
val includeRemoved = params.get("includeRemoved").map(_.toBoolean).getOrElse(false)
|
||||||
|
val users = getAllUsers(includeRemoved)
|
||||||
|
|
||||||
val members = users.collect { case account if(account.isGroupAccount) =>
|
val members = users.collect { case account if(account.isGroupAccount) =>
|
||||||
account.userName -> getGroupMembers(account.userName)
|
account.userName -> getGroupMembers(account.userName)
|
||||||
}.toMap
|
}.toMap
|
||||||
admin.users.html.list(users, members)
|
admin.users.html.list(users, members, includeRemoved)
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/admin/users/_newuser")(adminOnly {
|
get("/admin/users/_newuser")(adminOnly {
|
||||||
@@ -93,7 +96,8 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
|||||||
fullName = form.fullName,
|
fullName = form.fullName,
|
||||||
mailAddress = form.mailAddress,
|
mailAddress = form.mailAddress,
|
||||||
isAdmin = form.isAdmin,
|
isAdmin = form.isAdmin,
|
||||||
url = form.url))
|
url = form.url,
|
||||||
|
isRemoved = form.isRemoved))
|
||||||
|
|
||||||
updateImage(userName, form.fileId, form.clearImage)
|
updateImage(userName, form.fileId, form.clearImage)
|
||||||
redirect("/admin/users")
|
redirect("/admin/users")
|
||||||
|
|||||||
@@ -57,7 +57,12 @@ trait AccountService {
|
|||||||
def getAccountByMailAddress(mailAddress: String): Option[Account] =
|
def getAccountByMailAddress(mailAddress: String): Option[Account] =
|
||||||
Query(Accounts) filter(_.mailAddress is mailAddress.bind) firstOption
|
Query(Accounts) filter(_.mailAddress is mailAddress.bind) firstOption
|
||||||
|
|
||||||
def getAllUsers(): List[Account] = Query(Accounts) sortBy(_.userName) list
|
def getAllUsers(includeRemoved: Boolean = true): List[Account] =
|
||||||
|
if(includeRemoved){
|
||||||
|
Query(Accounts) sortBy(_.userName) list
|
||||||
|
} else {
|
||||||
|
Query(Accounts) filter (_.removed is false.bind) sortBy(_.userName) list
|
||||||
|
}
|
||||||
|
|
||||||
def createAccount(userName: String, password: String, fullName: String, mailAddress: String, isAdmin: Boolean, url: Option[String]): Unit =
|
def createAccount(userName: String, password: String, fullName: String, mailAddress: String, isAdmin: Boolean, url: Option[String]): Unit =
|
||||||
Accounts insert Account(
|
Accounts insert Account(
|
||||||
@@ -77,7 +82,7 @@ trait AccountService {
|
|||||||
def updateAccount(account: Account): Unit =
|
def updateAccount(account: Account): Unit =
|
||||||
Accounts
|
Accounts
|
||||||
.filter { a => a.userName is account.userName.bind }
|
.filter { a => a.userName is account.userName.bind }
|
||||||
.map { a => a.password ~ a.fullName ~ a.mailAddress ~ a.isAdmin ~ a.url.? ~ a.registeredDate ~ a.updatedDate ~ a.lastLoginDate.? }
|
.map { a => a.password ~ a.fullName ~ a.mailAddress ~ a.isAdmin ~ a.url.? ~ a.registeredDate ~ a.updatedDate ~ a.lastLoginDate.? ~ a.removed }
|
||||||
.update (
|
.update (
|
||||||
account.password,
|
account.password,
|
||||||
account.fullName,
|
account.fullName,
|
||||||
@@ -86,7 +91,8 @@ trait AccountService {
|
|||||||
account.url,
|
account.url,
|
||||||
account.registeredDate,
|
account.registeredDate,
|
||||||
currentDate,
|
currentDate,
|
||||||
account.lastLoginDate)
|
account.lastLoginDate,
|
||||||
|
account.isRemoved)
|
||||||
|
|
||||||
def updateAvatarImage(userName: String, image: Option[String]): Unit =
|
def updateAvatarImage(userName: String, image: Option[String]): Unit =
|
||||||
Accounts.filter(_.userName is userName.bind).map(_.image.?).update(image)
|
Accounts.filter(_.userName is userName.bind).map(_.image.?).update(image)
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
@(users: List[model.Account], members: Map[String, List[String]])(implicit context: app.Context)
|
@(users: List[model.Account], members: Map[String, List[String]], includeRemoved: Boolean)(implicit context: app.Context)
|
||||||
@import context._
|
@import context._
|
||||||
@import view.helpers._
|
@import view.helpers._
|
||||||
@html.main("Manage Users"){
|
@html.main("Manage Users"){
|
||||||
@admin.html.menu("users"){
|
@admin.html.menu("users"){
|
||||||
<div style="text-align: right; margin-bottom: 4px;">
|
<div class="pull-right" style="margin-bottom: 4px;">
|
||||||
<a href="@path/admin/users/_newuser" class="btn">New User</a>
|
<a href="@path/admin/users/_newuser" class="btn">New User</a>
|
||||||
<a href="@path/admin/users/_newgroup" class="btn">New Group</a>
|
<a href="@path/admin/users/_newgroup" class="btn">New Group</a>
|
||||||
</div>
|
</div>
|
||||||
|
<label for="includeRemoved">
|
||||||
|
<input type="checkbox" id="includeRemoved" name="includeRemoved" @if(includeRemoved){checked}/>
|
||||||
|
Include removed users
|
||||||
|
</label>
|
||||||
<table class="table table-bordered table-hover">
|
<table class="table table-bordered table-hover">
|
||||||
@users.map { account =>
|
@users.map { account =>
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td @if(account.isRemoved){style="background-color: #dddddd;"}>
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
@if(account.isGroupAccount){
|
@if(account.isGroupAccount){
|
||||||
<a href="@path/admin/users/@account.userName/_editgroup">Edit</a>
|
<a href="@path/admin/users/@account.userName/_editgroup">Edit</a>
|
||||||
@@ -58,3 +62,10 @@
|
|||||||
</table>
|
</table>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
<script>
|
||||||
|
$(function(){
|
||||||
|
$('#includeRemoved').click(function(){
|
||||||
|
location.href = '@path/admin/users?includeRemoved=' + this.checked;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -11,6 +11,12 @@
|
|||||||
<span id="error-userName" class="error"></span>
|
<span id="error-userName" class="error"></span>
|
||||||
</div>
|
</div>
|
||||||
<input type="text" name="userName" id="userName" value="@account.map(_.userName)"@if(account.isDefined){ readonly}/>
|
<input type="text" name="userName" id="userName" value="@account.map(_.userName)"@if(account.isDefined){ readonly}/>
|
||||||
|
@if(account.isDefined){
|
||||||
|
<label for="removed">
|
||||||
|
<input type="checkbox" name="removed" id="removed" value="true" @if(account.get.isRemoved){checked}/>
|
||||||
|
Disable
|
||||||
|
</label>
|
||||||
|
}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
@if(account.map(_.password.nonEmpty).getOrElse(true)){
|
@if(account.map(_.password.nonEmpty).getOrElse(true)){
|
||||||
<fieldset>
|
<fieldset>
|
||||||
|
|||||||
Reference in New Issue
Block a user