mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-01 19:15:59 +01:00
Implementing add collaborator stuff.
This commit is contained in:
@@ -16,7 +16,7 @@ class CreateRepositoryController extends CreateRepositoryControllerBase
|
|||||||
*/
|
*/
|
||||||
trait CreateRepositoryControllerBase extends ControllerBase { self: RepositoryService with WikiService =>
|
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(
|
val form = mapping(
|
||||||
"name" -> trim(label("Repository name", text(required, maxlength(40), repository))),
|
"name" -> trim(label("Repository name", text(required, maxlength(40), repository))),
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import service._
|
import service._
|
||||||
|
import jp.sf.amateras.scalatra.forms._
|
||||||
|
|
||||||
class SettingsController extends SettingsControllerBase with RepositoryService with AccountService
|
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") {
|
get("/:owner/:repository/settings") {
|
||||||
val owner = params("owner")
|
val owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
@@ -24,7 +31,24 @@ trait SettingsControllerBase extends ControllerBase { self: RepositoryService =>
|
|||||||
val owner = params("owner")
|
val owner = params("owner")
|
||||||
val repository = params("repository")
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
16
src/main/scala/model/Collaborator.scala
Normal file
16
src/main/scala/model/Collaborator.scala
Normal file
@@ -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
|
||||||
|
)
|
||||||
@@ -16,11 +16,10 @@ trait RepositoryService { self: AccountService =>
|
|||||||
* page after the project creation to configure the project as the private repository.
|
* page after the project creation to configure the project as the private repository.
|
||||||
*
|
*
|
||||||
* @param repositoryName the repository name
|
* @param repositoryName the repository name
|
||||||
* @param userName the user name of the project owner
|
* @param userName the user name of the repository owner
|
||||||
* @param description the project description
|
* @param description the repository description
|
||||||
* @return the created project id
|
|
||||||
*/
|
*/
|
||||||
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 create a git repository also here?
|
||||||
|
|
||||||
// TODO insert default labels.
|
// TODO insert default labels.
|
||||||
@@ -40,11 +39,11 @@ trait RepositoryService { self: AccountService =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the specified user's repository informations.
|
* Returns the list of specified user's repositories information.
|
||||||
*
|
*
|
||||||
* @param userName the user name
|
* @param userName the user name
|
||||||
* @param servletContext the servlet context
|
* @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] = {
|
def getRepositoriesOfUser(userName: String, servletContext: ServletContext): List[RepositoryInfo] = {
|
||||||
(Query(Repositories) filter(_.userName is userName.bind) sortBy(_.lastActivityDate desc) list) map { repository =>
|
(Query(Repositories) filter(_.userName is userName.bind) sortBy(_.lastActivityDate desc) list) map { repository =>
|
||||||
@@ -56,7 +55,7 @@ trait RepositoryService { self: AccountService =>
|
|||||||
/**
|
/**
|
||||||
* Returns the specified repository information.
|
* 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 repositoryName the repository name
|
||||||
* @param servletContext the servlet context
|
* @param servletContext the servlet context
|
||||||
* @return the repository information
|
* @return the repository information
|
||||||
@@ -71,7 +70,7 @@ trait RepositoryService { self: AccountService =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 account the account
|
||||||
* @param servletContext the servlet context
|
* @param servletContext the servlet context
|
||||||
@@ -103,14 +102,29 @@ trait RepositoryService { self: AccountService =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 {
|
object RepositoryService {
|
||||||
|
|||||||
@@ -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._
|
@import context._
|
||||||
@html.main("Settings"){
|
@html.main("Settings"){
|
||||||
@html.header("settings", repository)
|
@html.header("settings", repository)
|
||||||
@menu("collaborators", repository){
|
@menu("collaborators", repository){
|
||||||
<h3>Manage Collaborators</h3>
|
<h3>Manage Collaborators</h3>
|
||||||
|
<ul>
|
||||||
<input type="text" style="width: 300px; margin-bottom: 0px;"/>
|
@collaborators.map { collaboratorName =>
|
||||||
<input type="submit" class="btn" value="Add"/>
|
<li>@collaboratorName</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
<form method="POST" action="@path/@repository.owner/@repository.name/settings/collaborators/_add" validate="true">
|
||||||
|
<div>
|
||||||
|
<span class="error" id="error-userName"></span>
|
||||||
|
</div>
|
||||||
|
<input type="text" name="userName" id="userName" style="width: 300px; margin-bottom: 0px;"/>
|
||||||
|
<input type="submit" class="btn" value="Add"/>
|
||||||
|
</form>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user