mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 20:02:09 +00:00
[MODERATION] user blocking
- Add the ability to block a user via their profile page. - This will unstar their repositories and visa versa. - Blocked users cannot create issues or pull requests on your the doer's repositories (mind that this is not the case for organizations). - Blocked users cannot comment on the doer's opened issues or pull requests. - Blocked users cannot add reactions to doer's comments. - Blocked users cannot cause a notification trough mentioning the doer. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/540 (cherry picked from commit687d852480
) (cherry picked from commit0c32a4fde5
) (cherry picked from commit1791130e3c
)
This commit is contained in:
parent
70adac6d66
commit
37858b7e8f
37 changed files with 656 additions and 52 deletions
63
models/user/block_test.go
Normal file
63
models/user/block_test.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
// Copyright 2023 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package user_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIsBlocked(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
assert.True(t, user_model.IsBlocked(db.DefaultContext, 4, 1))
|
||||
|
||||
// Simple test cases to ensure the function can also respond with false.
|
||||
assert.False(t, user_model.IsBlocked(db.DefaultContext, 1, 1))
|
||||
assert.False(t, user_model.IsBlocked(db.DefaultContext, 3, 2))
|
||||
}
|
||||
|
||||
func TestIsBlockedMultiple(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
assert.True(t, user_model.IsBlockedMultiple(db.DefaultContext, []int64{4}, 1))
|
||||
assert.True(t, user_model.IsBlockedMultiple(db.DefaultContext, []int64{4, 3, 4, 5}, 1))
|
||||
|
||||
// Simple test cases to ensure the function can also respond with false.
|
||||
assert.False(t, user_model.IsBlockedMultiple(db.DefaultContext, []int64{1}, 1))
|
||||
assert.False(t, user_model.IsBlockedMultiple(db.DefaultContext, []int64{3, 4, 1}, 2))
|
||||
}
|
||||
|
||||
func TestUnblockUser(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
assert.True(t, user_model.IsBlocked(db.DefaultContext, 4, 1))
|
||||
|
||||
assert.NoError(t, user_model.UnblockUser(db.DefaultContext, 4, 1))
|
||||
|
||||
// Simple test cases to ensure the function can also respond with false.
|
||||
assert.False(t, user_model.IsBlocked(db.DefaultContext, 4, 1))
|
||||
}
|
||||
|
||||
func TestListBlockedUsers(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
blockedUsers, err := user_model.ListBlockedUsers(db.DefaultContext, 4)
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, blockedUsers, 1) {
|
||||
assert.EqualValues(t, 1, blockedUsers[0].ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListBlockedByUsersID(t *testing.T) {
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
blockedByUserIDs, err := user_model.ListBlockedByUsersID(db.DefaultContext, 1)
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, blockedByUserIDs, 1) {
|
||||
assert.EqualValues(t, 4, blockedByUserIDs[0])
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue