Skip to content

Commit aa3c0f8

Browse files
l-jonasJonas Lochmanntechknowlogick
authored
Add hide activity option (#11353)
* Add hide activity option This closes #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 <[email protected]> Co-authored-by: techknowlogick <[email protected]>
1 parent ac07418 commit aa3c0f8

File tree

13 files changed

+488
-16
lines changed

13 files changed

+488
-16
lines changed

integrations/privateactivity_test.go

+414
Large diffs are not rendered by default.

models/action.go

+6
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
319319
cond = cond.And(builder.In("repo_id", AccessibleRepoIDsQuery(opts.Actor)))
320320
}
321321

322+
if opts.Actor == nil || !opts.Actor.IsAdmin {
323+
if opts.RequestedUser.KeepActivityPrivate && actorID != opts.RequestedUser.ID {
324+
return make([]*Action, 0), nil
325+
}
326+
}
327+
322328
cond = cond.And(builder.Eq{"user_id": opts.RequestedUser.ID})
323329

324330
if opts.OnlyPerformedBy {

models/migrations/migrations.go

+2
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ var migrations = []Migration{
214214
NewMigration("prepend refs/heads/ to issue refs", prependRefsHeadsToIssueRefs),
215215
// v140 -> v141
216216
NewMigration("Save detected language file size to database instead of percent", fixLanguageStatsToSaveSize),
217+
// v141 -> 142
218+
NewMigration("Add KeepActivityPrivate to User table", addKeepActivityPrivateUserColumn),
217219
}
218220

219221
// GetCurrentDBVersion returns the current db version

models/migrations/v141.go

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package migrations
6+
7+
import (
8+
"fmt"
9+
10+
"xorm.io/xorm"
11+
)
12+
13+
func addKeepActivityPrivateUserColumn(x *xorm.Engine) error {
14+
type User struct {
15+
KeepActivityPrivate bool
16+
}
17+
18+
if err := x.Sync2(new(User)); err != nil {
19+
return fmt.Errorf("Sync2: %v", err)
20+
}
21+
return nil
22+
}

models/user.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ type User struct {
163163
RepoAdminChangeTeamAccess bool `xorm:"NOT NULL DEFAULT false"`
164164

165165
// Preferences
166-
DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
167-
Theme string `xorm:"NOT NULL DEFAULT ''"`
166+
DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
167+
Theme string `xorm:"NOT NULL DEFAULT ''"`
168+
KeepActivityPrivate bool `xorm:"NOT NULL DEFAULT false"`
168169
}
169170

170171
// SearchOrganizationsOptions options to filter organizations

models/user_heatmap.go

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ type UserHeatmapData struct {
1818
// GetUserHeatmapDataByUser returns an array of UserHeatmapData
1919
func GetUserHeatmapDataByUser(user *User) ([]*UserHeatmapData, error) {
2020
hdata := make([]*UserHeatmapData, 0)
21+
22+
if user.KeepActivityPrivate {
23+
return hdata, nil
24+
}
25+
2126
var groupBy string
2227
var groupByName = "timestamp" // We need this extra case because mssql doesn't allow grouping by alias
2328
switch {

modules/auth/user_form.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,15 @@ func (f *AccessTokenForm) Validate(ctx *macaron.Context, errs binding.Errors) bi
196196

197197
// UpdateProfileForm form for updating profile
198198
type UpdateProfileForm struct {
199-
Name string `binding:"AlphaDashDot;MaxSize(40)"`
200-
FullName string `binding:"MaxSize(100)"`
201-
Email string `binding:"Required;Email;MaxSize(254)"`
202-
KeepEmailPrivate bool
203-
Website string `binding:"ValidUrl;MaxSize(255)"`
204-
Location string `binding:"MaxSize(50)"`
205-
Language string `binding:"Size(5)"`
206-
Description string `binding:"MaxSize(255)"`
199+
Name string `binding:"AlphaDashDot;MaxSize(40)"`
200+
FullName string `binding:"MaxSize(100)"`
201+
Email string `binding:"Required;Email;MaxSize(254)"`
202+
KeepEmailPrivate bool
203+
Website string `binding:"ValidUrl;MaxSize(255)"`
204+
Location string `binding:"MaxSize(50)"`
205+
Language string `binding:"Size(5)"`
206+
Description string `binding:"MaxSize(255)"`
207+
KeepActivityPrivate bool
207208
}
208209

209210
// Validate validates the fields

options/locale/locale_en-US.ini

+4
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ follow = Follow
392392
unfollow = Unfollow
393393
heatmap.loading = Loading Heatmap…
394394
user_bio = Biography
395+
disabled_public_activity = This user has disabled the public visibility of the activity.
395396
396397
form.name_reserved = The username '%s' is reserved.
397398
form.name_pattern_not_allowed = The pattern '%s' is not allowed in a username.
@@ -430,6 +431,9 @@ continue = Continue
430431
cancel = Cancel
431432
language = Language
432433
ui = Theme
434+
privacy = Privacy
435+
keep_activity_private = Hide the activity from the profile page
436+
keep_activity_private_popup = Makes the activity visible only for you and the admins
433437
434438
lookup_avatar_by_mail = Look Up Avatar by Email Address
435439
federated_avatar_lookup = Federated Avatar Lookup

routers/user/home.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ func Dashboard(ctx *context.Context) {
112112
ctx.Data["PageIsDashboard"] = true
113113
ctx.Data["PageIsNews"] = true
114114
ctx.Data["SearchLimit"] = setting.UI.User.RepoPagingNum
115-
ctx.Data["EnableHeatmap"] = setting.Service.EnableUserHeatmap
115+
// no heatmap access for admins; GetUserHeatmapDataByUser ignores the calling user
116+
// so everyone would get the same empty heatmap
117+
ctx.Data["EnableHeatmap"] = setting.Service.EnableUserHeatmap && !ctxUser.KeepActivityPrivate
116118
ctx.Data["HeatmapUser"] = ctxUser.Name
117119

118120
var err error

routers/user/profile.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ func Profile(ctx *context.Context) {
9393
ctx.Data["PageIsUserProfile"] = true
9494
ctx.Data["Owner"] = ctxUser
9595
ctx.Data["OpenIDs"] = openIDs
96-
ctx.Data["EnableHeatmap"] = setting.Service.EnableUserHeatmap
96+
// no heatmap access for admins; GetUserHeatmapDataByUser ignores the calling user
97+
// so everyone would get the same empty heatmap
98+
ctx.Data["EnableHeatmap"] = setting.Service.EnableUserHeatmap && !ctxUser.KeepActivityPrivate
9799
ctx.Data["HeatmapUser"] = ctxUser.Name
98100
showPrivate := ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == ctxUser.ID)
99101

routers/user/setting/profile.go

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func ProfilePost(ctx *context.Context, form auth.UpdateProfileForm) {
9696
ctx.User.Location = form.Location
9797
ctx.User.Language = form.Language
9898
ctx.User.Description = form.Description
99+
ctx.User.KeepActivityPrivate = form.KeepActivityPrivate
99100
if err := models.UpdateUserSetting(ctx.User); err != nil {
100101
if _, ok := err.(models.ErrEmailAlreadyUsed); ok {
101102
ctx.Flash.Error(ctx.Tr("form.email_been_used"))

templates/user/profile.tmpl

+9-4
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,15 @@
104104
</div>
105105

106106
{{if eq .TabName "activity"}}
107-
{{if .EnableHeatmap}}
108-
{{template "user/dashboard/heatmap" .}}
109-
<div class="ui divider"></div>
110-
{{end}}
107+
{{if .Owner.KeepActivityPrivate}}
108+
<div class="ui info message">
109+
<p>{{.i18n.Tr "user.disabled_public_activity"}}</p>
110+
</div>
111+
{{end}}
112+
{{if .EnableHeatmap}}
113+
{{template "user/dashboard/heatmap" .}}
114+
<div class="ui divider"></div>
115+
{{end}}
111116
<div class="feeds">
112117
{{template "user/dashboard/feeds" .}}
113118
</div>

templates/user/settings/profile.tmpl

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@
5858
</div>
5959
</div>
6060

61+
<div class="field">
62+
<label for="keep-activity-private">{{.i18n.Tr "settings.privacy"}}</label>
63+
<div class="ui checkbox" id="keep-activity-private">
64+
<label class="poping up" data-content="{{.i18n.Tr "settings.keep_activity_private_popup"}}"><strong>{{.i18n.Tr "settings.keep_activity_private"}}</strong></label>
65+
<input name="keep_activity_private" type="checkbox" {{if .SignedUser.KeepActivityPrivate}}checked{{end}}>
66+
</div>
67+
</div>
6168
<div class="field">
6269
<button class="ui green button">{{$.i18n.Tr "settings.update_profile"}}</button>
6370
</div>

0 commit comments

Comments
 (0)