Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config options to hide issue events #17414

Merged
merged 52 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
c31588d
Add config option to hide issue events
qwerty287 Oct 23, 2021
b2ac2a5
Make configurable using a list
qwerty287 Oct 24, 2021
e499016
Add docs
qwerty287 Oct 24, 2021
d14beda
Add missing newline
qwerty287 Oct 25, 2021
3d8abdc
Merge branch 'main' into hide-issue-events
qwerty287 Oct 25, 2021
7e94f54
Merge branch 'main' into hide-issue-events
qwerty287 Oct 26, 2021
141611e
Merge branch 'main' into hide-issue-events
qwerty287 Oct 28, 2021
c3f40ae
Merge branch 'main' into hide-issue-events
qwerty287 Oct 29, 2021
d17579d
Merge branch 'main' into hide-issue-events
qwerty287 Nov 1, 2021
26270f1
Merge branch 'main' into hide-issue-events
qwerty287 Nov 12, 2021
7eabacf
Fix merge issues
qwerty287 Nov 12, 2021
20e9fc9
Merge branch 'main' into hide-issue-events
qwerty287 Nov 15, 2021
3891745
Merge branch 'main' into hide-issue-events
qwerty287 Nov 16, 2021
8fa5fe4
Merge branch 'main' into hide-issue-events
qwerty287 Nov 21, 2021
2463c85
Merge branch 'main' into hide-issue-events
qwerty287 Nov 22, 2021
2f49cab
Allow changes per user settings
qwerty287 Nov 22, 2021
f0e6e02
Fix lint
qwerty287 Nov 22, 2021
395a714
Merge branch 'main' into hide-issue-events
qwerty287 Nov 23, 2021
20b6975
Merge branch 'main' into hide-issue-events
qwerty287 Nov 26, 2021
15a5ab6
Rm old docs
qwerty287 Nov 27, 2021
02ba951
Apply suggestions from code review
qwerty287 Nov 27, 2021
9afedcf
Merge branch 'main' into hide-issue-events
qwerty287 Nov 28, 2021
3cd7818
Merge branch 'main' into hide-issue-events
qwerty287 Nov 29, 2021
afc675c
Use bitsets
qwerty287 Dec 2, 2021
d2b84b5
Rm comment
qwerty287 Dec 2, 2021
e16472b
fmt
qwerty287 Dec 2, 2021
1e09a6d
Merge branch 'main' into hide-issue-events
qwerty287 Dec 2, 2021
3a76a14
Fix lint
qwerty287 Dec 2, 2021
2b22ebe
Merge branch 'main' into hide-issue-events
qwerty287 Dec 6, 2021
33276f9
Merge branch 'main' into hide-issue-events
qwerty287 Dec 8, 2021
debb758
Merge branch 'main' into hide-issue-events
qwerty287 Dec 12, 2021
ff70bdb
Use variable/constant to provide key
qwerty287 Dec 14, 2021
ec2c9de
Merge branch 'hide-issue-events' of github.com:qwerty287/gitea into h…
qwerty287 Dec 14, 2021
9f61e51
fmt
qwerty287 Dec 14, 2021
050af8b
fix lint
qwerty287 Dec 14, 2021
d5a02bc
Merge branch 'main' into hide-issue-events
qwerty287 Dec 21, 2021
b2a77c1
Merge branch 'main' into hide-issue-events
qwerty287 Dec 24, 2021
241def9
refactor
wxiaoguang Dec 25, 2021
7a48acd
Add a prefix for user setting key
wxiaoguang Dec 25, 2021
b134912
Merge pull request #2 from wxiaoguang/hide-issue-events
qwerty287 Dec 26, 2021
5a92210
Merge branch 'main' into hide-issue-events
qwerty287 Dec 26, 2021
e05fb4b
Add license comment
wxiaoguang Dec 27, 2021
110300e
Merge branch 'main' into hide-issue-events
wxiaoguang Dec 27, 2021
a9666b1
Add license comment
wxiaoguang Dec 27, 2021
8723518
Merge branch 'main' into hide-issue-events
qwerty287 Jan 7, 2022
e2de406
Merge branch 'main' into hide-issue-events
zeripath Jan 7, 2022
e6b31ad
Update services/forms/user_form_hidden_comments.go
wxiaoguang Jan 8, 2022
b8c2785
Merge branch 'main' into hide-issue-events
zeripath Jan 8, 2022
24a927a
Merge branch 'main' into hide-issue-events
qwerty287 Jan 12, 2022
eb8caac
Merge branch 'main' into hide-issue-events
qwerty287 Jan 21, 2022
dcd7041
Merge branch 'main' into hide-issue-events
6543 Jan 21, 2022
c3933ba
check len == 0
6543 Jan 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,23 @@ continue = Continue
cancel = Cancel
language = Language
ui = Theme
shown_comments = Hidden comment types
comment_type_ref = References
comment_type_changed_labels = Changed labels
comment_type_changed_milestone = Changed milestone
comment_type_changed_assignees = Changed assignees
comment_type_changed_title = Changed title
comment_type_delete_branch = Delete branch
comment_type_changed_time = Changed time
comment_type_changed_deadline = Changed deadline
comment_type_changed_dependencies = Changed dependencies
comment_type_changed_lock_status = Changed lock status
comment_type_changed_target = Changed target branch
comment_type_review_request = Review requests
comment_type_pr_push = Added commits
comment_type_changed_project = Changed project
comment_type_changed_ref = Changed reference
saved_successfully = Your settings were saved successfully.
privacy = Privacy
keep_activity_private = Hide the activity from the profile page
keep_activity_private_popup = Makes the activity visible only for you and the admins
Expand Down
23 changes: 23 additions & 0 deletions routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"io"
"math/big"
"net/http"
"net/url"
"path"
Expand Down Expand Up @@ -1635,6 +1636,28 @@ func ViewIssue(ctx *context.Context) {
ctx.Data["HasProjectsWritePermission"] = ctx.Repo.CanWrite(unit.TypeProjects)
ctx.Data["IsRepoAdmin"] = ctx.IsSigned && (ctx.Repo.IsAdmin() || ctx.User.IsAdmin)
ctx.Data["LockReasons"] = setting.Repository.Issue.LockReasons
var hiddenEvents *big.Int
if ctx.IsSigned {
eventsRaw, err := user_model.GetSettings(ctx.User.ID, []string{"hidden_comment_types"})
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
ctx.ServerError("GetSettings", err)
return
}
if eventsRaw["hidden_comment_types"] != nil && eventsRaw["hidden_comment_types"].SettingValue != "" {
var ok bool
hiddenEvents, ok = new(big.Int).SetString(eventsRaw["hidden_comment_types"].SettingValue, 10)
if !ok {
hiddenEvents = nil
log.Error("SetString: error")
}
}
}
ctx.Data["IsEventShown"] = func(commentType models.CommentType) bool {
if hiddenEvents == nil {
return true
}
return hiddenEvents.Bit(int(commentType)) == 0
}
ctx.Data["RefEndName"] = git.RefEndName(issue.Ref)
ctx.HTML(http.StatusOK, tplIssueView)
}
Expand Down
43 changes: 43 additions & 0 deletions routers/web/user/setting/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"io"
"math/big"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -357,6 +358,28 @@ func Appearance(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsAppearance"] = true

var hiddenEvents *big.Int
eventsRaw, err := user_model.GetSettings(ctx.User.ID, []string{"hidden_comment_types"})
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
ctx.ServerError("GetSettings", err)
return
}
if eventsRaw["hidden_comment_types"] != nil && eventsRaw["hidden_comment_types"].SettingValue != "" {
var ok bool
hiddenEvents, ok = new(big.Int).SetString(eventsRaw["hidden_comment_types"].SettingValue, 10)
if !ok {
hiddenEvents = nil
log.Error("SetString: error")
}
}

ctx.Data["IsHidden"] = func(commentType int) bool {
if hiddenEvents == nil {
return false
}
return hiddenEvents.Bit(commentType) != 0
}

ctx.HTML(http.StatusOK, tplSettingsAppearance)
}

Expand Down Expand Up @@ -416,3 +439,23 @@ func UpdateUserLang(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/user/settings/appearance")

}

// UpdateUserShownComments update a user's shown comment types
func UpdateUserShownComments(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.UpdateCommentTypeForm)
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsAppearance"] = true

bitset := form.Bitset()
json := bitset.String()
err := user_model.SetSetting(&user_model.Setting{UserID: ctx.User.ID, SettingKey: "hidden_comment_types", SettingValue: string(json)})
if err != nil {
ctx.ServerError("SetSetting", err)
return
}

log.Trace("User settings updated: %s", ctx.User.Name)
ctx.Flash.Success(ctx.Tr("settings.saved_successfully"))
ctx.Redirect(setting.AppSubURL + "/user/settings/appearance")

}
1 change: 1 addition & 0 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ func RegisterRoutes(m *web.Route) {
m.Group("/appearance", func() {
m.Get("", userSetting.Appearance)
m.Post("/language", bindIgnErr(forms.UpdateLanguageForm{}), userSetting.UpdateUserLang)
m.Post("/shown_comments", bindIgnErr(forms.UpdateCommentTypeForm{}), userSetting.UpdateUserShownComments)
m.Post("/theme", bindIgnErr(forms.UpdateThemeForm{}), userSetting.UpdateUIThemePost)
})
m.Group("/security", func() {
Expand Down
112 changes: 112 additions & 0 deletions services/forms/user_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package forms

import (
"math/big"
"mime/multipart"
"net/http"
"strings"
Expand Down Expand Up @@ -267,6 +268,117 @@ func (f *UpdateLanguageForm) Validate(req *http.Request, errs binding.Errors) bi
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
}

// UpdateCommentTypeForm form for updating profile
type UpdateCommentTypeForm struct {
Reference bool
Labels bool
Milestone bool
Assignee bool
Title bool
Branch bool // delete branch
Time bool
Deadline bool
Dependencies bool
Lock bool
Target bool // target branch
Requests bool // review requests
Push bool // push to PR
Project bool
Ref bool // issue ref
}

// Validate validates the fields
func (f *UpdateCommentTypeForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
ctx := context.GetContext(req)
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
}

// IsHidden checks if the given commentType is visible
func (f *UpdateCommentTypeForm) IsHidden(commentType int) bool {
bitset := f.Bitset()
return bitset.Bit(commentType) != 0
}

// Bitset created the bitset to the update comment form
func (f *UpdateCommentTypeForm) Bitset() big.Int {
var bitset big.Int
types := []struct {
variable bool
types []int
}{
{
variable: f.Reference,
types: []int{3, 4, 5, 6},
},
{
variable: f.Labels,
types: []int{7},
},
{
variable: f.Milestone,
types: []int{8},
},
{
variable: f.Assignee,
types: []int{9},
},
{
variable: f.Title,
types: []int{10},
},
{
variable: f.Branch,
types: []int{11},
},
{
variable: f.Time,
types: []int{12, 13, 14, 15, 26},
},
{
variable: f.Deadline,
types: []int{16, 17, 18},
},
{
variable: f.Dependencies,
types: []int{19, 20},
},
{
variable: f.Lock,
types: []int{23, 24},
},
{
variable: f.Target,
types: []int{25},
},
{
variable: f.Requests,
types: []int{27},
},
{
variable: f.Push,
types: []int{29},
},
{
variable: f.Project,
types: []int{30, 31},
},
{
variable: f.Ref,
types: []int{33},
},
}
for _, v := range types {
for _, w := range v.types {
var bitSetVar uint
if v.variable {
bitSetVar = 1
}
bitset.SetBit(&bitset, w, bitSetVar)
}
}
return bitset
}

// Avatar types
const (
AvatarLocal string = "local"
Expand Down
Loading