diff --git a/src/main/resources/update/1_0.sql b/src/main/resources/update/1_0.sql index a022596..16195ab 100644 --- a/src/main/resources/update/1_0.sql +++ b/src/main/resources/update/1_0.sql @@ -2,7 +2,7 @@ USER_NAME VARCHAR(100) NOT NULL, MAIL_ADDRESS VARCHAR(100) NOT NULL, PASSWORD VARCHAR(20) NOT NULL, - USER_TYPE INT DEFAULT 0 NOT NULL, + ADMINISTRATOR BOOLEAN NOT NULL, URL VARCHAR(200), REGISTERED_DATE TIMESTAMP NOT NULL, UPDATED_DATE TIMESTAMP NOT NULL, @@ -12,7 +12,7 @@ CREATE TABLE REPOSITORY( REPOSITORY_NAME VARCHAR(100) NOT NULL, USER_NAME VARCHAR(100) NOT NULL, - REPOSITORY_TYPE INT DEFAULT 0 NOT NULL, + PRIVATE BOOLEAN NOT NULL, DESCRIPTION TEXT, DEFAULT_BRANCH VARCHAR(100), REGISTERED_DATE TIMESTAMP NOT NULL, @@ -35,6 +35,7 @@ ASSIGNED_USER_NAME VARCHAR(100), TITLE TEXT NOT NULL, CONTENT TEXT, + CLOSED BOOLEAN NOT NULL, REGISTERED_DATE TIMESTAMP NOT NULL, UPDATED_DATE TIMESTAMP NOT NULL ); @@ -113,7 +114,7 @@ USER_NAME, MAIL_ADDRESS, PASSWORD, - USER_TYPE, + ADMINISTRATOR, URL, REGISTERED_DATE, UPDATED_DATE, @@ -122,7 +123,7 @@ 'root', 'root@localhost', 'root', - 1, + true, 'https://github.com/takezoe/gitbucket', SYSDATE, SYSDATE, diff --git a/src/main/scala/app/SettingsController.scala b/src/main/scala/app/SettingsController.scala index f06d4ec..459c883 100644 --- a/src/main/scala/app/SettingsController.scala +++ b/src/main/scala/app/SettingsController.scala @@ -12,12 +12,12 @@ trait SettingsControllerBase extends ControllerBase { self: RepositoryService with AccountService with OwnerOnlyAuthenticator => - case class OptionsForm(description: Option[String], defaultBranch: String, repositoryType: Int) + case class OptionsForm(description: Option[String], defaultBranch: String, isPrivate: Boolean) val optionsForm = mapping( - "description" -> trim(label("Description" , optional(text()))), - "defaultBranch" -> trim(label("Default Branch" , text(required, maxlength(100)))), - "repositoryType" -> trim(label("Repository Type", number())) + "description" -> trim(label("Description" , optional(text()))), + "defaultBranch" -> trim(label("Default Branch" , text(required, maxlength(100)))), + "isPrivate" -> trim(label("Repository Type", boolean())) )(OptionsForm.apply) case class CollaboratorForm(userName: String) @@ -57,7 +57,7 @@ val repository = params("repository") // save repository options - saveRepositoryOptions(owner, repository, form.description, form.defaultBranch, form.repositoryType) + saveRepositoryOptions(owner, repository, form.description, form.defaultBranch, form.isPrivate) redirect("%s/%s/settings/options".format(owner, repository)) }) diff --git a/src/main/scala/app/UsersController.scala b/src/main/scala/app/UsersController.scala index 92aceeb..a690304 100644 --- a/src/main/scala/app/UsersController.scala +++ b/src/main/scala/app/UsersController.scala @@ -10,21 +10,21 @@ trait UsersControllerBase extends ControllerBase { self: AccountService with AdminOnlyAuthenticator => // TODO ユーザ名の先頭に_は使えないようにする&利用可能文字チェック - case class UserForm(userName: String, password: String, mailAddress: String, userType: Int, url: Option[String]) + case class UserForm(userName: String, password: String, mailAddress: String, isAdmin: Boolean, url: Option[String]) val newForm = mapping( - "userName" -> trim(label("Username" , text(required, maxlength(100), unique))), + "userName" -> trim(label("Username" , text(required, maxlength(100), unique))), "password" -> trim(label("Password" , text(required, maxlength(100)))), "mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100)))), - "userType" -> trim(label("User Type" , number())), + "isAdmin" -> trim(label("User Type" , boolean())), "url" -> trim(label("URL" , optional(text(maxlength(200))))) )(UserForm.apply) val editForm = mapping( - "userName" -> trim(label("Username" , text())), + "userName" -> trim(label("Username" , text())), "password" -> trim(label("Password" , text(required, maxlength(100)))), "mailAddress" -> trim(label("Mail Address" , text(required, maxlength(100)))), - "userType" -> trim(label("User Type" , number())), + "isAdmin" -> trim(label("User Type" , boolean())), "url" -> trim(label("URL" , optional(text(maxlength(200))))) )(UserForm.apply) @@ -41,8 +41,8 @@ createAccount(Account( userName = form.userName, password = form.password, - mailAddress = form.mailAddress, - userType = form.userType, + mailAddress = form.mailAddress, + isAdmin = form.isAdmin, url = form.url, registeredDate = currentDate, updatedDate = currentDate, @@ -60,11 +60,11 @@ val userName = params("userName") val currentDate = new java.sql.Date(System.currentTimeMillis) updateAccount(getAccountByUserName(userName).get.copy( - password = form.password, - mailAddress = form.mailAddress, - userType = form.userType, - url = form.url, - updatedDate = currentDate)) + password = form.password, + mailAddress = form.mailAddress, + isAdmin = form.isAdmin, + url = form.url, + updatedDate = currentDate)) redirect("/admin/users") }) diff --git a/src/main/scala/app/WikiController.scala b/src/main/scala/app/WikiController.scala index 4ad9007..ee0d0ba 100644 --- a/src/main/scala/app/WikiController.scala +++ b/src/main/scala/app/WikiController.scala @@ -193,7 +193,7 @@ def isWritable(owner: String, repository: String): Boolean = { context.loginAccount match { - case Some(a) if(a.userType == AccountService.Administrator) => true + case Some(a) if(a.isAdmin) => true case Some(a) if(a.userName == owner) => true case Some(a) if(getCollaborators(owner, repository).contains(a.userName)) => true case _ => false diff --git a/src/main/scala/model/Account.scala b/src/main/scala/model/Account.scala index a9643d6..5a88b52 100644 --- a/src/main/scala/model/Account.scala +++ b/src/main/scala/model/Account.scala @@ -6,12 +6,12 @@ def userName = column[String]("USER_NAME", O PrimaryKey) def mailAddress = column[String]("MAIL_ADDRESS") def password = column[String]("PASSWORD") - def userType = column[Int]("USER_TYPE") + def isAdmin = column[Boolean]("ADMINISTRATOR") def url = column[String]("URL") def registeredDate = column[java.sql.Date]("REGISTERED_DATE") // TODO convert java.util.Date later def updatedDate = column[java.sql.Date]("UPDATED_DATE") def lastLoginDate = column[java.sql.Date]("LAST_LOGIN_DATE") - def * = userName ~ mailAddress ~ password ~ userType ~ url.? ~ registeredDate ~ updatedDate ~ lastLoginDate.? <> (Account, Account.unapply _) + def * = userName ~ mailAddress ~ password ~ isAdmin ~ url.? ~ registeredDate ~ updatedDate ~ lastLoginDate.? <> (Account, Account.unapply _) // def ins = userName ~ mailAddress ~ password ~ userType ~ url.? ~ registeredDate ~ updatedDate ~ lastLoginDate.? <> ({ t => Account(None, t._1, t._2, t._3, t._4, t._5, t._6, t._7, t._8)}, { (o: Account) => Some((o.userName, o.mailAddress, o.password, o.userType, o.url, o.registeredDate, o.updatedDate, o.lastLoginDate))}) } @@ -19,7 +19,7 @@ userName: String, mailAddress: String, password: String, - userType: Int, + isAdmin: Boolean, url: Option[String], registeredDate: java.sql.Date, updatedDate: java.sql.Date, @@ -29,8 +29,7 @@ class AccountDao { import Database.threadLocalSession -// def insert(o: Account): Account = Accounts.ins returning Accounts.* insert o - def insert(o: Account): Long = Accounts.* insert o + def insert(o: Account): Long = Accounts insert o def select(key: String): Option[Account] = Query(Accounts) filter(_.userName is key.bind) firstOption diff --git a/src/main/scala/model/Repository.scala b/src/main/scala/model/Repository.scala index 0b3a1a9..4280b1e 100644 --- a/src/main/scala/model/Repository.scala +++ b/src/main/scala/model/Repository.scala @@ -5,20 +5,20 @@ object Repositories extends Table[Repository]("REPOSITORY") { def repositoryName= column[String]("REPOSITORY_NAME", O PrimaryKey) def userName = column[String]("USER_NAME", O PrimaryKey) - def repositoryType = column[Int]("REPOSITORY_TYPE") // TODO should be sealed? + def isPrivate = column[Boolean]("PRIVATE") def description = column[String]("DESCRIPTION") def defaultBranch = column[String]("DEFAULT_BRANCH") def registeredDate = column[java.sql.Date]("REGISTERED_DATE") // TODO convert java.util.Date later def updatedDate = column[java.sql.Date]("UPDATED_DATE") def lastActivityDate = column[java.sql.Date]("LAST_ACTIVITY_DATE") - def * = repositoryName ~ userName ~ repositoryType ~ description.? ~ defaultBranch ~ registeredDate ~ updatedDate ~ lastActivityDate <> (Repository, Repository.unapply _) + def * = repositoryName ~ userName ~ isPrivate ~ description.? ~ defaultBranch ~ registeredDate ~ updatedDate ~ lastActivityDate <> (Repository, Repository.unapply _) // def ins = repositoryName ~ userName ~ repositoryType ~ description.? ~ defaultBranch ~ registeredDate ~ updatedDate ~ lastActivityDate <> ({ t => Project(None, t._1, t._2, t._3, t._4, t._5, t._6, t._7, t._8)}, { (o: Project) => Some((o.projectName, o.userId, o.projectType, o.description, o.defaultBranch, o.registeredDate, o.updatedDate, o.lastActivityDate))}) } case class Repository( repositoryName: String, userName: String, - repositoryType: Int, + isPrivate: Boolean, description: Option[String], defaultBranch: String, registeredDate: java.sql.Date, diff --git a/src/main/scala/service/AccountService.scala b/src/main/scala/service/AccountService.scala index af152cf..4834e44 100644 --- a/src/main/scala/service/AccountService.scala +++ b/src/main/scala/service/AccountService.scala @@ -16,11 +16,11 @@ def updateAccount(account: Account): Unit = Query(Accounts) .filter { a => a.userName is account.userName.bind } - .map { a => a.password ~ a.mailAddress ~ a.userType ~ a.url.? ~ a.registeredDate ~ a.updatedDate ~ a.lastLoginDate.? } + .map { a => a.password ~ a.mailAddress ~ a.isAdmin ~ a.url.? ~ a.registeredDate ~ a.updatedDate ~ a.lastLoginDate.? } .update ( account.password, account.mailAddress, - account.userType, + account.isAdmin, account.url, account.registeredDate, account.updatedDate, @@ -31,10 +31,3 @@ .update(new java.sql.Date(System.currentTimeMillis)) } - -object AccountService { - - val Normal = 0 - val Administrator = 1 - -} \ No newline at end of file diff --git a/src/main/scala/service/RepositoryService.scala b/src/main/scala/service/RepositoryService.scala index f05c310..965f183 100644 --- a/src/main/scala/service/RepositoryService.scala +++ b/src/main/scala/service/RepositoryService.scala @@ -34,7 +34,7 @@ Repository( repositoryName = repositoryName, userName = userName, - repositoryType = Public, + isPrivate = false, description = description, defaultBranch = "master", registeredDate = currentDate, @@ -112,14 +112,14 @@ def getAccessibleRepositories(account: Option[Account], baseUrl: String): List[RepositoryInfo] = { account match { // for Administrators - case Some(x) if(x.userType == AccountService.Administrator) => { + case Some(x) if(x.isAdmin) => { (Query(Repositories) sortBy(_.lastActivityDate desc) list) map { repository => val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl) RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags) } } // for Normal Users - case Some(x) if(x.userType == AccountService.Normal) => { + case Some(x) if(!x.isAdmin) => { // TODO only repositories registered as collaborator (Query(Repositories) sortBy(_.lastActivityDate desc) list) map { repository => val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl) @@ -128,7 +128,7 @@ } // for Guests case None => { - (Query(Repositories) filter(_.repositoryType is Public.bind) sortBy(_.lastActivityDate desc) list) map { repository => + (Query(Repositories) filter(_.isPrivate is false.bind) sortBy(_.lastActivityDate desc) list) map { repository => val repositoryInfo = JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl) RepositoryInfo(repositoryInfo.owner, repositoryInfo.name, repositoryInfo.url, repository, repositoryInfo.branchList, repositoryInfo.tags) } @@ -149,11 +149,11 @@ * Save repository options. */ def saveRepositoryOptions(userName: String, repositoryName: String, - description: Option[String], defaultBranch: String, repositoryType: Int): Unit = + description: Option[String], defaultBranch: String, isPrivate: Boolean): Unit = Query(Repositories) .filter { r => (r.userName is userName.bind) && (r.repositoryName is repositoryName.bind) } - .map { r => r.description.? ~ r.defaultBranch ~ r.repositoryType ~ r.updatedDate } - .update (description, defaultBranch, repositoryType, new java.sql.Date(System.currentTimeMillis)) + .map { r => r.description.? ~ r.defaultBranch ~ r.isPrivate ~ r.updatedDate } + .update (description, defaultBranch, isPrivate, new java.sql.Date(System.currentTimeMillis)) /** * Add collaborator to the repository. @@ -194,8 +194,6 @@ object RepositoryService { - val Public = 0 - val Private = 1 - case class RepositoryInfo(owner: String, name: String, url: String, repository: Repository, branchList: List[String], tags: List[util.JGitUtil.TagInfo]) + } \ No newline at end of file diff --git a/src/main/scala/servlet/BasicAuthenticationFilter.scala b/src/main/scala/servlet/BasicAuthenticationFilter.scala index 71bc7e4..1a0908e 100644 --- a/src/main/scala/servlet/BasicAuthenticationFilter.scala +++ b/src/main/scala/servlet/BasicAuthenticationFilter.scala @@ -27,8 +27,7 @@ getRepository(repositoryOwner, repositoryName.replaceFirst("\\.wiki", ""), "") match { case Some(repository) => { - if(!request.getRequestURI.endsWith("/git-receive-pack") && - repository.repository.repositoryType == RepositoryService.Public){ + if(!request.getRequestURI.endsWith("/git-receive-pack") && !repository.repository.isPrivate){ chain.doFilter(req, res) } else { request.getHeader("Authorization") match { @@ -56,7 +55,7 @@ private def isWritableUser(username: String, password: String, repository: RepositoryService.RepositoryInfo): Boolean = { getAccountByUserName(username) match { case Some(account) if(account.password == password) => { - (account.userType == AccountService.Administrator // administrator + (account.isAdmin // administrator || account.userName == repository.owner // repository owner || getCollaborators(repository.owner, repository.name).contains(account.userName)) // collaborator } diff --git a/src/main/scala/util/Authenticator.scala b/src/main/scala/util/Authenticator.scala index 93aae60..7513864 100644 --- a/src/main/scala/util/Authenticator.scala +++ b/src/main/scala/util/Authenticator.scala @@ -14,7 +14,7 @@ private def authenticate(action: => Any) = { { context.loginAccount match { - case Some(x) if(x.userType == AccountService.Administrator) => action + case Some(x) if(x.isAdmin) => action case Some(x) if(request.getRequestURI.split("/")(1) == x.userName) => action case _ => Unauthorized() } @@ -50,7 +50,7 @@ private def authenticate(action: => Any) = { { context.loginAccount match { - case Some(x) if(x.userType == AccountService.Administrator) => action + case Some(x) if(x.isAdmin) => action case _ => Unauthorized() } } @@ -67,7 +67,7 @@ private def authenticate(action: => Any) = { val paths = request.getRequestURI.split("/") context.loginAccount match { - case Some(x) if(x.userType == AccountService.Administrator) => action + case Some(x) if(x.isAdmin) => action case Some(x) if(paths(1) == x.userName) => action case Some(x) if(getCollaborators(paths(1), paths(2)).contains(x.userName)) => action case _ => Unauthorized() @@ -88,11 +88,11 @@ getRepository(paths(1), paths(2), baseUrl) match { case None => NotFound() case Some(repository) => - if(repository.repository.repositoryType == RepositoryService.Public){ + if(!repository.repository.isPrivate){ action } else { context.loginAccount match { - case Some(x) if(x.userType == AccountService.Administrator) => action + case Some(x) if(x.isAdmin) => action case Some(x) if(paths(1) == x.userName) => action case Some(x) if(getCollaborators(paths(1), paths(2)).contains(x.userName)) => action case _ => Unauthorized() diff --git a/src/main/twirl/account/userinfo.scala.html b/src/main/twirl/account/userinfo.scala.html index af69d4a..62b9e8b 100644 --- a/src/main/twirl/account/userinfo.scala.html +++ b/src/main/twirl/account/userinfo.scala.html @@ -1,6 +1,5 @@ @(account: model.Account, repositories: List[service.RepositoryService.RepositoryInfo])(implicit context: app.Context) @import context._ -@import service.RepositoryService._ @html.main(account.userName){