diff --git a/src/main/scala/app/CreateRepositoryController.scala b/src/main/scala/app/CreateRepositoryController.scala index b2419d0..595f5cb 100644 --- a/src/main/scala/app/CreateRepositoryController.scala +++ b/src/main/scala/app/CreateRepositoryController.scala @@ -16,7 +16,7 @@ */ trait CreateRepositoryControllerBase extends ControllerBase { self: RepositoryService with WikiService => - case class RepositoryCreationForm(name: String, description: String) // TODO Option + case class RepositoryCreationForm(name: String, description: String) // TODO Option? val form = mapping( "name" -> trim(label("Repository name", text(required, maxlength(40), repository))), diff --git a/src/main/scala/app/SettingsController.scala b/src/main/scala/app/SettingsController.scala index b57e2be..ff9ece7 100644 --- a/src/main/scala/app/SettingsController.scala +++ b/src/main/scala/app/SettingsController.scala @@ -1,12 +1,19 @@ package app import service._ +import jp.sf.amateras.scalatra.forms._ class SettingsController extends SettingsControllerBase with RepositoryService with AccountService -trait SettingsControllerBase extends ControllerBase { self: RepositoryService => - +trait SettingsControllerBase extends ControllerBase { self: RepositoryService with AccountService => + + case class CollaboratorForm(userName: String) + + val form = mapping( + "userName" -> trim(label("Username", text(required, existUser))) + )(CollaboratorForm.apply) + get("/:owner/:repository/settings") { val owner = params("owner") val repository = params("repository") @@ -24,7 +31,24 @@ val owner = params("owner") val repository = params("repository") - settings.html.collaborators(getRepository(owner, repository, servletContext).get) + settings.html.collaborators(getCollaborators(owner, repository), getRepository(owner, repository, servletContext).get) + } + + post("/:owner/:repository/settings/collaborators/_add", form) { form => + val owner = params("owner") + val repository = params("repository") + addCollaborator(owner, repository, form.userName) + redirect("/%s/%s/settings/collaborators".format(owner, repository)) + } + + def existUser: Constraint = new Constraint(){ + def validate(name: String, value: String): Option[String] = { + getAccountByUserName(value) match { + case None => Some("User does not exist.") + case Some(x) if(x.userName == context.loginAccount.get.userName) => Some("User can access this repository already.") + case Some(x) => None + } + } } } \ No newline at end of file diff --git a/src/main/scala/model/Collaborator.scala b/src/main/scala/model/Collaborator.scala new file mode 100644 index 0000000..9d0d3b9 --- /dev/null +++ b/src/main/scala/model/Collaborator.scala @@ -0,0 +1,16 @@ +package model + +import scala.slick.driver.H2Driver.simple._ + +object Collaborators extends Table[Collaborator]("COLLABORATOR") { + def userName = column[String]("USER_NAME", O PrimaryKey) + def repositoryName = column[String]("REPOSITORY_NAME") + def collaboratorName = column[String]("COLLABORATOR_NAME") + def * = userName ~ repositoryName ~ collaboratorName <> (Collaborator, Collaborator.unapply _) +} + +case class Collaborator( + userName: String, + repositoryName: String, + collaboratorName: String +) diff --git a/src/main/scala/service/RepositoryService.scala b/src/main/scala/service/RepositoryService.scala index 8f18879..c422a29 100644 --- a/src/main/scala/service/RepositoryService.scala +++ b/src/main/scala/service/RepositoryService.scala @@ -16,11 +16,10 @@ * page after the project creation to configure the project as the private repository. * * @param repositoryName the repository name - * @param userName the user name of the project owner - * @param description the project description - * @return the created project id + * @param userName the user name of the repository owner + * @param description the repository description */ - def createRepository(repositoryName: String, userName: String, description: Option[String]): Long = { + def createRepository(repositoryName: String, userName: String, description: Option[String]): Unit = { // TODO create a git repository also here? // TODO insert default labels. @@ -40,11 +39,11 @@ } /** - * Returns the specified user's repository informations. + * Returns the list of specified user's repositories information. * * @param userName the user name * @param servletContext the servlet context - * @return the repository informations which is sorted in descending order of lastActivityDate. + * @return the list of repository information which is sorted in descending order of lastActivityDate. */ def getRepositoriesOfUser(userName: String, servletContext: ServletContext): List[RepositoryInfo] = { (Query(Repositories) filter(_.userName is userName.bind) sortBy(_.lastActivityDate desc) list) map { repository => @@ -56,7 +55,7 @@ /** * Returns the specified repository information. * - * @param userName the user name + * @param userName the user name of the repository owner * @param repositoryName the repository name * @param servletContext the servlet context * @return the repository information @@ -71,7 +70,7 @@ } /** - * Returns the accessible repository informations for the specified account user. + * Returns the list of accessible repositories information for the specified account user. * * @param account the account * @param servletContext the servlet context @@ -103,14 +102,29 @@ } } } - + /** - * Updates the last activity date of the project. + * TODO Updates the last activity date of the repository. */ - def updateLastActivityDate(userName: String, projectName: String): Unit = { + def updateLastActivityDate(userName: String, repositoryName: String): Unit = { } + /** + * Add collaborator to the repository. + * + * @param userName the user name of the repository owner + * @param repositoryName the repository name + * @param collaboratorName the collaborator name + */ + def addCollaborator(userName: String, repositoryName: String, collaboratorName: String): Unit = + Collaborators.* insert(Collaborator(userName, repositoryName, collaboratorName)) + + def getCollaborators(userName: String, repositoryName: String): List[String] = + (Query(Collaborators) filter { collaborator => + (collaborator.userName is userName.bind) && (collaborator.repositoryName is repositoryName.bind) + } sortBy(_.collaboratorName) list) map(_.collaboratorName) + } object RepositoryService { diff --git a/src/main/twirl/settings/collaborators.scala.html b/src/main/twirl/settings/collaborators.scala.html index 5ab2b5e..af2513b 100644 --- a/src/main/twirl/settings/collaborators.scala.html +++ b/src/main/twirl/settings/collaborators.scala.html @@ -1,11 +1,20 @@ -@(repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context) +@(collaborators: List[String], repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context) @import context._ @html.main("Settings"){ @html.header("settings", repository) @menu("collaborators", repository){

Manage Collaborators

- - - + +
+
+ +
+ + +
} }