diff --git a/src/main/scala/gitbucket/core/controller/ApiController.scala b/src/main/scala/gitbucket/core/controller/ApiController.scala
index e3175ad..eb585fb 100644
--- a/src/main/scala/gitbucket/core/controller/ApiController.scala
+++ b/src/main/scala/gitbucket/core/controller/ApiController.scala
@@ -178,7 +178,7 @@
*/
get("/api/v3/repos/:owner/:repo/collaborators") (referrersOnly { repository =>
// TODO Should ApiUser take permission? getCollaboratorUserNames does not return owner group members.
- JsonFormat(getCollaboratorUserNames(params("owner"), params("repo")).map(u => ApiUser(getAccountByUserName(u._1).get)))
+ JsonFormat(getCollaboratorUserNames(params("owner"), params("repo")).map(u => ApiUser(getAccountByUserName(u).get)))
})
/**
diff --git a/src/main/scala/gitbucket/core/controller/IssuesController.scala b/src/main/scala/gitbucket/core/controller/IssuesController.scala
index d97e31e..6fbe8e6 100644
--- a/src/main/scala/gitbucket/core/controller/IssuesController.scala
+++ b/src/main/scala/gitbucket/core/controller/IssuesController.scala
@@ -380,9 +380,4 @@
}
}
- // TODO Move to IssuesService?
- private def getAssignableUserNames(owner: String, repository: String): List[String] =
- (getCollaboratorUserNames(owner, repository, Seq("ADMIN", "WRITE")).map(_._1) :::
- (if(getAccountByUserName(owner).get.isGroupAccount) getGroupMembers(owner).map(_.userName) else List(owner))).sorted
-
}
diff --git a/src/main/scala/gitbucket/core/controller/PullRequestsController.scala b/src/main/scala/gitbucket/core/controller/PullRequestsController.scala
index 6d8fd7c..4a97ae0 100644
--- a/src/main/scala/gitbucket/core/controller/PullRequestsController.scala
+++ b/src/main/scala/gitbucket/core/controller/PullRequestsController.scala
@@ -533,9 +533,4 @@
hasWritePermission(owner, repoName, context.loginAccount))
}
- // TODO Move to IssuesService?
- private def getAssignableUserNames(owner: String, repository: String): List[String] =
- (getCollaboratorUserNames(owner, repository, Seq("ADMIN", "WRITE")).map(_._1) :::
- (if(getAccountByUserName(owner).get.isGroupAccount) getGroupMembers(owner).map(_.userName) else List(owner))).sorted
-
}
diff --git a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala
index 31ebeb9..ff16113 100644
--- a/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala
+++ b/src/main/scala/gitbucket/core/controller/RepositorySettingsController.scala
@@ -188,25 +188,6 @@
redirect(s"/${repository.owner}/${repository.name}/settings/collaborators")
})
-
-// /**
-// * Add the collaborator.
-// */
-// post("/:owner/:repository/settings/collaborators/add", collaboratorForm)(ownerOnly { (form, repository) =>
-// getAccountByUserName(repository.owner).foreach { _ =>
-// addCollaborator(repository.owner, repository.name, form.userName, "ADMIN") // TODO
-// }
-// redirect(s"/${repository.owner}/${repository.name}/settings/collaborators")
-// })
-//
-// /**
-// * Add the collaborator.
-// */
-// get("/:owner/:repository/settings/collaborators/remove")(ownerOnly { repository =>
-// removeCollaborator(repository.owner, repository.name, params("name"))
-// redirect(s"/${repository.owner}/${repository.name}/settings/collaborators")
-// })
-
/**
* Display the web hook page.
*/
diff --git a/src/main/scala/gitbucket/core/model/Collaborator.scala b/src/main/scala/gitbucket/core/model/Collaborator.scala
index f25e4b2..5036e3a 100644
--- a/src/main/scala/gitbucket/core/model/Collaborator.scala
+++ b/src/main/scala/gitbucket/core/model/Collaborator.scala
@@ -21,3 +21,20 @@
collaboratorName: String,
permission: String
)
+
+sealed abstract class Permission(val name: String)
+
+object Permission {
+ object ADMIN extends Permission("ADMIN")
+ object WRITE extends Permission("WRITE")
+ object READ extends Permission("READ")
+
+// val values: Vector[Permission] = Vector(ADMIN, WRITE, READ)
+//
+// private val map: Map[String, Permission] = values.map(enum => enum.name -> enum).toMap
+//
+// def apply(name: String): Permission = map(name)
+//
+// def valueOf(name: String): Option[Permission] = map.get(name)
+
+}
\ No newline at end of file
diff --git a/src/main/scala/gitbucket/core/service/IssuesService.scala b/src/main/scala/gitbucket/core/service/IssuesService.scala
index b9566a0..ecbfa55 100644
--- a/src/main/scala/gitbucket/core/service/IssuesService.scala
+++ b/src/main/scala/gitbucket/core/service/IssuesService.scala
@@ -14,7 +14,7 @@
trait IssuesService {
- self: AccountService =>
+ self: AccountService with RepositoryService =>
import IssuesService._
def getIssue(owner: String, repository: String, issueId: String)(implicit s: Session) =
@@ -433,6 +433,11 @@
}
}
+ def getAssignableUserNames(owner: String, repository: String)(implicit s: Session): List[String] = {
+ (getCollaboratorUserNames(owner, repository, Seq(Permission.ADMIN, Permission.WRITE)) :::
+ (if (getAccountByUserName(owner).get.isGroupAccount) getGroupMembers(owner).map(_.userName) else List(owner))).sorted
+ }
+
}
object IssuesService {
diff --git a/src/main/scala/gitbucket/core/service/RepositoryService.scala b/src/main/scala/gitbucket/core/service/RepositoryService.scala
index 41580b6..d340a82 100644
--- a/src/main/scala/gitbucket/core/service/RepositoryService.scala
+++ b/src/main/scala/gitbucket/core/service/RepositoryService.scala
@@ -1,7 +1,7 @@
package gitbucket.core.service
import gitbucket.core.controller.Context
-import gitbucket.core.model.{Collaborator, Repository, RepositoryOptions, Account}
+import gitbucket.core.model.{Collaborator, Repository, RepositoryOptions, Account, Permission}
import gitbucket.core.model.Profile._
import gitbucket.core.util.JGitUtil
import profile.simple._
@@ -340,12 +340,6 @@
def addCollaborator(userName: String, repositoryName: String, collaboratorName: String, permission: String)(implicit s: Session): Unit =
Collaborators insert Collaborator(userName, repositoryName, collaboratorName, permission)
-// /**
-// * Remove collaborator (user or group) from the repository.
-// */
-// def removeCollaborator(userName: String, repositoryName: String, collaboratorName: String)(implicit s: Session): Unit =
-// Collaborators.filter(_.byPrimaryKey(userName, repositoryName, collaboratorName)).delete
-
/**
* Remove all collaborators from the repository.
*/
@@ -367,17 +361,17 @@
* Returns the list of all collaborator name and permission which is sorted with ascending order.
* If a group is added as a collaborator, this method returns users who are belong to that group.
*/
- def getCollaboratorUserNames(userName: String, repositoryName: String, filter: Seq[String] = Nil)(implicit s: Session): List[(String, String)] = {
+ def getCollaboratorUserNames(userName: String, repositoryName: String, filter: Seq[Permission] = Nil)(implicit s: Session): List[String] = {
val q1 = Collaborators.filter(_.byRepository(userName, repositoryName))
.innerJoin(Accounts).on { case (t1, t2) => (t1.collaboratorName === t2.userName) && (t2.groupAccount === false.bind) }
- .map { case (t1, t2) => (t1.collaboratorName, "ADMIN") }
+ .map { case (t1, t2) => t1.collaboratorName }
val q2 = Collaborators.filter(_.byRepository(userName, repositoryName))
.innerJoin(Accounts).on { case (t1, t2) => (t1.collaboratorName === t2.userName) && (t2.groupAccount === true.bind) }
.innerJoin(GroupMembers).on { case ((t1, t2), t3) => t2.userName === t3.groupName }
- .map { case ((t1, t2), t3) => (t3.userName, "ADMIN") }
+ .map { case ((t1, t2), t3) => t3.userName }
- q1.union(q2).list
+ q1.union(q2).list.filter { x => filter.isEmpty || filter.exists(_.name == x) }
}
@@ -386,7 +380,7 @@
case Some(a) if(a.isAdmin) => true
case Some(a) if(a.userName == owner) => true
case Some(a) if(getGroupMembers(owner).exists(_.userName == a.userName)) => true
- case Some(a) if(getCollaboratorUserNames(owner, repository).contains((a.userName, "ADMIN"))) => true // TODO ADMIN|WRITE
+ case Some(a) if(getCollaboratorUserNames(owner, repository, Seq(Permission.ADMIN, Permission.WRITE)).contains(a.userName)) => true
case _ => false
}
}
diff --git a/src/main/scala/gitbucket/core/service/RequestCache.scala b/src/main/scala/gitbucket/core/service/RequestCache.scala
index 768a3b4..bd03cd8 100644
--- a/src/main/scala/gitbucket/core/service/RequestCache.scala
+++ b/src/main/scala/gitbucket/core/service/RequestCache.scala
@@ -11,7 +11,7 @@
* It may be called many times in one request, so each method stores
* its result into the cache which available during a request.
*/
-trait RequestCache extends SystemSettingsService with AccountService with IssuesService {
+trait RequestCache extends SystemSettingsService with AccountService with IssuesService with RepositoryService {
private implicit def context2Session(implicit context: Context): Session =
request2Session(context.request)
diff --git a/src/main/scala/gitbucket/core/util/Authenticator.scala b/src/main/scala/gitbucket/core/util/Authenticator.scala
index ca1c394..57f3942 100644
--- a/src/main/scala/gitbucket/core/util/Authenticator.scala
+++ b/src/main/scala/gitbucket/core/util/Authenticator.scala
@@ -2,6 +2,7 @@
import gitbucket.core.controller.ControllerBase
import gitbucket.core.service.{AccountService, RepositoryService}
+import gitbucket.core.model.Permission
import RepositoryService.RepositoryInfo
import Implicits._
import ControlUtil._
@@ -44,7 +45,7 @@
case Some(x) if(repository.owner == x.userName) => action(repository)
// TODO Repository management is allowed for only group managers?
case Some(x) if(getGroupMembers(repository.owner).exists { m => m.userName == x.userName && m.isManager == true }) => action(repository)
- case Some(x) if(getCollaboratorUserNames(paths(0), paths(1), Seq("ADMIN")).exists(_._1 == x.userName)) => action(repository)
+ case Some(x) if(getCollaboratorUserNames(paths(0), paths(1), Seq(Permission.ADMIN)).contains(x.userName)) => action(repository)
case _ => Unauthorized()
}
} getOrElse NotFound()
@@ -102,7 +103,7 @@
case Some(x) if(x.isAdmin) => action(repository)
case Some(x) if(paths(0) == x.userName) => action(repository)
case Some(x) if(getGroupMembers(repository.owner).exists(_.userName == x.userName)) => action(repository)
- case Some(x) if(getCollaboratorUserNames(paths(0), paths(1), Seq("ADMIN", "WRITE")).exists(_._1 == x.userName)) => action(repository)
+ case Some(x) if(getCollaboratorUserNames(paths(0), paths(1), Seq(Permission.ADMIN, Permission.WRITE)).contains(x.userName)) => action(repository)
case _ => Unauthorized()
}
} getOrElse NotFound()
@@ -129,7 +130,7 @@
case Some(x) if(x.isAdmin) => action(repository)
case Some(x) if(paths(0) == x.userName) => action(repository)
case Some(x) if(getGroupMembers(repository.owner).exists(_.userName == x.userName)) => action(repository)
- case Some(x) if(getCollaboratorUserNames(paths(0), paths(1)).exists(_._1 == x.userName)) => action(repository)
+ case Some(x) if(getCollaboratorUserNames(paths(0), paths(1)).contains(x.userName)) => action(repository)
case _ => Unauthorized()
}
}
@@ -155,7 +156,7 @@
case Some(x) if(!repository.repository.isPrivate) => action(repository)
case Some(x) if(paths(0) == x.userName) => action(repository)
case Some(x) if(getGroupMembers(repository.owner).exists(_.userName == x.userName)) => action(repository)
- case Some(x) if(getCollaboratorUserNames(paths(0), paths(1)).exists(_._1 == x.userName)) => action(repository)
+ case Some(x) if(getCollaboratorUserNames(paths(0), paths(1)).contains(x.userName)) => action(repository)
case _ => Unauthorized()
}
} getOrElse NotFound()
diff --git a/src/main/scala/gitbucket/core/util/Notifier.scala b/src/main/scala/gitbucket/core/util/Notifier.scala
index de42483..24a883d 100644
--- a/src/main/scala/gitbucket/core/util/Notifier.scala
+++ b/src/main/scala/gitbucket/core/util/Notifier.scala
@@ -25,7 +25,7 @@
// group members of group repository
getGroupMembers(issue.userName).map(_.userName) :::
// collaborators
- getCollaboratorUserNames(issue.userName, issue.repositoryName).map(_._1) :::
+ getCollaboratorUserNames(issue.userName, issue.repositoryName) :::
// participants
issue.openedUserName ::
getComments(issue.userName, issue.repositoryName, issue.issueId).map(_.commentedUserName)
diff --git a/src/main/twirl/gitbucket/core/settings/collaborators.scala.html b/src/main/twirl/gitbucket/core/settings/collaborators.scala.html
index 35e53ef..f20cdc1 100644
--- a/src/main/twirl/gitbucket/core/settings/collaborators.scala.html
+++ b/src/main/twirl/gitbucket/core/settings/collaborators.scala.html
@@ -2,6 +2,7 @@
isGroupRepository: Boolean,
repository: gitbucket.core.service.RepositoryService.RepositoryInfo)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers
+@import gitbucket.core.model.Permission
@gitbucket.core.html.main("Settings", Some(repository)){
@gitbucket.core.html.menu("settings", repository){
@gitbucket.core.settings.html.menu("collaborators", repository){
@@ -51,7 +52,7 @@
'userName': userName
}, function(data, status){
if(data == 'true'){
- addCollaboratorHTML(userName, 'ADMIN'); // TODO isGroup
+ addCollaboratorHTML(userName, '@Permission.ADMIN.name'); // TODO isGroup
} else {
$('#error-collaborators').text('User does not exist.');
}
@@ -72,16 +73,16 @@
}
function addCollaboratorHTML(userName, permission, isGroup){
- var adminButton = $('');
- if(permission == 'ADMIN'){
+ var adminButton = $('');
+ if(permission == '@Permission.ADMIN.name'){
adminButton.addClass('active');
}
- var writeButton = $('');
- if(permission == 'WRITE'){
+ var writeButton = $('');
+ if(permission == '@Permission.WRITE.name'){
writeButton.addClass('active');
}
- var readButton = $('');
- if(permission == 'READ'){
+ var readButton = $('');
+ if(permission == '@Permission.READ.name'){
readButton.addClass('active');
}