mirror of
				https://github.com/gitbucket/gitbucket.git
				synced 2025-10-31 10:36:05 +01:00 
			
		
		
		
	Upgrade to scalatra-forms 0.0.4
This commit is contained in:
		| @@ -32,7 +32,7 @@ object MyBuild extends Build { | |||||||
|         "org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test", |         "org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test", | ||||||
|         "org.scalatra" %% "scalatra-json" % ScalatraVersion, |         "org.scalatra" %% "scalatra-json" % ScalatraVersion, | ||||||
|         "org.json4s" %% "json4s-jackson" % "3.2.5", |         "org.json4s" %% "json4s-jackson" % "3.2.5", | ||||||
|         "jp.sf.amateras" %% "scalatra-forms" % "0.0.2", |         "jp.sf.amateras" %% "scalatra-forms" % "0.0.4", | ||||||
|         "commons-io" % "commons-io" % "2.4", |         "commons-io" % "commons-io" % "2.4", | ||||||
|         "org.pegdown" % "pegdown" % "1.4.1", |         "org.pegdown" % "pegdown" % "1.4.1", | ||||||
|         "org.apache.commons" % "commons-compress" % "1.5", |         "org.apache.commons" % "commons-compress" % "1.5", | ||||||
|   | |||||||
| @@ -15,12 +15,13 @@ import service.AccountService | |||||||
| import javax.servlet.http.{HttpServletResponse, HttpSession, HttpServletRequest} | import javax.servlet.http.{HttpServletResponse, HttpSession, HttpServletRequest} | ||||||
| import java.text.SimpleDateFormat | import java.text.SimpleDateFormat | ||||||
| import javax.servlet.{FilterChain, ServletResponse, ServletRequest} | import javax.servlet.{FilterChain, ServletResponse, ServletRequest} | ||||||
|  | import org.scalatra.i18n._ | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Provides generic features for controller implementations. |  * Provides generic features for controller implementations. | ||||||
|  */ |  */ | ||||||
| abstract class ControllerBase extends ScalatraFilter | abstract class ControllerBase extends ScalatraFilter | ||||||
|   with ClientSideValidationFormSupport with JacksonJsonSupport with Validations { |   with ClientSideValidationFormSupport with JacksonJsonSupport with I18nSupport with Validations { | ||||||
|  |  | ||||||
|   implicit val jsonFormats = DefaultFormats |   implicit val jsonFormats = DefaultFormats | ||||||
|  |  | ||||||
| @@ -169,12 +170,12 @@ trait AccountManagementControllerBase extends ControllerBase with FileUploadCont | |||||||
|     } |     } | ||||||
|  |  | ||||||
|   protected def uniqueUserName: Constraint = new Constraint(){ |   protected def uniqueUserName: Constraint = new Constraint(){ | ||||||
|     override def validate(name: String, value: String): Option[String] = |     override def validate(name: String, value: String, messages: Messages): Option[String] = | ||||||
|       getAccountByUserName(value).map { _ => "User already exists." } |       getAccountByUserName(value).map { _ => "User already exists." } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   protected def uniqueMailAddress(paramName: String = ""): Constraint = new Constraint(){ |   protected def uniqueMailAddress(paramName: String = ""): Constraint = new Constraint(){ | ||||||
|     override def validate(name: String, value: String, params: Map[String, String]): Option[String] = |     override def validate(name: String, value: String, params: Map[String, String], messages: Messages): Option[String] = | ||||||
|       getAccountByMailAddress(value) |       getAccountByMailAddress(value) | ||||||
|         .filter { x => if(paramName.isEmpty) true else Some(x.userName) != params.get(paramName) } |         .filter { x => if(paramName.isEmpty) true else Some(x.userName) != params.get(paramName) } | ||||||
|         .map    { _ => "Mail address is already registered." } |         .map    { _ => "Mail address is already registered." } | ||||||
|   | |||||||
| @@ -4,12 +4,11 @@ import util.Directory._ | |||||||
| import util.ControlUtil._ | import util.ControlUtil._ | ||||||
| import util._ | import util._ | ||||||
| import service._ | import service._ | ||||||
| import java.io.File |  | ||||||
| import org.eclipse.jgit.api.Git | import org.eclipse.jgit.api.Git | ||||||
| import org.apache.commons.io._ |  | ||||||
| import jp.sf.amateras.scalatra.forms._ | import jp.sf.amateras.scalatra.forms._ | ||||||
| import org.eclipse.jgit.lib.{FileMode, Constants, PersonIdent} | import org.eclipse.jgit.lib.{FileMode, Constants} | ||||||
| import org.eclipse.jgit.dircache.DirCache | import org.eclipse.jgit.dircache.DirCache | ||||||
|  | import org.scalatra.i18n.Messages | ||||||
|  |  | ||||||
| class CreateRepositoryController extends CreateRepositoryControllerBase | class CreateRepositoryController extends CreateRepositoryControllerBase | ||||||
|   with RepositoryService with AccountService with WikiService with LabelsService with ActivityService |   with RepositoryService with AccountService with WikiService with LabelsService with ActivityService | ||||||
| @@ -175,7 +174,7 @@ trait CreateRepositoryControllerBase extends ControllerBase { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   private def existsAccount: Constraint = new Constraint(){ |   private def existsAccount: Constraint = new Constraint(){ | ||||||
|     override def validate(name: String, value: String): Option[String] = |     override def validate(name: String, value: String, messages: Messages): Option[String] = | ||||||
|       if(getAccountByUserName(value).isEmpty) Some("User or group does not exist.") else None |       if(getAccountByUserName(value).isEmpty) Some("User or group does not exist.") else None | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -183,7 +182,7 @@ trait CreateRepositoryControllerBase extends ControllerBase { | |||||||
|    * Duplicate check for the repository name. |    * Duplicate check for the repository name. | ||||||
|    */ |    */ | ||||||
|   private def unique: Constraint = new Constraint(){ |   private def unique: Constraint = new Constraint(){ | ||||||
|     override def validate(name: String, value: String, params: Map[String, String]): Option[String] = |     override def validate(name: String, value: String, params: Map[String, String], messages: Messages): Option[String] = | ||||||
|       params.get("owner").flatMap { userName => |       params.get("owner").flatMap { userName => | ||||||
|         getRepositoryNamesOfUser(userName).find(_ == value).map(_ => "Repository already exists.") |         getRepositoryNamesOfUser(userName).find(_ == value).map(_ => "Repository already exists.") | ||||||
|       } |       } | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ package app | |||||||
| import jp.sf.amateras.scalatra.forms._ | import jp.sf.amateras.scalatra.forms._ | ||||||
| import service._ | import service._ | ||||||
| import util.CollaboratorsAuthenticator | import util.CollaboratorsAuthenticator | ||||||
|  | import org.scalatra.i18n.Messages | ||||||
|  |  | ||||||
| class LabelsController extends LabelsControllerBase | class LabelsController extends LabelsControllerBase | ||||||
|   with LabelsService with RepositoryService with AccountService with CollaboratorsAuthenticator |   with LabelsService with RepositoryService with AccountService with CollaboratorsAuthenticator | ||||||
| @@ -51,7 +52,7 @@ trait LabelsControllerBase extends ControllerBase { | |||||||
|    * Constraint for the identifier such as user name, repository name or page name. |    * Constraint for the identifier such as user name, repository name or page name. | ||||||
|    */ |    */ | ||||||
|   private def labelName: Constraint = new Constraint(){ |   private def labelName: Constraint = new Constraint(){ | ||||||
|     override def validate(name: String, value: String): Option[String] = |     override def validate(name: String, value: String, messages: Messages): Option[String] = | ||||||
|       if(!value.matches("^[^,]+$")){ |       if(!value.matches("^[^,]+$")){ | ||||||
|         Some(s"${name} contains invalid character.") |         Some(s"${name} contains invalid character.") | ||||||
|       } else if(value.startsWith("_") || value.startsWith("-")){ |       } else if(value.startsWith("_") || value.startsWith("-")){ | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ import util.{UsersAuthenticator, OwnerAuthenticator} | |||||||
| import jp.sf.amateras.scalatra.forms._ | import jp.sf.amateras.scalatra.forms._ | ||||||
| import org.apache.commons.io.FileUtils | import org.apache.commons.io.FileUtils | ||||||
| import org.scalatra.FlashMapSupport | import org.scalatra.FlashMapSupport | ||||||
|  | import org.scalatra.i18n.Messages | ||||||
| import service.WebHookService.WebHookPayload | import service.WebHookService.WebHookPayload | ||||||
| import util.JGitUtil.CommitInfo | import util.JGitUtil.CommitInfo | ||||||
| import util.ControlUtil._ | import util.ControlUtil._ | ||||||
| @@ -179,7 +180,7 @@ trait RepositorySettingsControllerBase extends ControllerBase with FlashMapSuppo | |||||||
|    * Provides duplication check for web hook url. |    * Provides duplication check for web hook url. | ||||||
|    */ |    */ | ||||||
|   private def webHook: Constraint = new Constraint(){ |   private def webHook: Constraint = new Constraint(){ | ||||||
|     override def validate(name: String, value: String): Option[String] = |     override def validate(name: String, value: String, messages: Messages): Option[String] = | ||||||
|       getWebHookURLs(params("owner"), params("repository")).map(_.url).find(_ == value).map(_ => "URL had been registered already.") |       getWebHookURLs(params("owner"), params("repository")).map(_.url).find(_ == value).map(_ => "URL had been registered already.") | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -187,7 +188,7 @@ trait RepositorySettingsControllerBase extends ControllerBase with FlashMapSuppo | |||||||
|    * Provides Constraint to validate the collaborator name. |    * Provides Constraint to validate the collaborator name. | ||||||
|    */ |    */ | ||||||
|   private def collaborator: Constraint = new Constraint(){ |   private def collaborator: Constraint = new Constraint(){ | ||||||
|     override def validate(name: String, value: String): Option[String] = |     override def validate(name: String, value: String, messages: Messages): Option[String] = | ||||||
|       getAccountByUserName(value) match { |       getAccountByUserName(value) match { | ||||||
|         case None => Some("User does not exist.") |         case None => Some("User does not exist.") | ||||||
|         case Some(x) if(x.isGroupAccount) |         case Some(x) if(x.isGroupAccount) | ||||||
|   | |||||||
| @@ -7,8 +7,9 @@ import util.ControlUtil._ | |||||||
| import jp.sf.amateras.scalatra.forms._ | import jp.sf.amateras.scalatra.forms._ | ||||||
| import org.eclipse.jgit.api.Git | import org.eclipse.jgit.api.Git | ||||||
| import org.scalatra.FlashMapSupport | import org.scalatra.FlashMapSupport | ||||||
| import service.WikiService.WikiPageInfo | import org.scalatra.i18n.Messages | ||||||
| import scala.Some | import scala.Some | ||||||
|  | import java.util.ResourceBundle | ||||||
|  |  | ||||||
| class WikiController extends WikiControllerBase  | class WikiController extends WikiControllerBase  | ||||||
|   with WikiService with RepositoryService with AccountService with ActivityService |   with WikiService with RepositoryService with AccountService with ActivityService | ||||||
| @@ -170,12 +171,12 @@ trait WikiControllerBase extends ControllerBase with FlashMapSupport { | |||||||
|   }) |   }) | ||||||
|  |  | ||||||
|   private def unique: Constraint = new Constraint(){ |   private def unique: Constraint = new Constraint(){ | ||||||
|     override def validate(name: String, value: String, params: Map[String, String]): Option[String] = |     override def validate(name: String, value: String, params: Map[String, String], messages: Messages): Option[String] = | ||||||
|       getWikiPageList(params("owner"), params("repository")).find(_ == value).map(_ => "Page already exists.") |       getWikiPageList(params("owner"), params("repository")).find(_ == value).map(_ => "Page already exists.") | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   private def pagename: Constraint = new Constraint(){ |   private def pagename: Constraint = new Constraint(){ | ||||||
|     override def validate(name: String, value: String): Option[String] = |     override def validate(name: String, value: String, messages: Messages): Option[String] = | ||||||
|       if(value.exists("\\/:*?\"<>|".contains(_))){ |       if(value.exists("\\/:*?\"<>|".contains(_))){ | ||||||
|         Some(s"${name} contains invalid character.") |         Some(s"${name} contains invalid character.") | ||||||
|       } else if(value.startsWith("_") || value.startsWith("-")){ |       } else if(value.startsWith("_") || value.startsWith("-")){ | ||||||
| @@ -186,7 +187,7 @@ trait WikiControllerBase extends ControllerBase with FlashMapSupport { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   private def conflictForNew: Constraint = new Constraint(){ |   private def conflictForNew: Constraint = new Constraint(){ | ||||||
|     override def validate(name: String, value: String): Option[String] = { |     override def validate(name: String, value: String, messages: Messages): Option[String] = { | ||||||
|       optionIf(targetWikiPage.nonEmpty){ |       optionIf(targetWikiPage.nonEmpty){ | ||||||
|         Some("Someone has created the wiki since you started. Please reload this page and re-apply your changes.") |         Some("Someone has created the wiki since you started. Please reload this page and re-apply your changes.") | ||||||
|       } |       } | ||||||
| @@ -194,7 +195,7 @@ trait WikiControllerBase extends ControllerBase with FlashMapSupport { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   private def conflictForEdit: Constraint = new Constraint(){ |   private def conflictForEdit: Constraint = new Constraint(){ | ||||||
|     override def validate(name: String, value: String): Option[String] = { |     override def validate(name: String, value: String, messages: Messages): Option[String] = { | ||||||
|       optionIf(targetWikiPage.map(_.id != params("id")).getOrElse(false)){ |       optionIf(targetWikiPage.map(_.id != params("id")).getOrElse(false)){ | ||||||
|         Some("Someone has edited the wiki since you started. Please reload this page and re-apply your changes.") |         Some("Someone has edited the wiki since you started. Please reload this page and re-apply your changes.") | ||||||
|       } |       } | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| package util | package util | ||||||
|  |  | ||||||
| import jp.sf.amateras.scalatra.forms._ | import jp.sf.amateras.scalatra.forms._ | ||||||
|  | import org.scalatra.i18n.Messages | ||||||
|  |  | ||||||
| trait Validations { | trait Validations { | ||||||
|  |  | ||||||
| @@ -8,7 +9,7 @@ trait Validations { | |||||||
|    * Constraint for the identifier such as user name, repository name or page name. |    * Constraint for the identifier such as user name, repository name or page name. | ||||||
|    */ |    */ | ||||||
|   def identifier: Constraint = new Constraint(){ |   def identifier: Constraint = new Constraint(){ | ||||||
|     override def validate(name: String, value: String): Option[String] = |     override def validate(name: String, value: String, messages: Messages): Option[String] = | ||||||
|       if(!value.matches("^[a-zA-Z0-9\\-_.]+$")){ |       if(!value.matches("^[a-zA-Z0-9\\-_.]+$")){ | ||||||
|         Some(s"${name} contains invalid character.") |         Some(s"${name} contains invalid character.") | ||||||
|       } else if(value.startsWith("_") || value.startsWith("-")){ |       } else if(value.startsWith("_") || value.startsWith("-")){ | ||||||
| @@ -25,7 +26,7 @@ trait Validations { | |||||||
|    */ |    */ | ||||||
|   def date(constraints: Constraint*): SingleValueType[java.util.Date] = |   def date(constraints: Constraint*): SingleValueType[java.util.Date] = | ||||||
|     new SingleValueType[java.util.Date]((pattern("\\d{4}-\\d{2}-\\d{2}") +: constraints): _*){ |     new SingleValueType[java.util.Date]((pattern("\\d{4}-\\d{2}-\\d{2}") +: constraints): _*){ | ||||||
|       def convert(value: String): java.util.Date = new java.text.SimpleDateFormat("yyyy-MM-dd").parse(value) |       def convert(value: String, messages: Messages): java.util.Date = new java.text.SimpleDateFormat("yyyy-MM-dd").parse(value) | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user