Merge pull request 'feat: don't allow blocking the doer' (#6411) from gusted/forgejo-org-block-yourown into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6411
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-12-30 08:14:17 +00:00
commit a5dc315a64
3 changed files with 21 additions and 0 deletions

View file

@ -147,6 +147,20 @@ func TestBlockUserFromOrganization(t *testing.T) {
session.MakeRequest(t, req, http.StatusInternalServerError)
})
})
t.Run("Block the doer", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
req := NewRequestWithValues(t, "POST", org.OrganisationLink()+"/settings/blocked_users/block", map[string]string{
"_csrf": GetCSRF(t, session, org.OrganisationLink()+"/settings/blocked_users"),
"uname": doer.Name,
})
session.MakeRequest(t, req, http.StatusSeeOther)
assert.False(t, unittest.BeanExists(t, &user_model.BlockedUser{BlockID: doer.ID, UserID: org.ID}))
flashCookie := session.GetCookie(forgejo_context.CookieNameFlash)
assert.NotNil(t, flashCookie)
assert.EqualValues(t, "error%3DYou%2Bcannot%2Bblock%2Byourself.", flashCookie.Value)
})
}
// TestBlockActions ensures that certain actions cannot be performed as a doer