Update flag columns to BOOLEAN.

This commit is contained in:
takezoe
2013-06-21 13:24:58 +09:00
parent 44e53e05fd
commit 65eb89475a
16 changed files with 58 additions and 76 deletions

View File

@@ -2,7 +2,7 @@ CREATE TABLE ACCOUNT(
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 ACCOUNT(
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 @@ CREATE TABLE ISSUE(
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 @@ INSERT INTO ACCOUNT (
USER_NAME,
MAIL_ADDRESS,
PASSWORD,
USER_TYPE,
ADMINISTRATOR,
URL,
REGISTERED_DATE,
UPDATED_DATE,
@@ -122,7 +123,7 @@ INSERT INTO ACCOUNT (
'root',
'root@localhost',
'root',
1,
true,
'https://github.com/takezoe/gitbucket',
SYSDATE,
SYSDATE,

View File

@@ -12,12 +12,12 @@ class SettingsController extends SettingsControllerBase
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 @@ trait SettingsControllerBase extends ControllerBase {
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))
})

View File

@@ -10,21 +10,21 @@ class UsersController extends UsersControllerBase with AccountService with Admin
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 @@ trait UsersControllerBase extends ControllerBase { self: AccountService with Adm
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 @@ trait UsersControllerBase extends ControllerBase { self: AccountService with Adm
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")
})

View File

@@ -193,7 +193,7 @@ trait WikiControllerBase extends ControllerBase {
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

View File

@@ -6,12 +6,12 @@ object Accounts extends Table[Account]("ACCOUNT") {
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 @@ case class Account(
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 @@ case class Account(
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

View File

@@ -5,20 +5,20 @@ import scala.slick.driver.H2Driver.simple._
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,

View File

@@ -16,11 +16,11 @@ trait AccountService {
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 @@ trait AccountService {
.update(new java.sql.Date(System.currentTimeMillis))
}
object AccountService {
val Normal = 0
val Administrator = 1
}

View File

@@ -34,7 +34,7 @@ trait RepositoryService { self: AccountService =>
Repository(
repositoryName = repositoryName,
userName = userName,
repositoryType = Public,
isPrivate = false,
description = description,
defaultBranch = "master",
registeredDate = currentDate,
@@ -112,14 +112,14 @@ trait RepositoryService { self: AccountService =>
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 @@ trait RepositoryService { self: AccountService =>
}
// 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 @@ trait RepositoryService { self: AccountService =>
* 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 @@ trait RepositoryService { self: AccountService =>
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])
}

View File

@@ -27,8 +27,7 @@ class BasicAuthenticationFilter extends Filter with RepositoryService with Accou
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 @@ class BasicAuthenticationFilter extends Filter with RepositoryService with Accou
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
}

View File

@@ -14,7 +14,7 @@ trait OwnerOnlyAuthenticator { self: ControllerBase =>
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 @@ trait AdminOnlyAuthenticator { self: ControllerBase =>
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 @@ trait WritableRepositoryAuthenticator { self: ControllerBase with RepositoryServ
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 @@ trait ReadableRepositoryAuthenticator { self: ControllerBase with RepositoryServ
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()

View File

@@ -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){
<div class="container-fluid">
<div class="row-fluid">
@@ -33,7 +32,7 @@
<a href="@path/@repository.owner">@repository.owner</a>
/
<a href="@path/@repository.owner/@repository.name">@repository.name</a>
@if(repository.repository.repositoryType == Private){
@if(repository.repository.isPrivate){
<i class="icon-lock"></i>
}
</div>

View File

@@ -1,6 +1,5 @@
@(account: Option[model.Account])(implicit context: app.Context)
@import context._
@import service.AccountService._
@html.main(if(account.isEmpty) "New User" else "Update User"){
<form method="POST" action="@if(account.isEmpty){@path/admin/users/_new} else {@path/admin/users/@account.get.userName/_edit}" validate="true">
<fieldset>
@@ -21,10 +20,10 @@
<fieldset>
<label><strong>User Type</strong></label>
<label for="userType_Normal">
<input type="radio" name="userType" id="userType_Normal" value="@Normal"@if(account.isEmpty || account.get.userType==Normal){ checked}/> Normal
<input type="radio" name="isAdmin" id="userType_Normal" value="false"@if(account.isEmpty || !account.get.isAdmin){ checked}/> Normal
</label>
<label for="userType_Admin">
<input type="radio" name="userType" id="userType_Admin" value="@Administrator"@if(account.isDefined && account.get.userType==Administrator){ checked}/> Administrator
<input type="radio" name="isAdmin" id="userType_Admin" value="true"@if(account.isDefined && account.get.isAdmin){ checked}/> Administrator
</label>
</fieldset>
<fieldset>

View File

@@ -1,6 +1,5 @@
@(users: List[model.Account])(implicit context: app.Context)
@import context._
@import service.AccountService._
@html.main("Manage Users"){
<div style="text-align: right; margin-bottom: 4px;">
<a href="@path/admin/users/_new" class="btn">New User</a>
@@ -20,11 +19,10 @@
<td><a href="@path/admin/users/@account.userName/_edit">@account.userName</a></td>
<td>@account.mailAddress</td>
<td>
@if(account.userType == Normal){
Normal
}
@if(account.userType == Administrator){
@if(account.isAdmin){
Administrator
} else {
Normal
}
</td>
<td>@account.url</td>

View File

@@ -1,10 +1,8 @@
@(active: String, repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context)
@import context._
@import service.AccountService._
@import service.RepositoryService._
<div class="head">
<a href="@path/@repository.owner">@repository.owner</a> / <a href="@path/@repository.owner/@repository.name">@repository.name</a>
@if(repository.repository.repositoryType == Private){
@if(repository.repository.isPrivate){
<i class="icon-lock"></i>
}
</div>
@@ -19,7 +17,7 @@
<th class="box-header@if(active=="wiki"){ active}">
<a href="@path/@repository.owner/@repository.name/wiki">Wiki</a>
</th>
@if(loginAccount.isDefined && (loginAccount.get.userType == Administrator || loginAccount.get.userName == repository.owner)){
@if(loginAccount.isDefined && (loginAccount.get.isAdmin || loginAccount.get.userName == repository.owner)){
<th class="box-header@if(active=="settings"){ active}">
<a href="@path/@repository.owner/@repository.name/settings">Settings</a>
</th>

View File

@@ -1,6 +1,5 @@
@(repositories: List[service.RepositoryService.RepositoryInfo])(implicit context: app.Context)
@import context._
@import service.RepositoryService._
@main("GitBucket"){
<h3>Recent updated repositories</h3>
@repositories.map { repository =>
@@ -9,7 +8,7 @@
<a href="@path/@repository.owner">@repository.owner</a>
/
<a href="@path/@repository.owner/@repository.name">@repository.name</a>
@if(repository.repository.repositoryType == Private){
@if(repository.repository.isPrivate){
<i class="icon-lock"></i>
}
</div>

View File

@@ -1,6 +1,5 @@
@(repository: service.RepositoryService.RepositoryInfo)(implicit context: app.Context)
@import context._
@import service.RepositoryService._
@html.main("Settings"){
@html.header("settings", repository)
@menu("options", repository){
@@ -25,11 +24,11 @@
<fieldset>
<label><strong>Repository Type</strong></label>
<label>
<input type="radio" name="repositoryType" value="@Public"@if(repository.repository.repositoryType==Public){ checked}>
<input type="radio" name="isPrivate" value="false"@if(!repository.repository.isPrivate){ checked}>
<strong>Public</strong> - All users and guests can read this repository.
</label>
<label>
<input type="radio" name="repositoryType" value="@Private"@if(repository.repository.repositoryType==Private){ checked}>
<input type="radio" name="isPrivate" value="true"@if(repository.repository.isPrivate){ checked}>
<strong>Private</strong> - Only collaborators can read this repository.
</label>
</fieldset>