(refs #1286) Show whether group account on the collaborators proposal

This commit is contained in:
Naoki Takezoe
2016-11-01 16:03:02 +09:00
parent 0456739118
commit 0c3c6ea15a
4 changed files with 30 additions and 18 deletions

View File

@@ -110,10 +110,10 @@ trait IndexControllerBase extends ControllerBase {
contentType = formats("json")
org.json4s.jackson.Serialization.write(
Map("options" -> (if(params.get("userOnly").isDefined) {
getAllUsers(false).filter(!_.isGroupAccount).map(_.userName).toArray
getAllUsers(false).filter(!_.isGroupAccount).map { t => (t.userName, t.isGroupAccount) }.toArray
} else {
getAllUsers(false).map(_.userName).toArray
}))
getAllUsers(false).map { t => (t.userName, t.isGroupAccount) }.toArray
}).map { case (userName, groupAccount) => userName + ":" + groupAccount })
)
})

View File

@@ -355,8 +355,13 @@ trait RepositoryService { self: AccountService =>
/**
* Returns the list of collaborators name (user name or group name) which is sorted with ascending order.
*/
def getCollaborators(userName: String, repositoryName: String)(implicit s: Session): List[Collaborator] =
Collaborators.filter(_.byRepository(userName, repositoryName)).sortBy(_.collaboratorName).list
def getCollaborators(userName: String, repositoryName: String)(implicit s: Session): List[(Collaborator, Boolean)] =
Collaborators
.innerJoin(Accounts).on(_.collaboratorName === _.userName)
.filter { case (t1, t2) => t1.byRepository(userName, repositoryName) }
.map { case (t1, t2) => (t1, t2.groupAccount) }
.sortBy { case (t1, t2) => t1.collaboratorName }
.list
/**
* Returns the list of all collaborator name and permission which is sorted with ascending order.

View File

@@ -5,6 +5,13 @@
<script>
$(function(){
$('#@id').typeahead({
highlighter: function(item) {
var x = item.split(':');
return $('<div><strong>' + x[0] + '</strong>' + (x[1] == 'true' ? ' (group)' : '') + '</div>');
},
updater: function (item) {
return item.split(':')[0];
},
source: function (query, process) {
return $.get('@context.path/_user/proposals@if(userOnly){?userOnly}', { query: query },
function (data) {

View File

@@ -1,4 +1,4 @@
@(collaborators: List[gitbucket.core.model.Collaborator],
@(collaborators: List[(gitbucket.core.model.Collaborator, Boolean)],
isGroupRepository: Boolean,
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers
@@ -11,9 +11,9 @@
</ul>
@gitbucket.core.helper.html.account("userName", 200, false)
<input type="button" class="btn btn-default" value="Add" id="addCollaborator"/>
<input type="hidden" id="collaborators" name="collaborators" value="@collaborators.map(x => x.userName + ":" + x.permission).mkString(",")"/>
<input type="hidden" id="collaborators" name="collaborators" value="@collaborators.map(x => x._1.userName + ":" + x._1.permission).mkString(",")"/>
<div>
<span class="error" id="error-members"></span>
<span class="error" id="error-collaborators"></span>
</div>
<div class="align-right" style="margin-top: 20px;">
<input type="submit" class="btn btn-success" value="Apply changes"/>
@@ -29,7 +29,7 @@ $(function(){
});
$('#addCollaborator').click(function(){
$('#error-members').text('');
$('#error-collaborators').text('');
var userName = $('#userName').val();
// check empty
@@ -42,7 +42,7 @@ $(function(){
return $(this).data('name') == userName;
}).length > 0;
if(exists){
$('#error-members').text('User has been already added.');
$('#error-collaborators').text('User has been already added.');
return false;
}
@@ -51,9 +51,9 @@ $(function(){
'userName': userName
}, function(data, status){
if(data == 'true'){
addCollaboratorHTML(userName, 'ADMIN');
addCollaboratorHTML(userName, 'ADMIN'); // TODO isGroup
} else {
$('#error-members').text('User does not exist.');
$('#error-collaborators').text('User does not exist.');
}
});
});
@@ -67,11 +67,11 @@ $(function(){
return !(e.keyCode == 13);
});
@collaborators.map { x =>
addCollaboratorHTML('@x.collaboratorName', '@x.permission');
@collaborators.map { case (collaborator, isGroup) =>
addCollaboratorHTML('@collaborator.collaboratorName', '@collaborator.permission', @isGroup);
}
function addCollaboratorHTML(userName, permission){
function addCollaboratorHTML(userName, permission, isGroup){
var adminButton = $('<label class="btn btn-default btn-mini"><input type="radio" value="ADMIN" name="' + userName + '">Admin</label>');
if(permission == 'ADMIN'){
adminButton.addClass('active');
@@ -93,7 +93,7 @@ $(function(){
.append(readButton))
.append(' ')
.append($('<a>').attr('href', '@context.path/' + userName).text(userName))
.append(' ')
.append(isGroup ? ' (group)' : '')
.append($('<a href="#" class="remove pull-right">(remove)</a>')));
}