summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorl-jonas <43265000+l-jonas@users.noreply.github.com>2020-06-05 22:01:53 +0200
committerGitHub <noreply@github.com>2020-06-05 16:01:53 -0400
commitaa3c0f8eba9b75b3d4206fbcf3fcfc23929ade2f (patch)
treed504c127ed722a93889f954da2799d11c9f148c3 /models
parentac0741801101d56b6bccd1089ffedf2b3480758b (diff)
downloadgitea-aa3c0f8eba9b75b3d4206fbcf3fcfc23929ade2f.tar.gz
gitea-aa3c0f8eba9b75b3d4206fbcf3fcfc23929ade2f.zip
Add hide activity option (#11353)
* Add hide activity option This closes https://github.com/go-gitea/gitea/issues/7927 * Adjust for linter * Adjust for linter * Add tests * Remove info that admins can view the activity * Adjust new tests for linter * Rename v139.go to v140.go * Rename v140.go to v141.go * properly indent * gofmt Co-authored-by: Jonas Lochmann <git@inkompetenz.org> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'models')
-rw-r--r--models/action.go6
-rw-r--r--models/migrations/migrations.go2
-rw-r--r--models/migrations/v141.go22
-rw-r--r--models/user.go5
-rw-r--r--models/user_heatmap.go5
5 files changed, 38 insertions, 2 deletions
diff --git a/models/action.go b/models/action.go
index fd49c6d4ed..59ccdb2d4c 100644
--- a/models/action.go
+++ b/models/action.go
@@ -319,6 +319,12 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
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})
if opts.OnlyPerformedBy {
diff --git a/models/migrations/migrations.go b/models/migrations/migrations.go
index 869661aee4..432bcffb1b 100644
--- a/models/migrations/migrations.go
+++ b/models/migrations/migrations.go
@@ -214,6 +214,8 @@ var migrations = []Migration{
NewMigration("prepend refs/heads/ to issue refs", prependRefsHeadsToIssueRefs),
// v140 -> v141
NewMigration("Save detected language file size to database instead of percent", fixLanguageStatsToSaveSize),
+ // v141 -> 142
+ NewMigration("Add KeepActivityPrivate to User table", addKeepActivityPrivateUserColumn),
}
// GetCurrentDBVersion returns the current db version
diff --git a/models/migrations/v141.go b/models/migrations/v141.go
new file mode 100644
index 0000000000..b5824ecd48
--- /dev/null
+++ b/models/migrations/v141.go
@@ -0,0 +1,22 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package migrations
+
+import (
+ "fmt"
+
+ "xorm.io/xorm"
+)
+
+func addKeepActivityPrivateUserColumn(x *xorm.Engine) error {
+ type User struct {
+ KeepActivityPrivate bool
+ }
+
+ if err := x.Sync2(new(User)); err != nil {
+ return fmt.Errorf("Sync2: %v", err)
+ }
+ return nil
+}
diff --git a/models/user.go b/models/user.go
index 8875840db7..0ecb1b9a48 100644
--- a/models/user.go
+++ b/models/user.go
@@ -163,8 +163,9 @@ type User struct {
RepoAdminChangeTeamAccess bool `xorm:"NOT NULL DEFAULT false"`
// Preferences
- DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
- Theme string `xorm:"NOT NULL DEFAULT ''"`
+ DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
+ Theme string `xorm:"NOT NULL DEFAULT ''"`
+ KeepActivityPrivate bool `xorm:"NOT NULL DEFAULT false"`
}
// SearchOrganizationsOptions options to filter organizations
diff --git a/models/user_heatmap.go b/models/user_heatmap.go
index 3d9e0683fc..ce3ec029ca 100644
--- a/models/user_heatmap.go
+++ b/models/user_heatmap.go
@@ -18,6 +18,11 @@ type UserHeatmapData struct {
// GetUserHeatmapDataByUser returns an array of UserHeatmapData
func GetUserHeatmapDataByUser(user *User) ([]*UserHeatmapData, error) {
hdata := make([]*UserHeatmapData, 0)
+
+ if user.KeepActivityPrivate {
+ return hdata, nil
+ }
+
var groupBy string
var groupByName = "timestamp" // We need this extra case because mssql doesn't allow grouping by alias
switch {