(refs #102)Add validation and auto completion to the transfer user name field

This commit is contained in:
takezoe
2014-01-18 06:44:39 +09:00
parent fba81138ea
commit 89bfcdc44e
2 changed files with 24 additions and 13 deletions

View File

@@ -48,7 +48,7 @@ trait RepositorySettingsControllerBase extends ControllerBase with FlashMapSuppo
case class TransferOwnerShipForm(newOwner: String)
val transferForm = mapping(
"newOwner" -> trim(label("New owner", text(required))) // TODO user and repository existence check
"newOwner" -> trim(label("New owner", text(required, transferUser)))
)(TransferOwnerShipForm.apply)
/**
@@ -256,4 +256,20 @@ trait RepositorySettingsControllerBase extends ControllerBase with FlashMapSuppo
}
}
/**
* Provides Constraint to validate the repository transfer user.
*/
private def transferUser: Constraint = new Constraint(){
override def validate(name: String, value: String, messages: Messages): Option[String] =
getAccountByUserName(value) match {
case None => Some("User does not exist.")
case Some(x) => if(x.userName == params("owner")){
Some("This is current repository owner.")
} else {
params.get("repository").flatMap { repositoryName =>
getRepositoryNamesOfUser(x.userName).find(_ == repositoryName).map{ _ => "User already has same repository." }
}
}
}
}
}