@ -298,15 +298,52 @@ type GetFeedsOptions struct {
// GetFeeds returns actions according to the provided options
// GetFeeds returns actions according to the provided options
func GetFeeds ( opts GetFeedsOptions ) ( [ ] * Action , error ) {
func GetFeeds ( opts GetFeedsOptions ) ( [ ] * Action , error ) {
if ! activityReadable ( opts . RequestedUser , opts . Actor ) {
return make ( [ ] * Action , 0 ) , nil
}
cond , err := activityQueryCondition ( opts )
if err != nil {
return nil , err
}
actions := make ( [ ] * Action , 0 , setting . UI . FeedPagingNum )
if err := x . Limit ( setting . UI . FeedPagingNum ) . Desc ( "id" ) . Where ( cond ) . Find ( & actions ) ; err != nil {
return nil , fmt . Errorf ( "Find: %v" , err )
}
if err := ActionList ( actions ) . LoadAttributes ( ) ; err != nil {
return nil , fmt . Errorf ( "LoadAttributes: %v" , err )
}
return actions , nil
}
func activityReadable ( user * User , doer * User ) bool {
var doerID int64
if doer != nil {
doerID = doer . ID
}
if doer == nil || ! doer . IsAdmin {
if user . KeepActivityPrivate && doerID != user . ID {
return false
}
}
return true
}
func activityQueryCondition ( opts GetFeedsOptions ) ( builder . Cond , error ) {
cond := builder . NewCond ( )
cond := builder . NewCond ( )
var repoIDs [ ] int64
var repoIDs [ ] int64
var actorID int64
var actorID int64
if opts . Actor != nil {
if opts . Actor != nil {
actorID = opts . Actor . ID
actorID = opts . Actor . ID
}
}
// check readable repositories by doer/actor
if opts . Actor == nil || ! opts . Actor . IsAdmin {
if opts . RequestedUser . IsOrganization ( ) {
if opts . RequestedUser . IsOrganization ( ) {
env , err := opts . RequestedUser . AccessibleReposEnv ( actorID )
env , err := opts . RequestedUser . AccessibleReposEnv ( actorID )
if err != nil {
if err != nil {
@ -315,16 +352,10 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
if repoIDs , err = env . RepoIDs ( 1 , opts . RequestedUser . NumRepos ) ; err != nil {
if repoIDs , err = env . RepoIDs ( 1 , opts . RequestedUser . NumRepos ) ; err != nil {
return nil , fmt . Errorf ( "GetUserRepositories: %v" , err )
return nil , fmt . Errorf ( "GetUserRepositories: %v" , err )
}
}
cond = cond . And ( builder . In ( "repo_id" , repoIDs ) )
cond = cond . And ( builder . In ( "repo_id" , repoIDs ) )
} else {
} else {
cond = cond . And ( builder . In ( "repo_id" , AccessibleRepoIDsQuery ( opts . Actor ) ) )
cond = cond . And ( builder . In ( "repo_id" , AccessibleRepoIDsQuery ( opts . Actor ) ) )
}
}
if opts . Actor == nil || ! opts . Actor . IsAdmin {
if opts . RequestedUser . KeepActivityPrivate && actorID != opts . RequestedUser . ID {
return make ( [ ] * Action , 0 ) , nil
}
}
}
cond = cond . And ( builder . Eq { "user_id" : opts . RequestedUser . ID } )
cond = cond . And ( builder . Eq { "user_id" : opts . RequestedUser . ID } )
@ -335,20 +366,9 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
if ! opts . IncludePrivate {
if ! opts . IncludePrivate {
cond = cond . And ( builder . Eq { "is_private" : false } )
cond = cond . And ( builder . Eq { "is_private" : false } )
}
}
if ! opts . IncludeDeleted {
if ! opts . IncludeDeleted {
cond = cond . And ( builder . Eq { "is_deleted" : false } )
cond = cond . And ( builder . Eq { "is_deleted" : false } )
}
}
actions := make ( [ ] * Action , 0 , setting . UI . FeedPagingNum )
return cond , nil
if err := x . Limit ( setting . UI . FeedPagingNum ) . Desc ( "id" ) . Where ( cond ) . Find ( & actions ) ; err != nil {
return nil , fmt . Errorf ( "Find: %v" , err )
}
if err := ActionList ( actions ) . LoadAttributes ( ) ; err != nil {
return nil , fmt . Errorf ( "LoadAttributes: %v" , err )
}
return actions , nil
}
}