temporary blocking doesn't need to delete/hide comments #377
This commit is contained in:
@@ -316,8 +316,8 @@ func TestAdmin_Block(t *testing.T) {
|
||||
err = json.Unmarshal([]byte(res), &comments)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 2, len(comments.Comments), "should have 2 comments")
|
||||
assert.Equal(t, "", comments.Comments[0].Text)
|
||||
assert.True(t, comments.Comments[0].Deleted)
|
||||
assert.Equal(t, "", comments.Comments[0].Text, "permanent block clear comment")
|
||||
assert.True(t, comments.Comments[0].Deleted, "permanent block set deleted comment's status")
|
||||
|
||||
// unblock
|
||||
code, body = block(-1, "")
|
||||
@@ -331,14 +331,15 @@ func TestAdmin_Block(t *testing.T) {
|
||||
code, _ = block(1, "50ms")
|
||||
require.Equal(t, 200, code)
|
||||
|
||||
// get as regular user
|
||||
res, code = get(t, ts.URL+"/api/v1/find?site=radio-t&url=https://radio-t.com/blah&sort=+time")
|
||||
assert.Equal(t, 200, code)
|
||||
comments = commentsWithInfo{}
|
||||
err = json.Unmarshal([]byte(res), &comments)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 4, len(comments.Comments), "should have 4 comments")
|
||||
assert.Equal(t, "", comments.Comments[2].Text)
|
||||
assert.True(t, comments.Comments[2].Deleted)
|
||||
assert.Equal(t, "test test #1", comments.Comments[2].Text, "comment not removed and not cleared")
|
||||
assert.False(t, comments.Comments[2].Deleted, "not deleted")
|
||||
|
||||
srv.pubRest.cache = &cache.Nop{} // TODO: with lru cache it won't be refreshed and invalidated for long time
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
|
||||
@@ -729,19 +729,15 @@ func (s *DataStore) alterComments(cc []store.Comment, user store.User) (res []st
|
||||
func (s *DataStore) alterComment(c store.Comment, user store.User) (res store.Comment) {
|
||||
|
||||
blocReq := engine.FlagRequest{Flag: engine.Blocked, Locator: store.Locator{SiteID: c.Locator.SiteID}, UserID: c.User.ID}
|
||||
blocked, _ := s.Engine.Flag(blocReq)
|
||||
blocked, bErr := s.Engine.Flag(blocReq)
|
||||
|
||||
// process blocked users
|
||||
if blocked {
|
||||
if !user.Admin { // reset comment to deleted for non-admins
|
||||
c.SetDeleted(store.SoftDelete)
|
||||
}
|
||||
c.User.Blocked = true
|
||||
c.Deleted = true
|
||||
// mark user blocked
|
||||
if bErr == nil && blocked {
|
||||
c.User.Blocked = blocked
|
||||
}
|
||||
|
||||
// set verified status retroactively
|
||||
if !blocked {
|
||||
if !c.User.Blocked {
|
||||
verifReq := engine.FlagRequest{Flag: engine.Verified, Locator: store.Locator{SiteID: c.Locator.SiteID}, UserID: c.User.ID}
|
||||
c.User.Verified, _ = s.Engine.Flag(verifReq)
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
|
||||
### find request with tree
|
||||
GET {{host}}/api/v1/find?site={{site}}&sort=-controversy&format=tree&url={{url}}
|
||||
GET {{host}}/api/v1/find?site={{site}}&sort=-time&format=tree&url={{url}}
|
||||
|
||||
### find request with plain
|
||||
GET {{host}}/api/v1/find?site={{site}}&sort=-controversy&format=plain&url={{url}}
|
||||
|
||||
Reference in New Issue
Block a user