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 user blocking #29028

Merged
merged 23 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4e7b8e1
Add user blocks.
KN4CK3R Jan 29, 2024
9cafd97
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R Jan 30, 2024
81e8bfa
Add web part.
KN4CK3R Feb 1, 2024
df59f17
Add docs.
KN4CK3R Feb 2, 2024
983ab22
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R Feb 2, 2024
b89c51a
Add more tests.
KN4CK3R Feb 2, 2024
701bdc9
Fix test.
KN4CK3R Feb 2, 2024
8c5732c
Use `show-modal`.
KN4CK3R Feb 2, 2024
e6a4e5c
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R Feb 2, 2024
b57c1f4
Update docs/content/usage/blocking-users.en-us.md
KN4CK3R Feb 3, 2024
43d2e66
Add missing migration.
KN4CK3R Feb 5, 2024
deacef9
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R Feb 5, 2024
5099747
Add suggestions.
KN4CK3R Feb 6, 2024
3d8e1b9
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R Feb 6, 2024
3af664d
Do not block actions by repository admins.
KN4CK3R Feb 8, 2024
28da385
Merge branch 'main' into feature-user-block
KN4CK3R Feb 11, 2024
211cf09
Merge branch 'feature-user-block' of https://github.com/KN4CK3R/gitea…
KN4CK3R Feb 24, 2024
576e6b4
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R Feb 24, 2024
6c9c584
Change update method.
KN4CK3R Feb 24, 2024
30f5bdd
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R Feb 28, 2024
4429f95
Merge branch 'main' of https://github.com/go-gitea/gitea into feature…
KN4CK3R Mar 2, 2024
75ea916
Merge branch 'main' into feature-user-block
GiteaBot Mar 4, 2024
eb8525b
Merge branch 'main' into feature-user-block
GiteaBot Mar 4, 2024
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
55 changes: 55 additions & 0 deletions docs/content/usage/blocking-users.en-us.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
date: "2024-01-31T00:00:00+00:00"
title: "Blocking a user"
slug: "blocking-user"
sidebar_position: 25
toc: false
draft: false
aliases:
- /en-us/webhooks
menu:
sidebar:
parent: "usage"
name: "Blocking a user"
sidebar_position: 30
identifier: "blocking-user"
---

# Blocking a user

Gitea supports blocking of users to restrict how they can interact with you and your content.

You can block a user in your account settings, from the user's profile or from comments created by the user.
The user is not directly notified about the block.
KN4CK3R marked this conversation as resolved.
Show resolved Hide resolved
Organization owners can block can block anyone who is not a member of the organization too.
KN4CK3R marked this conversation as resolved.
Show resolved Hide resolved

### When you block a user

- the user stops following you
- you stop following the user
- the user's stars are removed from your repositories
- your stars are removed from their repositories
- the user stops watching your repositories
- you stop watching their repositories
- the issue assignments are removed from your repositories
KN4CK3R marked this conversation as resolved.
Show resolved Hide resolved
- your issue assignments are removed from their repositories
- the user is removed as a collaborator on your repositories
- you are removed as a collaborator on their repositories
- any pending repository transfers to or from the blocked user are canceled

### When you block a user, the user cannot

- follow you
- watch your repositories
delvh marked this conversation as resolved.
Show resolved Hide resolved
- star your repositories
- fork your repositories
- transfer repositories to you
- open issues or pull requests on your repositories
- comment on issues or pull requests you've created
- comment on issues or pull requests on your repositories
- react to your comments on issues or pull requests
- react to comments on issues or pull requests on your repositories
- assign you to issues or pull requests
- add you as a collaborator on their repositories
- send you notifications by @mentioning your username
- be added as team member (if blocked by an organization)
42 changes: 27 additions & 15 deletions models/fixtures/access.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,96 +42,108 @@

-
id: 8
user_id: 15
user_id: 10
repo_id: 21
mode: 2

-
id: 9
user_id: 10
repo_id: 32
mode: 2

-
id: 10
user_id: 15
repo_id: 21
mode: 2

-
id: 11
user_id: 15
repo_id: 22
mode: 2

-
id: 10
id: 12
user_id: 15
repo_id: 23
mode: 4

-
id: 11
id: 13
user_id: 15
repo_id: 24
mode: 4

-
id: 12
id: 14
user_id: 15
repo_id: 32
mode: 2

-
id: 13
id: 15
user_id: 18
repo_id: 21
mode: 2

-
id: 14
id: 16
user_id: 18
repo_id: 22
mode: 2

-
id: 15
id: 17
user_id: 18
repo_id: 23
mode: 4

-
id: 16
id: 18
user_id: 18
repo_id: 24
mode: 4

-
id: 17
id: 19
user_id: 20
repo_id: 24
mode: 1

-
id: 18
id: 20
user_id: 20
repo_id: 27
mode: 4

-
id: 19
id: 21
user_id: 20
repo_id: 28
mode: 4

-
id: 20
id: 22
user_id: 29
repo_id: 4
mode: 2

-
id: 21
id: 23
user_id: 29
repo_id: 24
mode: 1

-
id: 22
id: 24
user_id: 31
repo_id: 27
mode: 4

-
id: 23
id: 25
user_id: 31
repo_id: 28
mode: 4
12 changes: 12 additions & 0 deletions models/fixtures/collaboration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,15 @@
repo_id: 22
user_id: 18
mode: 2 # write

-
id: 9
repo_id: 21
user_id: 10
mode: 2 # write

-
id: 10
repo_id: 32
user_id: 10
mode: 2 # write
4 changes: 4 additions & 0 deletions models/fixtures/issue_assignees.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@
id: 4
assignee_id: 2
issue_id: 17
-
id: 5
assignee_id: 10
issue_id: 6
16 changes: 16 additions & 0 deletions models/fixtures/repo_transfer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,19 @@
repo_id: 3
created_unix: 1553610671
updated_unix: 1553610671

-
id: 2
doer_id: 16
recipient_id: 10
repo_id: 21
created_unix: 1553610671
updated_unix: 1553610671

-
id: 3
doer_id: 3
recipient_id: 10
repo_id: 32
created_unix: 1553610671
updated_unix: 1553610671
8 changes: 4 additions & 4 deletions models/fixtures/repository.yml
Original file line number Diff line number Diff line change
Expand Up @@ -614,8 +614,8 @@
owner_name: user16
lower_name: big_test_public_3
name: big_test_public_3
num_watches: 0
num_stars: 0
num_watches: 1
num_stars: 1
num_forks: 0
num_issues: 0
num_closed_issues: 0
Expand Down Expand Up @@ -945,8 +945,8 @@
owner_name: org3
lower_name: repo21
name: repo21
num_watches: 0
num_stars: 0
num_watches: 1
num_stars: 1
num_forks: 0
num_issues: 2
num_closed_issues: 0
Expand Down
10 changes: 10 additions & 0 deletions models/fixtures/star.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,13 @@
id: 2
uid: 2
repo_id: 4

-
id: 3
uid: 10
repo_id: 21

-
id: 4
uid: 10
repo_id: 32
2 changes: 1 addition & 1 deletion models/fixtures/user.yml
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
use_custom_avatar: false
num_followers: 0
num_following: 0
num_stars: 0
num_stars: 2
num_repos: 3
num_teams: 0
num_members: 0
Expand Down
19 changes: 19 additions & 0 deletions models/fixtures/user_blocking.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-
id: 1
blocker_id: 2
blockee_id: 29

-
id: 2
blocker_id: 17
blockee_id: 28

-
id: 3
blocker_id: 2
blockee_id: 34

-
id: 4
blocker_id: 50
blockee_id: 34
12 changes: 12 additions & 0 deletions models/fixtures/watch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,15 @@
user_id: 11
repo_id: 1
mode: 3 # auto

-
id: 6
user_id: 10
repo_id: 21
mode: 1 # normal

-
id: 7
user_id: 10
repo_id: 32
mode: 1 # normal
21 changes: 21 additions & 0 deletions models/issues/assignees.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ func IsUserAssignedToIssue(ctx context.Context, issue *Issue, user *user_model.U
return db.Exist[IssueAssignees](ctx, builder.Eq{"assignee_id": user.ID, "issue_id": issue.ID})
}

type AssignedIssuesOptions struct {
db.ListOptions
AssigneeID int64
RepoOwnerID int64
}

func (opts *AssignedIssuesOptions) ToConds() builder.Cond {
cond := builder.NewCond()
if opts.AssigneeID != 0 {
cond = cond.And(builder.In("issue.id", builder.Select("issue_id").From("issue_assignees").Where(builder.Eq{"assignee_id": opts.AssigneeID})))
}
if opts.RepoOwnerID != 0 {
cond = cond.And(builder.In("issue.repo_id", builder.Select("id").From("repository").Where(builder.Eq{"owner_id": opts.RepoOwnerID})))
}
return cond
}

func GetAssignedIssues(ctx context.Context, opts *AssignedIssuesOptions) ([]*Issue, int64, error) {
return db.FindAndCount[Issue](ctx, opts)
}

// ToggleIssueAssignee changes a user between assigned and not assigned for this issue, and make issue comment for it.
func ToggleIssueAssignee(ctx context.Context, issue *Issue, doer *user_model.User, assigneeID int64) (removed bool, comment *Comment, err error) {
ctx, committer, err := db.TxContext(ctx)
Expand Down
9 changes: 9 additions & 0 deletions models/issues/issue_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,15 @@ func FindAndUpdateIssueMentions(ctx context.Context, issue *Issue, doer *user_mo
if err != nil {
return nil, fmt.Errorf("UpdateIssueMentions [%d]: %w", issue.ID, err)
}

notBlocked := make([]*user_model.User, 0, len(mentions))
for _, user := range mentions {
if !user_model.IsUserBlockedBy(ctx, doer, user.ID) {
notBlocked = append(notBlocked, user)
}
}
mentions = notBlocked

if err = UpdateIssueMentions(ctx, issue.ID, mentions); err != nil {
return nil, fmt.Errorf("UpdateIssueMentions [%d]: %w", issue.ID, err)
}
Expand Down
4 changes: 4 additions & 0 deletions models/issues/issue_xref.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ func (issue *Issue) verifyReferencedIssue(stdCtx context.Context, ctx *crossRefe
if !perm.CanReadIssuesOrPulls(refIssue.IsPull) {
return nil, references.XRefActionNone, nil
}
if user_model.IsUserBlockedBy(stdCtx, ctx.Doer, refIssue.PosterID, refIssue.Repo.OwnerID) {
return nil, references.XRefActionNone, nil
}

// Accept close/reopening actions only if the poster is able to close the
// referenced issue manually at this moment. The only exception is
// the poster of a new PR referencing an issue on the same repo: then the merger
Expand Down
19 changes: 0 additions & 19 deletions models/issues/reaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,25 +240,6 @@ func CreateReaction(ctx context.Context, opts *ReactionOptions) (*Reaction, erro
return reaction, nil
}

// CreateIssueReaction creates a reaction on issue.
func CreateIssueReaction(ctx context.Context, doerID, issueID int64, content string) (*Reaction, error) {
return CreateReaction(ctx, &ReactionOptions{
Type: content,
DoerID: doerID,
IssueID: issueID,
})
}

// CreateCommentReaction creates a reaction on comment.
func CreateCommentReaction(ctx context.Context, doerID, issueID, commentID int64, content string) (*Reaction, error) {
return CreateReaction(ctx, &ReactionOptions{
Type: content,
DoerID: doerID,
IssueID: issueID,
CommentID: commentID,
})
}

// DeleteReaction deletes reaction for issue or comment.
func DeleteReaction(ctx context.Context, opts *ReactionOptions) error {
reaction := &Reaction{
Expand Down
Loading
Loading