Add unique checking before rename repository.

This commit is contained in:
takezoe
2014-01-18 03:54:57 +09:00
parent f33b398428
commit d50e07265e
2 changed files with 14 additions and 1 deletions

View File

@@ -24,7 +24,7 @@ trait RepositorySettingsControllerBase extends ControllerBase with FlashMapSuppo
case class OptionsForm(repositoryName: String, description: Option[String], defaultBranch: String, isPrivate: Boolean)
val optionsForm = mapping(
"repositoryName" -> trim(label("Description" , text(required, maxlength(40), identifier))), // TODO unique checking
"repositoryName" -> trim(label("Description" , text(required, maxlength(40), identifier, renameRepositoryName))),
"description" -> trim(label("Description" , optional(text()))),
"defaultBranch" -> trim(label("Default Branch" , text(required, maxlength(100)))),
"isPrivate" -> trim(label("Repository Type", boolean()))
@@ -209,4 +209,16 @@ trait RepositorySettingsControllerBase extends ControllerBase with FlashMapSuppo
}
}
/**
* Duplicate check for the rename repository name.
*/
private def renameRepositoryName: Constraint = new Constraint(){
override def validate(name: String, value: String, params: Map[String, String], messages: Messages): Option[String] =
params.get("repository").filter(_ != value).flatMap { _ =>
params.get("owner").flatMap { userName =>
getRepositoryNamesOfUser(userName).find(_ == value).map(_ => "Repository already exists.")
}
}
}
}

View File

@@ -12,6 +12,7 @@
<fieldset>
<label for="repositoryName" class="strong">Repository Name:</label>
<input type="text" name="repositoryName" id="repositoryName" value="@repository.name"/>
<span id="error-repositoryName" class="error"></span>
</fieldset>
<fieldset class="margin">
<label for="description" class="strong">Description:</label>