feature: heatmap visibility options

This commit is contained in:
Tim-Niclas Oelschläger 2024-02-22 00:45:15 +01:00
parent f74c869221
commit 9cab4a716b
No known key found for this signature in database
10 changed files with 111 additions and 16 deletions

View File

@ -425,14 +425,15 @@ func (a *Action) GetIssueContent(ctx context.Context) string {
// GetFeedsOptions options for retrieving feeds
type GetFeedsOptions struct {
db.ListOptions
RequestedUser *user_model.User // the user we want activity for
RequestedTeam *organization.Team // the team we want activity for
RequestedRepo *repo_model.Repository // the repo we want activity for
Actor *user_model.User // the user viewing the activity
IncludePrivate bool // include private actions
OnlyPerformedBy bool // only actions performed by requested user
IncludeDeleted bool // include deleted actions
Date string // the day we want activity for: YYYY-MM-DD
RequestedUser *user_model.User // the user we want activity for
RequestedTeam *organization.Team // the team we want activity for
RequestedRepo *repo_model.Repository // the repo we want activity for
Actor *user_model.User // the user viewing the activity
IncludePrivate bool // include private actions
OnlyPerformedBy bool // only actions performed by requested user
IncludeDeleted bool // include deleted actions
Date string // the day we want activity for: YYYY-MM-DD
IncludePrivateRepos bool // include private repos
}
// GetFeeds returns actions according to the provided options
@ -515,7 +516,7 @@ func activityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder.
}
// check readable repositories by doer/actor
if opts.Actor == nil || !opts.Actor.IsAdmin {
if opts.Actor == nil || !opts.IncludePrivateRepos && !opts.Actor.IsAdmin {
cond = cond.And(builder.In("repo_id", repo_model.AccessibleRepoIDsQuery(opts.Actor)))
}

View File

@ -32,7 +32,7 @@ func GetUserHeatmapDataByUserTeam(ctx context.Context, user *user_model.User, te
func getUserHeatmapData(ctx context.Context, user *user_model.User, team *organization.Team, doer *user_model.User) ([]*UserHeatmapData, error) {
hdata := make([]*UserHeatmapData, 0)
if !ActivityReadable(user, doer) {
if !ActivityReadable(user, doer) || user.HeatmapVisibility.ShowNone() {
return hdata, nil
}
@ -56,7 +56,8 @@ func getUserHeatmapData(ctx context.Context, user *user_model.User, team *organi
// * Heatmaps for individual users only include actions that the user themself did.
// * For organizations actions by all users that were made in owned
// repositories are counted.
OnlyPerformedBy: !user.IsOrganization(),
OnlyPerformedBy: !user.IsOrganization(),
IncludePrivateRepos: user.HeatmapVisibility.ShowAll(),
})
if err != nil {
return nil, err

View File

@ -142,9 +142,10 @@ type User struct {
RepoAdminChangeTeamAccess bool `xorm:"NOT NULL DEFAULT false"`
// Preferences
DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
Theme string `xorm:"NOT NULL DEFAULT ''"`
KeepActivityPrivate bool `xorm:"NOT NULL DEFAULT false"`
DiffViewStyle string `xorm:"NOT NULL DEFAULT ''"`
Theme string `xorm:"NOT NULL DEFAULT ''"`
KeepActivityPrivate bool `xorm:"NOT NULL DEFAULT false"`
HeatmapVisibility structs.HeatmapVisibility `xorm:"NOT NULL DEFAULT 0"`
}
func init() {

View File

@ -0,0 +1,50 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package structs
// HeatmapVisibility defines the activities shown in heatmap
type HeatmapVisibility int
const (
// HeatmapVisibilityPublic show public activities in heatmap
HeatmapVisibilityPublic HeatmapVisibility = iota
// HeatmapVisibilityAll shows all activities in heatmap
HeatmapVisibilityAll
// HeatmapVisibilityNone show no activities in heatmap
HeatmapVisibilityNone
)
// HeatmapVisibilities is a map of HeatmapVisibility types
var HeatmapVisibilities = map[string]HeatmapVisibility{
"public": HeatmapVisibilityPublic,
"all": HeatmapVisibilityAll,
"none": HeatmapVisibilityNone,
}
// ShowPublic returns true if HeatmapVisibility is public
func (vt HeatmapVisibility) ShowPublic() bool {
return vt == HeatmapVisibilityPublic
}
// ShowAll returns true if HeatmapVisibility is all
func (vt HeatmapVisibility) ShowAll() bool {
return vt == HeatmapVisibilityAll
}
// ShowNone returns true if HeatmapVisibility is none
func (vt HeatmapVisibility) ShowNone() bool {
return vt == HeatmapVisibilityNone
}
// String provides the mode string of the visibility type (public, all, none)
func (vt HeatmapVisibility) String() string {
for k, v := range HeatmapVisibilities {
if vt == v {
return k
}
}
return ""
}

View File

@ -608,6 +608,7 @@ follow = Follow
unfollow = Unfollow
user_bio = Biography
disabled_public_activity = This user has disabled the public visibility of the activity.
disabled_public_heatmap = This user has disabled the public visibility of the heatmap.
email_visibility.limited = Your email address is visible to all authenticated users
email_visibility.private = Your email address is only visible to you and administrators
show_on_map = Show this place on a map
@ -679,6 +680,14 @@ saved_successfully = Your settings were saved successfully.
privacy = Privacy
keep_activity_private = Hide Activity from profile page
keep_activity_private_popup = Makes the activity visible only for you and the admins
heatmap_visibility_popup = Specify which activities are visible in heatmap
heatmap_visibility = Visible activities in heatmap
heatmap_visibility.public_popup = Only activies from repositories which can be visited from the viewer are in the heatmap
heatmap_visibility.public = Public
heatmap_visibility.all_popup = Only activies from repositories which can be visited from the viewer are in the heatmap
heatmap_visibility.all = All
heatmap_visibility.none_popup = Don't show the heatmap
heatmap_visibility.none = None
lookup_avatar_by_mail = Look Up Avatar by Email Address
federated_avatar_lookup = Federated Avatar Lookup

View File

@ -93,6 +93,7 @@ func ProfilePost(ctx *context.Context) {
Website: optional.Some(form.Website),
Location: optional.Some(form.Location),
Visibility: optional.Some(form.Visibility),
HeatmapVisibility: optional.Some(form.HeatmapVisibility),
KeepActivityPrivate: optional.Some(form.KeepActivityPrivate),
}
if err := user_service.UpdateUser(ctx, ctx.Doer, opts); err != nil {

View File

@ -224,6 +224,7 @@ type UpdateProfileForm struct {
Location string `binding:"MaxSize(50)"`
Description string `binding:"MaxSize(255)"`
Visibility structs.VisibleType
HeatmapVisibility structs.HeatmapVisibility
KeepActivityPrivate bool
}

View File

@ -27,6 +27,7 @@ type UpdateOptions struct {
MaxRepoCreation optional.Option[int]
IsRestricted optional.Option[bool]
Visibility optional.Option[structs.VisibleType]
HeatmapVisibility optional.Option[structs.HeatmapVisibility]
KeepActivityPrivate optional.Option[bool]
Language optional.Option[string]
Theme optional.Option[string]
@ -129,6 +130,11 @@ func UpdateUser(ctx context.Context, u *user_model.User, opts *UpdateOptions) er
cols = append(cols, "visibility")
}
if opts.HeatmapVisibility.Has() {
u.HeatmapVisibility = opts.HeatmapVisibility.Value()
cols = append(cols, "heatmap_visibility")
}
if opts.KeepActivityPrivate.Has() {
u.KeepActivityPrivate = opts.KeepActivityPrivate.Value()

View File

@ -15,9 +15,16 @@
<div class="ui info message">
<p>{{ctx.Locale.Tr "user.disabled_public_activity"}}</p>
</div>
{{else}}
{{if .ContextUser.HeatmapVisibility.ShowNone}}
<div class="ui info message">
<p>{{ctx.Locale.Tr "user.disabled_public_heatmap"}}</p>
</div>
{{else}}
{{template "user/heatmap" .}}
{{end}}
{{template "user/dashboard/feeds" .}}
{{end}}
{{template "user/heatmap" .}}
{{template "user/dashboard/feeds" .}}
{{else if eq .TabName "stars"}}
<div class="stars">
{{template "explore/repo_search" .}}

View File

@ -85,6 +85,24 @@
</div>
</div>
<div class="inline field">
<span class="inline field" data-tooltip-content="{{ctx.Locale.Tr "settings.heatmap_visibility_popup"}}"><label>{{ctx.Locale.Tr "settings.heatmap_visibility"}}</label></span>
<div class="ui selection type dropdown">
<input type="hidden" id="heatmap_visibility" name="heatmap_visibility" value="{{printf "%d" .SignedUser.HeatmapVisibility}}">
<div class="text">
{{if .SignedUser.HeatmapVisibility.ShowPublic}}{{ctx.Locale.Tr "settings.heatmap_visibility.public"}}{{end}}
{{if .SignedUser.HeatmapVisibility.ShowAll}}{{ctx.Locale.Tr "settings.heatmap_visibility.all"}}{{end}}
{{if .SignedUser.HeatmapVisibility.ShowNone}}{{ctx.Locale.Tr "settings.heatmap_visibility.none"}}{{end}}
</div>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
<div class="item" data-tooltip-content="{{ctx.Locale.Tr "settings.heatmap_visibility.public_popup"}}" data-value="0">{{ctx.Locale.Tr "settings.heatmap_visibility.public"}}</div>
<div class="item" data-tooltip-content="{{ctx.Locale.Tr "settings.heatmap_visibility.all_popup"}}" data-value="1">{{ctx.Locale.Tr "settings.heatmap_visibility.all"}}</div>
<div class="item" data-tooltip-content="{{ctx.Locale.Tr "settings.heatmap_visibility.none_popup"}}" data-value="2">{{ctx.Locale.Tr "settings.heatmap_visibility.none"}}</div>
</div>
</div>
</div>
<div class="divider"></div>
<div class="field">