mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 06:25:51 +01:00
Show newsfeed of private repo to its owner
This commit is contained in:
@@ -1,85 +1,92 @@
|
|||||||
package app
|
package app
|
||||||
|
|
||||||
import util._
|
import util._
|
||||||
import service._
|
import service._
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
|
|
||||||
class IndexController extends IndexControllerBase
|
class IndexController extends IndexControllerBase
|
||||||
with RepositoryService with ActivityService with AccountService with UsersAuthenticator
|
with RepositoryService with ActivityService with AccountService with UsersAuthenticator
|
||||||
|
|
||||||
trait IndexControllerBase extends ControllerBase {
|
trait IndexControllerBase extends ControllerBase {
|
||||||
self: RepositoryService with ActivityService with AccountService with UsersAuthenticator =>
|
self: RepositoryService with ActivityService with AccountService with UsersAuthenticator =>
|
||||||
|
|
||||||
case class SignInForm(userName: String, password: String)
|
case class SignInForm(userName: String, password: String)
|
||||||
|
|
||||||
val form = mapping(
|
val form = mapping(
|
||||||
"userName" -> trim(label("Username", text(required))),
|
"userName" -> trim(label("Username", text(required))),
|
||||||
"password" -> trim(label("Password", text(required)))
|
"password" -> trim(label("Password", text(required)))
|
||||||
)(SignInForm.apply)
|
)(SignInForm.apply)
|
||||||
|
|
||||||
get("/"){
|
get("/"){
|
||||||
val loginAccount = context.loginAccount
|
val loginAccount = context.loginAccount
|
||||||
|
|
||||||
html.index(getRecentActivities(),
|
if(loginAccount.isEmpty) {
|
||||||
getVisibleRepositories(loginAccount, context.baseUrl, withoutPhysicalInfo = true),
|
html.index(getRecentActivities(),
|
||||||
loginAccount.map{ account => getUserRepositories(account.userName, context.baseUrl, withoutPhysicalInfo = true) }.getOrElse(Nil)
|
getVisibleRepositories(loginAccount, context.baseUrl, withoutPhysicalInfo = true),
|
||||||
)
|
loginAccount.map{ account => getUserRepositories(account.userName, context.baseUrl, withoutPhysicalInfo = true) }.getOrElse(Nil)
|
||||||
}
|
)
|
||||||
|
} else {
|
||||||
get("/signin"){
|
html.index(getRecentActivitiesByUser(loginAccount.get.userName),
|
||||||
val redirect = params.get("redirect")
|
getVisibleRepositories(loginAccount, context.baseUrl, withoutPhysicalInfo = true),
|
||||||
if(redirect.isDefined && redirect.get.startsWith("/")){
|
loginAccount.map{ account => getUserRepositories(account.userName, context.baseUrl, withoutPhysicalInfo = true) }.getOrElse(Nil)
|
||||||
flash += Keys.Flash.Redirect -> redirect.get
|
)
|
||||||
}
|
}
|
||||||
html.signin()
|
}
|
||||||
}
|
|
||||||
|
get("/signin"){
|
||||||
post("/signin", form){ form =>
|
val redirect = params.get("redirect")
|
||||||
authenticate(context.settings, form.userName, form.password) match {
|
if(redirect.isDefined && redirect.get.startsWith("/")){
|
||||||
case Some(account) => signin(account)
|
flash += Keys.Flash.Redirect -> redirect.get
|
||||||
case None => redirect("/signin")
|
}
|
||||||
}
|
html.signin()
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/signout"){
|
post("/signin", form){ form =>
|
||||||
session.invalidate
|
authenticate(context.settings, form.userName, form.password) match {
|
||||||
redirect("/")
|
case Some(account) => signin(account)
|
||||||
}
|
case None => redirect("/signin")
|
||||||
|
}
|
||||||
get("/activities.atom"){
|
}
|
||||||
contentType = "application/atom+xml; type=feed"
|
|
||||||
helper.xml.feed(getRecentActivities())
|
get("/signout"){
|
||||||
}
|
session.invalidate
|
||||||
|
redirect("/")
|
||||||
/**
|
}
|
||||||
* Set account information into HttpSession and redirect.
|
|
||||||
*/
|
get("/activities.atom"){
|
||||||
private def signin(account: model.Account) = {
|
contentType = "application/atom+xml; type=feed"
|
||||||
session.setAttribute(Keys.Session.LoginAccount, account)
|
helper.xml.feed(getRecentActivities())
|
||||||
updateLastLoginDate(account.userName)
|
}
|
||||||
|
|
||||||
flash.get(Keys.Flash.Redirect).asInstanceOf[Option[String]].map { redirectUrl =>
|
/**
|
||||||
if(redirectUrl.stripSuffix("/") == request.getContextPath){
|
* Set account information into HttpSession and redirect.
|
||||||
redirect("/")
|
*/
|
||||||
} else {
|
private def signin(account: model.Account) = {
|
||||||
redirect(redirectUrl)
|
session.setAttribute(Keys.Session.LoginAccount, account)
|
||||||
}
|
updateLastLoginDate(account.userName)
|
||||||
}.getOrElse {
|
|
||||||
redirect("/")
|
flash.get(Keys.Flash.Redirect).asInstanceOf[Option[String]].map { redirectUrl =>
|
||||||
}
|
if(redirectUrl.stripSuffix("/") == request.getContextPath){
|
||||||
}
|
redirect("/")
|
||||||
|
} else {
|
||||||
/**
|
redirect(redirectUrl)
|
||||||
* JSON API for collaborator completion.
|
}
|
||||||
*
|
}.getOrElse {
|
||||||
* TODO Move to other controller?
|
redirect("/")
|
||||||
*/
|
}
|
||||||
get("/_user/proposals")(usersOnly {
|
}
|
||||||
contentType = formats("json")
|
|
||||||
org.json4s.jackson.Serialization.write(
|
/**
|
||||||
Map("options" -> getAllUsers().filter(!_.isGroupAccount).map(_.userName).toArray)
|
* JSON API for collaborator completion.
|
||||||
)
|
*
|
||||||
})
|
* TODO Move to other controller?
|
||||||
|
*/
|
||||||
|
get("/_user/proposals")(usersOnly {
|
||||||
}
|
contentType = formats("json")
|
||||||
|
org.json4s.jackson.Serialization.write(
|
||||||
|
Map("options" -> getAllUsers().filter(!_.isGroupAccount).map(_.userName).toArray)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package service
|
|||||||
import model._
|
import model._
|
||||||
import scala.slick.driver.H2Driver.simple._
|
import scala.slick.driver.H2Driver.simple._
|
||||||
import Database.threadLocalSession
|
import Database.threadLocalSession
|
||||||
|
import util.JGitUtil.RepositoryInfo
|
||||||
|
|
||||||
trait ActivityService {
|
trait ActivityService {
|
||||||
|
|
||||||
@@ -24,12 +25,20 @@ trait ActivityService {
|
|||||||
def getRecentActivities(): List[Activity] =
|
def getRecentActivities(): List[Activity] =
|
||||||
Activities
|
Activities
|
||||||
.innerJoin(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName))
|
.innerJoin(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName))
|
||||||
.filter { case (t1, t2) => t2.isPrivate is false.bind }
|
.filter { case (t1, t2) => t2.isPrivate is false.bind }
|
||||||
.sortBy { case (t1, t2) => t1.activityId desc }
|
.sortBy { case (t1, t2) => t1.activityId desc }
|
||||||
.map { case (t1, t2) => t1 }
|
.map { case (t1, t2) => t1 }
|
||||||
.take(30)
|
.take(30)
|
||||||
.list
|
.list
|
||||||
|
|
||||||
|
def getRecentActivitiesByUser(loginUserName : String): List[Activity] =
|
||||||
|
Activities
|
||||||
|
.innerJoin(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName))
|
||||||
|
.filter { case (t1, t2) => (t2.isPrivate is false.bind) || (t2.userName is loginUserName.bind) }
|
||||||
|
.sortBy { case (t1, t2) => t1.activityId desc }
|
||||||
|
.map { case (t1, t2) => t1 }
|
||||||
|
.take(30)
|
||||||
|
.list
|
||||||
|
|
||||||
def recordCreateRepositoryActivity(userName: String, repositoryName: String, activityUserName: String): Unit =
|
def recordCreateRepositoryActivity(userName: String, repositoryName: String, activityUserName: String): Unit =
|
||||||
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
||||||
|
|||||||
Reference in New Issue
Block a user