(refs #1286) Fix models

This commit is contained in:
Naoki Takezoe
2016-11-01 06:51:30 +09:00
parent 60ff046823
commit ce916a7d4b
3 changed files with 14 additions and 12 deletions

View File

@@ -7,7 +7,8 @@ trait CollaboratorComponent extends TemplateComponent { self: Profile =>
class Collaborators(tag: Tag) extends Table[Collaborator](tag, "COLLABORATOR") with BasicTemplate {
val collaboratorName = column[String]("COLLABORATOR_NAME")
def * = (userName, repositoryName, collaboratorName) <> (Collaborator.tupled, Collaborator.unapply)
val permission = column[String]("PERMISSION")
def * = (userName, repositoryName, collaboratorName, permission) <> (Collaborator.tupled, Collaborator.unapply)
def byPrimaryKey(owner: String, repository: String, collaborator: String) =
byRepository(owner, repository) && (collaboratorName === collaborator.bind)
@@ -17,5 +18,6 @@ trait CollaboratorComponent extends TemplateComponent { self: Profile =>
case class Collaborator(
userName: String,
repositoryName: String,
collaboratorName: String
collaboratorName: String,
permission: String
)

View File

@@ -23,11 +23,12 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
val allowWikiEditing = column[Boolean]("ALLOW_WIKI_EDITING")
val externalWikiUrl = column[String]("EXTERNAL_WIKI_URL")
val allowFork = column[Boolean]("ALLOW_FORK")
val allowCreateIssue = column[Boolean]("ALLOW_CREATE_ISSUE")
def * = (
(userName, repositoryName, isPrivate, description.?, defaultBranch,
registeredDate, updatedDate, lastActivityDate, originUserName.?, originRepositoryName.?, parentUserName.?, parentRepositoryName.?),
(enableIssues, externalIssuesUrl.?, enableWiki, allowWikiEditing, externalWikiUrl.?, allowFork)
(enableIssues, externalIssuesUrl.?, enableWiki, allowWikiEditing, externalWikiUrl.?, allowFork, allowCreateIssue)
).shaped <> (
{ case (repository, options) =>
Repository(
@@ -90,5 +91,6 @@ case class RepositoryOptions(
enableWiki: Boolean,
allowWikiEditing: Boolean,
externalWikiUrl: Option[String],
allowFork: Boolean
allowFork: Boolean,
allowCreateIssue: Boolean
)

View File

@@ -43,7 +43,8 @@ trait RepositoryService { self: AccountService =>
enableWiki = true,
allowWikiEditing = true,
externalWikiUrl = None,
allowFork = true
allowFork = true,
allowCreateIssue = false
)
)
@@ -124,11 +125,8 @@ trait RepositoryService { self: AccountService =>
repositoryName = newRepositoryName
)) :_*)
if(account.isGroupAccount){
Collaborators.insertAll(getGroupMembers(newUserName).map(m => Collaborator(newUserName, newRepositoryName, m.userName)) :_*)
} else {
Collaborators.insertAll(collaborators.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
}
// TODO Drop transfered owner from collaborators?
Collaborators.insertAll(collaborators.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
// Update activity messages
Activities.filter { t =>
@@ -340,7 +338,7 @@ trait RepositoryService { self: AccountService =>
* Add collaborator (user or group) to the repository.
*/
def addCollaborator(userName: String, repositoryName: String, collaboratorName: String)(implicit s: Session): Unit =
Collaborators insert Collaborator(userName, repositoryName, collaboratorName)
Collaborators insert Collaborator(userName, repositoryName, collaboratorName, "ADMIN") // TODO
/**
* Remove collaborator (user or group) from the repository.
@@ -358,7 +356,7 @@ trait RepositoryService { self: AccountService =>
* Returns the list of collaborators name (user name or group name) which is sorted with ascending order.
*/
def getCollaborators(userName: String, repositoryName: String)(implicit s: Session): List[String] =
Collaborators.filter(_.byRepository(userName, repositoryName)).sortBy(_.collaboratorName).map(_.collaboratorName).list
Collaborators.filter(_.byRepository(userName, repositoryName)).sortBy(_.collaboratorName).map(_.collaboratorName).list // TODO return with permission
/**
* Returns the list of all collaborator name and permission which is sorted with ascending order.