Add "include group accounts" checkbox in User management

This commit is contained in:
KOUNOIKE Yuusuke
2018-01-20 13:00:43 +09:00
parent b72556c007
commit 4a9303d7a7
3 changed files with 31 additions and 14 deletions

View File

@@ -331,12 +331,17 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
get("/admin/users")(adminOnly {
val includeRemoved = params.get("includeRemoved").map(_.toBoolean).getOrElse(false)
val users = getAllUsers(includeRemoved)
val members = users.collect { case account if(account.isGroupAccount) =>
account.userName -> getGroupMembers(account.userName).map(_.userName)
}.toMap
val includeGroups = params.get("includeGroups").map(_.toBoolean).getOrElse(false)
val users = getAllUsers(includeRemoved, includeGroups)
if(includeGroups){
val members = users.collect { case account if(account.isGroupAccount) =>
account.userName -> getGroupMembers(account.userName).map(_.userName)
}.toMap
html.userlist(users, members, includeRemoved)
html.userlist(users, members, includeRemoved, includeGroups)
}else{
html.userlist(users, Map[String, List[String]](), includeRemoved, includeGroups)
}
})
get("/admin/users/_newuser")(adminOnly {

View File

@@ -96,12 +96,19 @@ trait AccountService {
def getAccountByMailAddress(mailAddress: String, includeRemoved: Boolean = false)(implicit s: Session): Option[Account] =
Accounts filter(t => (t.mailAddress.toLowerCase === mailAddress.toLowerCase.bind) && (t.removed === false.bind, !includeRemoved)) firstOption
def getAllUsers(includeRemoved: Boolean = true)(implicit s: Session): List[Account] =
if(includeRemoved){
Accounts sortBy(_.userName) list
} else {
Accounts filter (_.removed === false.bind) sortBy(_.userName) list
}
def getAllUsers(includeRemoved: Boolean = true, includeGroups: Boolean = true)(implicit s: Session): List[Account] =
{
((includeRemoved, includeGroups) match {
case (true, true) =>
Accounts
case (true, false) =>
Accounts filter (_.groupAccount === false.bind)
case (false, true) =>
Accounts filter (_.removed === false.bind)
case (false, false) =>
Accounts filter (t => t.removed === false.bind && t.groupAccount === false.bind)
}) sortBy(_.userName) list
}
def isLastAdministrator(account: Account)(implicit s: Session): Boolean = {
if(account.isAdmin){

View File

@@ -1,4 +1,4 @@
@(users: List[gitbucket.core.model.Account], members: Map[String, List[String]], includeRemoved: Boolean)(implicit context: gitbucket.core.controller.Context)
@(users: List[gitbucket.core.model.Account], members: Map[String, List[String]], includeRemoved: Boolean, includeGroups: Boolean)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers
@gitbucket.core.html.main("Manage Users"){
@gitbucket.core.admin.html.menu("users"){
@@ -10,6 +10,10 @@
<input type="checkbox" id="includeRemoved" name="includeRemoved" @if(includeRemoved){checked}/>
Include removed users
</label>
<label for="includeGroups">
<input type="checkbox" id="includeGroups" name="includeGroups" @if(includeGroups){checked}/>
Include group accounts
</label>
<table class="table table-bordered table-hover">
@users.map { account =>
<tr>
@@ -63,8 +67,9 @@
}
<script>
$(function(){
$('#includeRemoved').click(function(){
location.href = '@context.path/admin/users?includeRemoved=' + this.checked;
$('#includeRemoved,#includeGroups').click(function(){
location.href = '@context.path/admin/users?includeRemoved=' + $('#includeRemoved').prop('checked')
+ '&includeGroups=' + $('#includeGroups').prop('checked');
});
});
</script>