diff --git a/src/main/scala/app/SettingsController.scala b/src/main/scala/app/SettingsController.scala index 366d313..e4155e5 100644 --- a/src/main/scala/app/SettingsController.scala +++ b/src/main/scala/app/SettingsController.scala @@ -66,7 +66,7 @@ /** * 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 repository = params("repository") addCollaborator(owner, repository, form.userName) @@ -74,6 +74,18 @@ }) /** + * 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. */ def collaborator: Constraint = new Constraint(){ diff --git a/src/main/scala/service/RepositoryService.scala b/src/main/scala/service/RepositoryService.scala index ab87879..d6f0bf4 100644 --- a/src/main/scala/service/RepositoryService.scala +++ b/src/main/scala/service/RepositoryService.scala @@ -26,7 +26,7 @@ val currentDate = new java.sql.Date(System.currentTimeMillis) - Repositories.* insert + Repositories insert Repository( repositoryName = repositoryName, userName = userName, @@ -130,11 +130,31 @@ * @param collaboratorName the collaborator name */ 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] = - (Query(Collaborators) filter { collaborator => - (collaborator.userName is userName.bind) && (collaborator.repositoryName is repositoryName.bind) + (Query(Collaborators) filter { c => + (c.userName is userName.bind) && (c.repositoryName is repositoryName.bind) } sortBy(_.collaboratorName) list) map(_.collaboratorName) } diff --git a/src/main/twirl/settings/collaborators.scala.html b/src/main/twirl/settings/collaborators.scala.html index af2513b..a174d21 100644 --- a/src/main/twirl/settings/collaborators.scala.html +++ b/src/main/twirl/settings/collaborators.scala.html @@ -4,12 +4,15 @@ @html.header("settings", repository) @menu("collaborators", repository){

Manage Collaborators

-