Skip to content

Commit c337ff0

Browse files
KN4CK3Rlafriks
andauthored
Add user blocking (#29028)
Fixes #17453 This PR adds the abbility to block a user from a personal account or organization to restrict how the blocked user can interact with the blocker. The docs explain what's the consequence of blocking a user. Screenshots: ![grafik](https://github.com/go-gitea/gitea/assets/1666336/4ed884f3-e06a-4862-afd3-3b8aa2488dc6) ![grafik](https://github.com/go-gitea/gitea/assets/1666336/ae6d4981-f252-4f50-a429-04f0f9f1cdf1) ![grafik](https://github.com/go-gitea/gitea/assets/1666336/ca153599-5b0f-4b4a-90fe-18bdfd6f0b6b) --------- Co-authored-by: Lauris BH <[email protected]>
1 parent 8e12ba3 commit c337ff0

File tree

109 files changed

+2873
-543
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+2873
-543
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
date: "2024-01-31T00:00:00+00:00"
3+
title: "Blocking a user"
4+
slug: "blocking-user"
5+
sidebar_position: 25
6+
toc: false
7+
draft: false
8+
aliases:
9+
- /en-us/webhooks
10+
menu:
11+
sidebar:
12+
parent: "usage"
13+
name: "Blocking a user"
14+
sidebar_position: 30
15+
identifier: "blocking-user"
16+
---
17+
18+
# Blocking a user
19+
20+
Gitea supports blocking of users to restrict how they can interact with you and your content.
21+
22+
You can block a user in your account settings, from the user's profile or from comments created by the user.
23+
The user is not directly notified about the block, but they can notice they are blocked when they attempt to interact with you.
24+
Organization owners can block anyone who is not a member of the organization too.
25+
If a blocked user has admin permissions, they can still perform all actions even if blocked.
26+
27+
### When you block a user
28+
29+
- the user stops following you
30+
- you stop following the user
31+
- the user's stars are removed from your repositories
32+
- your stars are removed from their repositories
33+
- the user stops watching your repositories
34+
- you stop watching their repositories
35+
- the user's issue assignments are removed from your repositories
36+
- your issue assignments are removed from their repositories
37+
- the user is removed as a collaborator on your repositories
38+
- you are removed as a collaborator on their repositories
39+
- any pending repository transfers to or from the blocked user are canceled
40+
41+
### When you block a user, the user cannot
42+
43+
- follow you
44+
- watch your repositories
45+
- star your repositories
46+
- fork your repositories
47+
- transfer repositories to you
48+
- open issues or pull requests on your repositories
49+
- comment on issues or pull requests you've created
50+
- comment on issues or pull requests on your repositories
51+
- react to your comments on issues or pull requests
52+
- react to comments on issues or pull requests on your repositories
53+
- assign you to issues or pull requests
54+
- add you as a collaborator on their repositories
55+
- send you notifications by @mentioning your username
56+
- be added as team member (if blocked by an organization)

models/fixtures/access.yml

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,120 +42,132 @@
4242

4343
-
4444
id: 8
45-
user_id: 15
45+
user_id: 10
4646
repo_id: 21
4747
mode: 2
4848

4949
-
5050
id: 9
51+
user_id: 10
52+
repo_id: 32
53+
mode: 2
54+
55+
-
56+
id: 10
57+
user_id: 15
58+
repo_id: 21
59+
mode: 2
60+
61+
-
62+
id: 11
5163
user_id: 15
5264
repo_id: 22
5365
mode: 2
5466

5567
-
56-
id: 10
68+
id: 12
5769
user_id: 15
5870
repo_id: 23
5971
mode: 4
6072

6173
-
62-
id: 11
74+
id: 13
6375
user_id: 15
6476
repo_id: 24
6577
mode: 4
6678

6779
-
68-
id: 12
80+
id: 14
6981
user_id: 15
7082
repo_id: 32
7183
mode: 2
7284

7385
-
74-
id: 13
86+
id: 15
7587
user_id: 18
7688
repo_id: 21
7789
mode: 2
7890

7991
-
80-
id: 14
92+
id: 16
8193
user_id: 18
8294
repo_id: 22
8395
mode: 2
8496

8597
-
86-
id: 15
98+
id: 17
8799
user_id: 18
88100
repo_id: 23
89101
mode: 4
90102

91103
-
92-
id: 16
104+
id: 18
93105
user_id: 18
94106
repo_id: 24
95107
mode: 4
96108

97109
-
98-
id: 17
110+
id: 19
99111
user_id: 20
100112
repo_id: 24
101113
mode: 1
102114

103115
-
104-
id: 18
116+
id: 20
105117
user_id: 20
106118
repo_id: 27
107119
mode: 4
108120

109121
-
110-
id: 19
122+
id: 21
111123
user_id: 20
112124
repo_id: 28
113125
mode: 4
114126

115127
-
116-
id: 20
128+
id: 22
117129
user_id: 29
118130
repo_id: 4
119131
mode: 2
120132

121133
-
122-
id: 21
134+
id: 23
123135
user_id: 29
124136
repo_id: 24
125137
mode: 1
126138

127139
-
128-
id: 22
140+
id: 24
129141
user_id: 31
130142
repo_id: 27
131143
mode: 4
132144

133145
-
134-
id: 23
146+
id: 25
135147
user_id: 31
136148
repo_id: 28
137149
mode: 4
138150

139151
-
140-
id: 24
152+
id: 26
141153
user_id: 38
142154
repo_id: 60
143155
mode: 2
144156

145157
-
146-
id: 25
158+
id: 27
147159
user_id: 38
148160
repo_id: 61
149161
mode: 1
150162

151163
-
152-
id: 26
164+
id: 28
153165
user_id: 39
154166
repo_id: 61
155167
mode: 1
156168

157169
-
158-
id: 27
170+
id: 29
159171
user_id: 40
160172
repo_id: 61
161173
mode: 4

models/fixtures/collaboration.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,15 @@
5151
repo_id: 60
5252
user_id: 38
5353
mode: 2 # write
54+
55+
-
56+
id: 10
57+
repo_id: 21
58+
user_id: 10
59+
mode: 2 # write
60+
61+
-
62+
id: 11
63+
repo_id: 32
64+
user_id: 10
65+
mode: 2 # write

models/fixtures/issue_assignees.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
id: 4
1515
assignee_id: 2
1616
issue_id: 17
17+
-
18+
id: 5
19+
assignee_id: 10
20+
issue_id: 6

models/fixtures/repo_transfer.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,19 @@
55
repo_id: 3
66
created_unix: 1553610671
77
updated_unix: 1553610671
8+
9+
-
10+
id: 2
11+
doer_id: 16
12+
recipient_id: 10
13+
repo_id: 21
14+
created_unix: 1553610671
15+
updated_unix: 1553610671
16+
17+
-
18+
id: 3
19+
doer_id: 3
20+
recipient_id: 10
21+
repo_id: 32
22+
created_unix: 1553610671
23+
updated_unix: 1553610671

models/fixtures/repository.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,8 @@
614614
owner_name: user16
615615
lower_name: big_test_public_3
616616
name: big_test_public_3
617-
num_watches: 0
618-
num_stars: 0
617+
num_watches: 1
618+
num_stars: 1
619619
num_forks: 0
620620
num_issues: 0
621621
num_closed_issues: 0
@@ -945,8 +945,8 @@
945945
owner_name: org3
946946
lower_name: repo21
947947
name: repo21
948-
num_watches: 0
949-
num_stars: 0
948+
num_watches: 1
949+
num_stars: 1
950950
num_forks: 0
951951
num_issues: 2
952952
num_closed_issues: 0

models/fixtures/star.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@
77
id: 2
88
uid: 2
99
repo_id: 4
10+
11+
-
12+
id: 3
13+
uid: 10
14+
repo_id: 21
15+
16+
-
17+
id: 4
18+
uid: 10
19+
repo_id: 32

models/fixtures/user.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@
361361
use_custom_avatar: false
362362
num_followers: 0
363363
num_following: 0
364-
num_stars: 0
364+
num_stars: 2
365365
num_repos: 3
366366
num_teams: 0
367367
num_members: 0

models/fixtures/user_blocking.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-
2+
id: 1
3+
blocker_id: 2
4+
blockee_id: 29
5+
6+
-
7+
id: 2
8+
blocker_id: 17
9+
blockee_id: 28
10+
11+
-
12+
id: 3
13+
blocker_id: 2
14+
blockee_id: 34
15+
16+
-
17+
id: 4
18+
blocker_id: 50
19+
blockee_id: 34

models/fixtures/watch.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,15 @@
2727
user_id: 11
2828
repo_id: 1
2929
mode: 3 # auto
30+
31+
-
32+
id: 6
33+
user_id: 10
34+
repo_id: 21
35+
mode: 1 # normal
36+
37+
-
38+
id: 7
39+
user_id: 10
40+
repo_id: 32
41+
mode: 1 # normal

models/issues/assignees.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,27 @@ func IsUserAssignedToIssue(ctx context.Context, issue *Issue, user *user_model.U
6464
return db.Exist[IssueAssignees](ctx, builder.Eq{"assignee_id": user.ID, "issue_id": issue.ID})
6565
}
6666

67+
type AssignedIssuesOptions struct {
68+
db.ListOptions
69+
AssigneeID int64
70+
RepoOwnerID int64
71+
}
72+
73+
func (opts *AssignedIssuesOptions) ToConds() builder.Cond {
74+
cond := builder.NewCond()
75+
if opts.AssigneeID != 0 {
76+
cond = cond.And(builder.In("issue.id", builder.Select("issue_id").From("issue_assignees").Where(builder.Eq{"assignee_id": opts.AssigneeID})))
77+
}
78+
if opts.RepoOwnerID != 0 {
79+
cond = cond.And(builder.In("issue.repo_id", builder.Select("id").From("repository").Where(builder.Eq{"owner_id": opts.RepoOwnerID})))
80+
}
81+
return cond
82+
}
83+
84+
func GetAssignedIssues(ctx context.Context, opts *AssignedIssuesOptions) ([]*Issue, int64, error) {
85+
return db.FindAndCount[Issue](ctx, opts)
86+
}
87+
6788
// ToggleIssueAssignee changes a user between assigned and not assigned for this issue, and make issue comment for it.
6889
func ToggleIssueAssignee(ctx context.Context, issue *Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *Comment, err error) {
6990
ctx, committer, err := db.TxContext(ctx)

models/issues/issue_update.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,15 @@ func FindAndUpdateIssueMentions(ctx context.Context, issue *Issue, doer *user_mo
517517
if err != nil {
518518
return nil, fmt.Errorf("UpdateIssueMentions [%d]: %w", issue.ID, err)
519519
}
520+
521+
notBlocked := make([]*user_model.User, 0, len(mentions))
522+
for _, user := range mentions {
523+
if !user_model.IsUserBlockedBy(ctx, doer, user.ID) {
524+
notBlocked = append(notBlocked, user)
525+
}
526+
}
527+
mentions = notBlocked
528+
520529
if err = UpdateIssueMentions(ctx, issue.ID, mentions); err != nil {
521530
return nil, fmt.Errorf("UpdateIssueMentions [%d]: %w", issue.ID, err)
522531
}

models/issues/issue_xref.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ func (issue *Issue) verifyReferencedIssue(stdCtx context.Context, ctx *crossRefe
214214
if !perm.CanReadIssuesOrPulls(refIssue.IsPull) {
215215
return nil, references.XRefActionNone, nil
216216
}
217+
if user_model.IsUserBlockedBy(stdCtx, ctx.Doer, refIssue.PosterID, refIssue.Repo.OwnerID) {
218+
return nil, references.XRefActionNone, nil
219+
}
220+
217221
// Accept close/reopening actions only if the poster is able to close the
218222
// referenced issue manually at this moment. The only exception is
219223
// the poster of a new PR referencing an issue on the same repo: then the merger

0 commit comments

Comments
 (0)