A fork of Gitea (see branch `mj`) adding Majority Judgment Polls 𐄷 over Issues and Merge Requests. https://git.mieuxvoter.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

397 lines
11 KiB

9 years ago
9 years ago
9 years ago
9 years ago
6 years ago
6 years ago
9 years ago
9 years ago
6 years ago
9 years ago
7 years ago
6 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
3 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
3 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
9 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
9 years ago
6 years ago
9 years ago
6 years ago
6 years ago
6 years ago
7 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
3 years ago
7 years ago
6 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
3 years ago
Restricted users (#6274) * Restricted users (#4334): initial implementation * Add User.IsRestricted & UI to edit it * Pass user object instead of user id to places where IsRestricted flag matters * Restricted users: maintain access rows for all referenced repos (incl public) * Take logged in user & IsRestricted flag into account in org/repo listings, searches and accesses * Add basic repo access tests for restricted users Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Mention restricted users in the faq Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Revert unnecessary change `.isUserPartOfOrg` -> `.IsUserPartOfOrg` Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Remove unnecessary `org.IsOrganization()` call Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Revert to an `int64` keyed `accessMap` * Add type `userAccess` * Add convenience func updateUserAccess() * Turn accessMap into a `map[int64]userAccess` Signed-off-by: Manush Dodunekov <manush@stendahls.se> * or even better: `map[int64]*userAccess` * updateUserAccess(): use tighter syntax as suggested by lafriks * even tighter * Avoid extra loop * Don't disclose limited orgs to unauthenticated users * Don't assume block only applies to orgs * Use an array of `VisibleType` for filtering * fix yet another thinko * Ok - no need for u * Revert "Ok - no need for u" This reverts commit 5c3e886aabd5acd997a3b35687d322439732c200. Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv>
3 years ago
Restricted users (#6274) * Restricted users (#4334): initial implementation * Add User.IsRestricted & UI to edit it * Pass user object instead of user id to places where IsRestricted flag matters * Restricted users: maintain access rows for all referenced repos (incl public) * Take logged in user & IsRestricted flag into account in org/repo listings, searches and accesses * Add basic repo access tests for restricted users Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Mention restricted users in the faq Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Revert unnecessary change `.isUserPartOfOrg` -> `.IsUserPartOfOrg` Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Remove unnecessary `org.IsOrganization()` call Signed-off-by: Manush Dodunekov <manush@stendahls.se> * Revert to an `int64` keyed `accessMap` * Add type `userAccess` * Add convenience func updateUserAccess() * Turn accessMap into a `map[int64]userAccess` Signed-off-by: Manush Dodunekov <manush@stendahls.se> * or even better: `map[int64]*userAccess` * updateUserAccess(): use tighter syntax as suggested by lafriks * even tighter * Avoid extra loop * Don't disclose limited orgs to unauthenticated users * Don't assume block only applies to orgs * Use an array of `VisibleType` for filtering * fix yet another thinko * Ok - no need for u * Revert "Ok - no need for u" This reverts commit 5c3e886aabd5acd997a3b35687d322439732c200. Co-authored-by: Antoine GIRARD <sapk@users.noreply.github.com> Co-authored-by: Lauris BH <lauris@nix.lv>
3 years ago
9 years ago
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2019 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package models
  6. import (
  7. "fmt"
  8. "path"
  9. "strconv"
  10. "strings"
  11. "time"
  12. "code.gitea.io/gitea/modules/base"
  13. "code.gitea.io/gitea/modules/git"
  14. "code.gitea.io/gitea/modules/log"
  15. "code.gitea.io/gitea/modules/setting"
  16. "code.gitea.io/gitea/modules/timeutil"
  17. "xorm.io/builder"
  18. )
  19. // ActionType represents the type of an action.
  20. type ActionType int
  21. // Possible action types.
  22. const (
  23. ActionCreateRepo ActionType = iota + 1 // 1
  24. ActionRenameRepo // 2
  25. ActionStarRepo // 3
  26. ActionWatchRepo // 4
  27. ActionCommitRepo // 5
  28. ActionCreateIssue // 6
  29. ActionCreatePullRequest // 7
  30. ActionTransferRepo // 8
  31. ActionPushTag // 9
  32. ActionCommentIssue // 10
  33. ActionMergePullRequest // 11
  34. ActionCloseIssue // 12
  35. ActionReopenIssue // 13
  36. ActionClosePullRequest // 14
  37. ActionReopenPullRequest // 15
  38. ActionDeleteTag // 16
  39. ActionDeleteBranch // 17
  40. ActionMirrorSyncPush // 18
  41. ActionMirrorSyncCreate // 19
  42. ActionMirrorSyncDelete // 20
  43. ActionApprovePullRequest // 21
  44. ActionRejectPullRequest // 22
  45. ActionCommentPull // 23
  46. ActionPublishRelease // 24
  47. ActionPullReviewDismissed // 25
  48. )
  49. // Action represents user operation type and other information to
  50. // repository. It implemented interface base.Actioner so that can be
  51. // used in template render.
  52. type Action struct {
  53. ID int64 `xorm:"pk autoincr"`
  54. UserID int64 `xorm:"INDEX"` // Receiver user id.
  55. OpType ActionType
  56. ActUserID int64 `xorm:"INDEX"` // Action user id.
  57. ActUser *User `xorm:"-"`
  58. RepoID int64 `xorm:"INDEX"`
  59. Repo *Repository `xorm:"-"`
  60. CommentID int64 `xorm:"INDEX"`
  61. Comment *Comment `xorm:"-"`
  62. IsDeleted bool `xorm:"INDEX NOT NULL DEFAULT false"`
  63. RefName string
  64. IsPrivate bool `xorm:"INDEX NOT NULL DEFAULT false"`
  65. Content string `xorm:"TEXT"`
  66. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  67. }
  68. // GetOpType gets the ActionType of this action.
  69. func (a *Action) GetOpType() ActionType {
  70. return a.OpType
  71. }
  72. // LoadActUser loads a.ActUser
  73. func (a *Action) LoadActUser() {
  74. if a.ActUser != nil {
  75. return
  76. }
  77. var err error
  78. a.ActUser, err = GetUserByID(a.ActUserID)
  79. if err == nil {
  80. return
  81. } else if IsErrUserNotExist(err) {
  82. a.ActUser = NewGhostUser()
  83. } else {
  84. log.Error("GetUserByID(%d): %v", a.ActUserID, err)
  85. }
  86. }
  87. func (a *Action) loadRepo() {
  88. if a.Repo != nil {
  89. return
  90. }
  91. var err error
  92. a.Repo, err = GetRepositoryByID(a.RepoID)
  93. if err != nil {
  94. log.Error("GetRepositoryByID(%d): %v", a.RepoID, err)
  95. }
  96. }
  97. // GetActFullName gets the action's user full name.
  98. func (a *Action) GetActFullName() string {
  99. a.LoadActUser()
  100. return a.ActUser.FullName
  101. }
  102. // GetActUserName gets the action's user name.
  103. func (a *Action) GetActUserName() string {
  104. a.LoadActUser()
  105. return a.ActUser.Name
  106. }
  107. // ShortActUserName gets the action's user name trimmed to max 20
  108. // chars.
  109. func (a *Action) ShortActUserName() string {
  110. return base.EllipsisString(a.GetActUserName(), 20)
  111. }
  112. // GetDisplayName gets the action's display name based on DEFAULT_SHOW_FULL_NAME, or falls back to the username if it is blank.
  113. func (a *Action) GetDisplayName() string {
  114. if setting.UI.DefaultShowFullName {
  115. trimmedFullName := strings.TrimSpace(a.GetActFullName())
  116. if len(trimmedFullName) > 0 {
  117. return trimmedFullName
  118. }
  119. }
  120. return a.ShortActUserName()
  121. }
  122. // GetDisplayNameTitle gets the action's display name used for the title (tooltip) based on DEFAULT_SHOW_FULL_NAME
  123. func (a *Action) GetDisplayNameTitle() string {
  124. if setting.UI.DefaultShowFullName {
  125. return a.ShortActUserName()
  126. }
  127. return a.GetActFullName()
  128. }
  129. // GetRepoUserName returns the name of the action repository owner.
  130. func (a *Action) GetRepoUserName() string {
  131. a.loadRepo()
  132. return a.Repo.OwnerName
  133. }
  134. // ShortRepoUserName returns the name of the action repository owner
  135. // trimmed to max 20 chars.
  136. func (a *Action) ShortRepoUserName() string {
  137. return base.EllipsisString(a.GetRepoUserName(), 20)
  138. }
  139. // GetRepoName returns the name of the action repository.
  140. func (a *Action) GetRepoName() string {
  141. a.loadRepo()
  142. return a.Repo.Name
  143. }
  144. // ShortRepoName returns the name of the action repository
  145. // trimmed to max 33 chars.
  146. func (a *Action) ShortRepoName() string {
  147. return base.EllipsisString(a.GetRepoName(), 33)
  148. }
  149. // GetRepoPath returns the virtual path to the action repository.
  150. func (a *Action) GetRepoPath() string {
  151. return path.Join(a.GetRepoUserName(), a.GetRepoName())
  152. }
  153. // ShortRepoPath returns the virtual path to the action repository
  154. // trimmed to max 20 + 1 + 33 chars.
  155. func (a *Action) ShortRepoPath() string {
  156. return path.Join(a.ShortRepoUserName(), a.ShortRepoName())
  157. }
  158. // GetRepoLink returns relative link to action repository.
  159. func (a *Action) GetRepoLink() string {
  160. if len(setting.AppSubURL) > 0 {
  161. return path.Join(setting.AppSubURL, a.GetRepoPath())
  162. }
  163. return "/" + a.GetRepoPath()
  164. }
  165. // GetRepositoryFromMatch returns a *Repository from a username and repo strings
  166. func GetRepositoryFromMatch(ownerName, repoName string) (*Repository, error) {
  167. var err error
  168. refRepo, err := GetRepositoryByOwnerAndName(ownerName, repoName)
  169. if err != nil {
  170. if IsErrRepoNotExist(err) {
  171. log.Warn("Repository referenced in commit but does not exist: %v", err)
  172. return nil, err
  173. }
  174. log.Error("GetRepositoryByOwnerAndName: %v", err)
  175. return nil, err
  176. }
  177. return refRepo, nil
  178. }
  179. // GetCommentLink returns link to action comment.
  180. func (a *Action) GetCommentLink() string {
  181. return a.getCommentLink(x)
  182. }
  183. func (a *Action) getCommentLink(e Engine) string {
  184. if a == nil {
  185. return "#"
  186. }
  187. if a.Comment == nil && a.CommentID != 0 {
  188. a.Comment, _ = getCommentByID(e, a.CommentID)
  189. }
  190. if a.Comment != nil {
  191. return a.Comment.HTMLURL()
  192. }
  193. if len(a.GetIssueInfos()) == 0 {
  194. return "#"
  195. }
  196. // Return link to issue
  197. issueIDString := a.GetIssueInfos()[0]
  198. issueID, err := strconv.ParseInt(issueIDString, 10, 64)
  199. if err != nil {
  200. return "#"
  201. }
  202. issue, err := getIssueByID(e, issueID)
  203. if err != nil {
  204. return "#"
  205. }
  206. if err = issue.loadRepo(e); err != nil {
  207. return "#"
  208. }
  209. return issue.HTMLURL()
  210. }
  211. // GetBranch returns the action's repository branch.
  212. func (a *Action) GetBranch() string {
  213. return strings.TrimPrefix(a.RefName, git.BranchPrefix)
  214. }
  215. // GetTag returns the action's repository tag.
  216. func (a *Action) GetTag() string {
  217. return strings.TrimPrefix(a.RefName, git.TagPrefix)
  218. }
  219. // GetContent returns the action's content.
  220. func (a *Action) GetContent() string {
  221. return a.Content
  222. }
  223. // GetCreate returns the action creation time.
  224. func (a *Action) GetCreate() time.Time {
  225. return a.CreatedUnix.AsTime()
  226. }
  227. // GetIssueInfos returns a list of issues associated with
  228. // the action.
  229. func (a *Action) GetIssueInfos() []string {
  230. return strings.SplitN(a.Content, "|", 3)
  231. }
  232. // GetIssueTitle returns the title of first issue associated
  233. // with the action.
  234. func (a *Action) GetIssueTitle() string {
  235. index, _ := strconv.ParseInt(a.GetIssueInfos()[0], 10, 64)
  236. issue, err := GetIssueByIndex(a.RepoID, index)
  237. if err != nil {
  238. log.Error("GetIssueByIndex: %v", err)
  239. return "500 when get issue"
  240. }
  241. return issue.Title
  242. }
  243. // GetIssueContent returns the content of first issue associated with
  244. // this action.
  245. func (a *Action) GetIssueContent() string {
  246. index, _ := strconv.ParseInt(a.GetIssueInfos()[0], 10, 64)
  247. issue, err := GetIssueByIndex(a.RepoID, index)
  248. if err != nil {
  249. log.Error("GetIssueByIndex: %v", err)
  250. return "500 when get issue"
  251. }
  252. return issue.Content
  253. }
  254. // GetFeedsOptions options for retrieving feeds
  255. type GetFeedsOptions struct {
  256. RequestedUser *User // the user we want activity for
  257. RequestedTeam *Team // the team we want activity for
  258. Actor *User // the user viewing the activity
  259. IncludePrivate bool // include private actions
  260. OnlyPerformedBy bool // only actions performed by requested user
  261. IncludeDeleted bool // include deleted actions
  262. Date string // the day we want activity for: YYYY-MM-DD
  263. }
  264. // GetFeeds returns actions according to the provided options
  265. func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
  266. if !activityReadable(opts.RequestedUser, opts.Actor) {
  267. return make([]*Action, 0), nil
  268. }
  269. cond, err := activityQueryCondition(opts)
  270. if err != nil {
  271. return nil, err
  272. }
  273. actions := make([]*Action, 0, setting.UI.FeedPagingNum)
  274. if err := x.Limit(setting.UI.FeedPagingNum).Desc("id").Where(cond).Find(&actions); err != nil {
  275. return nil, fmt.Errorf("Find: %v", err)
  276. }
  277. if err := ActionList(actions).LoadAttributes(); err != nil {
  278. return nil, fmt.Errorf("LoadAttributes: %v", err)
  279. }
  280. return actions, nil
  281. }
  282. func activityReadable(user, doer *User) bool {
  283. var doerID int64
  284. if doer != nil {
  285. doerID = doer.ID
  286. }
  287. if doer == nil || !doer.IsAdmin {
  288. if user.KeepActivityPrivate && doerID != user.ID {
  289. return false
  290. }
  291. }
  292. return true
  293. }
  294. func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) {
  295. cond := builder.NewCond()
  296. var repoIDs []int64
  297. var actorID int64
  298. if opts.Actor != nil {
  299. actorID = opts.Actor.ID
  300. }
  301. // check readable repositories by doer/actor
  302. if opts.Actor == nil || !opts.Actor.IsAdmin {
  303. if opts.RequestedUser.IsOrganization() {
  304. env, err := opts.RequestedUser.AccessibleReposEnv(actorID)
  305. if err != nil {
  306. return nil, fmt.Errorf("AccessibleReposEnv: %v", err)
  307. }
  308. if repoIDs, err = env.RepoIDs(1, opts.RequestedUser.NumRepos); err != nil {
  309. return nil, fmt.Errorf("GetUserRepositories: %v", err)
  310. }
  311. cond = cond.And(builder.In("repo_id", repoIDs))
  312. } else {
  313. cond = cond.And(builder.In("repo_id", AccessibleRepoIDsQuery(opts.Actor)))
  314. }
  315. }
  316. if opts.RequestedTeam != nil {
  317. env := opts.RequestedUser.AccessibleTeamReposEnv(opts.RequestedTeam)
  318. teamRepoIDs, err := env.RepoIDs(1, opts.RequestedUser.NumRepos)
  319. if err != nil {
  320. return nil, fmt.Errorf("GetTeamRepositories: %v", err)
  321. }
  322. cond = cond.And(builder.In("repo_id", teamRepoIDs))
  323. }
  324. cond = cond.And(builder.Eq{"user_id": opts.RequestedUser.ID})
  325. if opts.OnlyPerformedBy {
  326. cond = cond.And(builder.Eq{"act_user_id": opts.RequestedUser.ID})
  327. }
  328. if !opts.IncludePrivate {
  329. cond = cond.And(builder.Eq{"is_private": false})
  330. }
  331. if !opts.IncludeDeleted {
  332. cond = cond.And(builder.Eq{"is_deleted": false})
  333. }
  334. if opts.Date != "" {
  335. dateLow, err := time.ParseInLocation("2006-01-02", opts.Date, setting.DefaultUILocation)
  336. if err != nil {
  337. log.Warn("Unable to parse %s, filter not applied: %v", opts.Date, err)
  338. } else {
  339. dateHigh := dateLow.Add(86399000000000) // 23h59m59s
  340. cond = cond.And(builder.Gte{"created_unix": dateLow.Unix()})
  341. cond = cond.And(builder.Lte{"created_unix": dateHigh.Unix()})
  342. }
  343. }
  344. return cond, nil
  345. }