Collaborators became removable.

This commit is contained in:
takezoe
2013-06-04 21:08:19 +09:00
parent faf162a5f0
commit 9174ed8441
4 changed files with 64 additions and 8 deletions

View File

@@ -66,13 +66,25 @@ trait SettingsControllerBase extends ControllerBase { self: RepositoryService wi
/** /**
* Add the collaborator. * Add the collaborator.
*/ */
post("/:owner/:repository/settings/collaborators/_add", collaboratorForm)(ownerOnly { form => post("/:owner/:repository/settings/collaborators/add", collaboratorForm)(ownerOnly { form =>
val owner = params("owner") val owner = params("owner")
val repository = params("repository") val repository = params("repository")
addCollaborator(owner, repository, form.userName) addCollaborator(owner, repository, form.userName)
redirect("/%s/%s/settings/collaborators".format(owner, repository)) redirect("/%s/%s/settings/collaborators".format(owner, repository))
}) })
/**
* Add the collaborator.
*/
get("/:owner/:repository/settings/collaborators/remove")(ownerOnly {
val owner = params("owner")
val repository = params("repository")
val userName = params("name")
removeCollaborator(owner, repository, userName)
redirect("/%s/%s/settings/collaborators".format(owner, repository))
})
/** /**
* Provides Constraint to validate the collaborator name. * Provides Constraint to validate the collaborator name.
*/ */

View File

@@ -26,7 +26,7 @@ trait RepositoryService { self: AccountService =>
val currentDate = new java.sql.Date(System.currentTimeMillis) val currentDate = new java.sql.Date(System.currentTimeMillis)
Repositories.* insert Repositories insert
Repository( Repository(
repositoryName = repositoryName, repositoryName = repositoryName,
userName = userName, userName = userName,
@@ -130,11 +130,31 @@ trait RepositoryService { self: AccountService =>
* @param collaboratorName the collaborator name * @param collaboratorName the collaborator name
*/ */
def addCollaborator(userName: String, repositoryName: String, collaboratorName: String): Unit = def addCollaborator(userName: String, repositoryName: String, collaboratorName: String): Unit =
Collaborators.* insert(Collaborator(userName, repositoryName, collaboratorName)) Collaborators insert(Collaborator(userName, repositoryName, collaboratorName))
/**
* Remove collaborator from the repository.
*
* @param userName the user name of the repository owner
* @param repositoryName the repository name
* @param collaboratorName the collaborator name
*/
def removeCollaborator(userName: String, repositoryName: String, collaboratorName: String): Unit =
(Query(Collaborators) filter { c =>
(c.userName is userName.bind) && (c.repositoryName is repositoryName.bind) && (c.collaboratorName is collaboratorName.bind)
}).delete
/**
* Returns the list of collaborators name which is sorted with ascending order.
*
* @param userName the user name of the repository owner
* @param repositoryName the repository name
* @return the list of collaborators name
*/
def getCollaborators(userName: String, repositoryName: String): List[String] = def getCollaborators(userName: String, repositoryName: String): List[String] =
(Query(Collaborators) filter { collaborator => (Query(Collaborators) filter { c =>
(collaborator.userName is userName.bind) && (collaborator.repositoryName is repositoryName.bind) (c.userName is userName.bind) && (c.repositoryName is repositoryName.bind)
} sortBy(_.collaboratorName) list) map(_.collaboratorName) } sortBy(_.collaboratorName) list) map(_.collaboratorName)
} }

View File

@@ -4,12 +4,15 @@
@html.header("settings", repository) @html.header("settings", repository)
@menu("collaborators", repository){ @menu("collaborators", repository){
<h3>Manage Collaborators</h3> <h3>Manage Collaborators</h3>
<ul> <ul class="collaborator">
@collaborators.map { collaboratorName => @collaborators.map { collaboratorName =>
<li>@collaboratorName</li> <li>
<a href="@path/@collaboratorName">@collaboratorName</a>
<a href="@path/@repository.owner/@repository.name/settings/collaborators/remove?name=@collaboratorName" class="remove">(remove)</a>
</li>
} }
</ul> </ul>
<form method="POST" action="@path/@repository.owner/@repository.name/settings/collaborators/_add" validate="true"> <form method="POST" action="@path/@repository.owner/@repository.name/settings/collaborators/add" validate="true">
<div> <div>
<span class="error" id="error-userName"></span> <span class="error" id="error-userName"></span>
</div> </div>

View File

@@ -152,4 +152,25 @@ dd {
hr { hr {
margin-top: 4px; margin-top: 4px;
margin-bottom: 4px; margin-bottom: 4px;
}
ul.collaborator {
list-style-type: none;
margin-left: 0px;
}
ul.collaborator li {
background-color: #eee;
border: 1px solid #ccc;
border-radius: 3px;
padding: 6px;
}
ul.collaborator li:hover {
background-color: #f8f8f8;
}
ul.collaborator a.remove {
color: #dd0000;
text-decoration: underline;
} }