Prevent flagging of deleted posts and don't show deleted posts in flagged post list (#3846)
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
c3c62ad2ad
Коммит
80d83ae77c
@@ -1332,6 +1332,7 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
go Publish(message)
|
go Publish(message)
|
||||||
go DeletePostFiles(c.TeamId, post)
|
go DeletePostFiles(c.TeamId, post)
|
||||||
|
go DeleteFlaggedPost(c.Session.UserId, post)
|
||||||
|
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
result["id"] = postId
|
result["id"] = postId
|
||||||
@@ -1339,6 +1340,13 @@ func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteFlaggedPost(userId string, post *model.Post) {
|
||||||
|
if result := <-Srv.Store.Preference().Delete(userId, model.PREFERENCE_CATEGORY_FLAGGED_POST, post.Id); result.Err != nil {
|
||||||
|
l4g.Warn(utils.T("api.post.delete_flagged_post.app_error.warn"), result.Err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func DeletePostFiles(teamId string, post *model.Post) {
|
func DeletePostFiles(teamId string, post *model.Post) {
|
||||||
if len(post.Filenames) == 0 {
|
if len(post.Filenames) == 0 {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1097,6 +1097,10 @@
|
|||||||
"id": "api.post.create_post.bad_filename.error",
|
"id": "api.post.create_post.bad_filename.error",
|
||||||
"translation": "Bad filename discarded, filename=%v"
|
"translation": "Bad filename discarded, filename=%v"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.post.delete_flagged_post.app_error.warn",
|
||||||
|
"translation": "Unable to delete flagged post preference when deleting post, err=%v"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "api.post.create_post.channel_root_id.app_error",
|
"id": "api.post.create_post.channel_root_id.app_error",
|
||||||
"translation": "Invalid ChannelId for RootId parameter"
|
"translation": "Invalid ChannelId for RootId parameter"
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ func (s SqlPostStore) GetFlaggedPosts(userId string, offset int, limit int) Stor
|
|||||||
pl := &model.PostList{}
|
pl := &model.PostList{}
|
||||||
|
|
||||||
var posts []*model.Post
|
var posts []*model.Post
|
||||||
if _, err := s.GetReplica().Select(&posts, "SELECT * FROM Posts WHERE Id IN (SELECT Name FROM Preferences WHERE UserId = :UserId AND Category = :Category) ORDER BY CreateAt ASC LIMIT :Limit OFFSET :Offset", map[string]interface{}{"UserId": userId, "Category": model.PREFERENCE_CATEGORY_FLAGGED_POST, "Offset": offset, "Limit": limit}); err != nil {
|
if _, err := s.GetReplica().Select(&posts, "SELECT * FROM Posts WHERE Id IN (SELECT Name FROM Preferences WHERE UserId = :UserId AND Category = :Category) AND DeleteAt = 0 ORDER BY CreateAt ASC LIMIT :Limit OFFSET :Offset", map[string]interface{}{"UserId": userId, "Category": model.PREFERENCE_CATEGORY_FLAGGED_POST, "Offset": offset, "Limit": limit}); err != nil {
|
||||||
result.Err = model.NewLocAppError("SqlPostStore.GetFlaggedPosts", "store.sql_post.get_flagged_posts.app_error", nil, err.Error())
|
result.Err = model.NewLocAppError("SqlPostStore.GetFlaggedPosts", "store.sql_post.get_flagged_posts.app_error", nil, err.Error())
|
||||||
} else {
|
} else {
|
||||||
for _, post := range posts {
|
for _, post := range posts {
|
||||||
|
|||||||
@@ -923,6 +923,14 @@ func TestPostStoreGetFlaggedPosts(t *testing.T) {
|
|||||||
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
|
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
|
||||||
time.Sleep(2 * time.Millisecond)
|
time.Sleep(2 * time.Millisecond)
|
||||||
|
|
||||||
|
o3 := &model.Post{}
|
||||||
|
o3.ChannelId = o1.ChannelId
|
||||||
|
o3.UserId = model.NewId()
|
||||||
|
o3.Message = "a" + model.NewId() + "b"
|
||||||
|
o3.DeleteAt = 1
|
||||||
|
o3 = (<-store.Post().Save(o3)).Data.(*model.Post)
|
||||||
|
time.Sleep(2 * time.Millisecond)
|
||||||
|
|
||||||
r1 := (<-store.Post().GetFlaggedPosts(o1.ChannelId, 0, 2)).Data.(*model.PostList)
|
r1 := (<-store.Post().GetFlaggedPosts(o1.ChannelId, 0, 2)).Data.(*model.PostList)
|
||||||
|
|
||||||
if len(r1.Order) != 0 {
|
if len(r1.Order) != 0 {
|
||||||
@@ -968,4 +976,19 @@ func TestPostStoreGetFlaggedPosts(t *testing.T) {
|
|||||||
if len(r4.Order) != 2 {
|
if len(r4.Order) != 2 {
|
||||||
t.Fatal("should have 2 posts")
|
t.Fatal("should have 2 posts")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
preferences = model.Preferences{
|
||||||
|
{
|
||||||
|
UserId: o1.UserId,
|
||||||
|
Category: model.PREFERENCE_CATEGORY_FLAGGED_POST,
|
||||||
|
Name: o3.Id,
|
||||||
|
Value: "true",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
Must(store.Preference().Save(&preferences))
|
||||||
|
|
||||||
|
if len(r4.Order) != 2 {
|
||||||
|
t.Fatal("should have 2 posts")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,6 +336,26 @@ export default class PostInfo extends React.Component {
|
|||||||
flagFunc = this.flagPost;
|
flagFunc = this.flagPost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let flagTrigger;
|
||||||
|
if (!Utils.isPostEphemeral(post)) {
|
||||||
|
flagTrigger = (
|
||||||
|
<OverlayTrigger
|
||||||
|
key={'flagtooltipkey' + flagVisible}
|
||||||
|
delayShow={Constants.OVERLAY_TIME_DELAY}
|
||||||
|
placement='top'
|
||||||
|
overlay={flagTooltip}
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href='#'
|
||||||
|
className={'flag-icon__container ' + flagVisible}
|
||||||
|
onClick={flagFunc}
|
||||||
|
>
|
||||||
|
{flag}
|
||||||
|
</a>
|
||||||
|
</OverlayTrigger>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ul className='post__header--info'>
|
<ul className='post__header--info'>
|
||||||
<li className='col'>
|
<li className='col'>
|
||||||
@@ -345,20 +365,7 @@ export default class PostInfo extends React.Component {
|
|||||||
compactDisplay={this.props.compactDisplay}
|
compactDisplay={this.props.compactDisplay}
|
||||||
useMilitaryTime={this.props.useMilitaryTime}
|
useMilitaryTime={this.props.useMilitaryTime}
|
||||||
/>
|
/>
|
||||||
<OverlayTrigger
|
{flagTrigger}
|
||||||
key={'flagtooltipkey' + flagVisible}
|
|
||||||
delayShow={Constants.OVERLAY_TIME_DELAY}
|
|
||||||
placement='top'
|
|
||||||
overlay={flagTooltip}
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href='#'
|
|
||||||
className={'flag-icon__container ' + flagVisible}
|
|
||||||
onClick={flagFunc}
|
|
||||||
>
|
|
||||||
{flag}
|
|
||||||
</a>
|
|
||||||
</OverlayTrigger>
|
|
||||||
</li>
|
</li>
|
||||||
{options}
|
{options}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@@ -330,6 +330,26 @@ export default class RhsComment extends React.Component {
|
|||||||
flagFunc = this.flagPost;
|
flagFunc = this.flagPost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let flagTrigger;
|
||||||
|
if (!Utils.isPostEphemeral(post)) {
|
||||||
|
flagTrigger = (
|
||||||
|
<OverlayTrigger
|
||||||
|
key={'commentflagtooltipkey' + flagVisible}
|
||||||
|
delayShow={Constants.OVERLAY_TIME_DELAY}
|
||||||
|
placement='top'
|
||||||
|
overlay={flagTooltip}
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href='#'
|
||||||
|
className={'flag-icon__container ' + flagVisible}
|
||||||
|
onClick={flagFunc}
|
||||||
|
>
|
||||||
|
{flag}
|
||||||
|
</a>
|
||||||
|
</OverlayTrigger>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'post post--thread ' + currentUserCss + ' ' + compactClass}>
|
<div className={'post post--thread ' + currentUserCss + ' ' + compactClass}>
|
||||||
<div className='post__content'>
|
<div className='post__content'>
|
||||||
@@ -352,20 +372,7 @@ export default class RhsComment extends React.Component {
|
|||||||
minute='2-digit'
|
minute='2-digit'
|
||||||
/>
|
/>
|
||||||
</time>
|
</time>
|
||||||
<OverlayTrigger
|
{flagTrigger}
|
||||||
key={'commentflagtooltipkey' + flagVisible}
|
|
||||||
delayShow={Constants.OVERLAY_TIME_DELAY}
|
|
||||||
placement='top'
|
|
||||||
overlay={flagTooltip}
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
href='#'
|
|
||||||
className={'flag-icon__container ' + flagVisible}
|
|
||||||
onClick={flagFunc}
|
|
||||||
>
|
|
||||||
{flag}
|
|
||||||
</a>
|
|
||||||
</OverlayTrigger>
|
|
||||||
</li>
|
</li>
|
||||||
<li className='col col__reply'>
|
<li className='col col__reply'>
|
||||||
{dropdown}
|
{dropdown}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user