2016-06-30 13:55:44 -04:00
|
|
|
import { ajax } from 'discourse/lib/ajax';
|
2015-11-20 20:27:06 -05:00
|
|
|
import Post from 'discourse/models/post';
|
2017-09-06 10:21:07 -04:00
|
|
|
import computed from 'ember-addons/ember-computed-decorators';
|
2017-09-23 10:39:58 -04:00
|
|
|
import { popupAjaxError } from 'discourse/lib/ajax-error';
|
2015-11-20 20:27:06 -05:00
|
|
|
|
2017-09-11 16:44:20 -04:00
|
|
|
export default Post.extend({
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2017-09-06 10:21:07 -04:00
|
|
|
@computed
|
|
|
|
summary() {
|
2013-06-17 03:15:56 -04:00
|
|
|
return _(this.post_actions)
|
2014-07-28 13:17:37 -04:00
|
|
|
.groupBy(function (a) { return a.post_action_type_id; })
|
|
|
|
.map(function (v,k) { return I18n.t('admin.flags.summary.action_type_' + k, { count: v.length }); })
|
2013-06-26 02:18:50 -04:00
|
|
|
.join(',');
|
2017-09-06 10:21:07 -04:00
|
|
|
},
|
2014-07-28 13:17:37 -04:00
|
|
|
|
2017-09-06 10:21:07 -04:00
|
|
|
@computed('last_revised_at', 'post_actions.@each.created_at')
|
|
|
|
wasEdited(lastRevisedAt) {
|
2015-08-11 12:27:07 -04:00
|
|
|
if (Ember.isEmpty(this.get("last_revised_at"))) { return false; }
|
2017-09-06 10:21:07 -04:00
|
|
|
lastRevisedAt = Date.parse(lastRevisedAt);
|
2014-08-18 12:56:39 -04:00
|
|
|
return _.some(this.get("post_actions"), function (postAction) {
|
|
|
|
return Date.parse(postAction.created_at) < lastRevisedAt;
|
|
|
|
});
|
2017-09-06 10:21:07 -04:00
|
|
|
},
|
2014-08-18 12:56:39 -04:00
|
|
|
|
2018-01-17 13:03:14 -05:00
|
|
|
@computed('post_actions')
|
|
|
|
hasDisposedBy() {
|
|
|
|
return this.get('post_actions').some(action => action.disposed_by);
|
|
|
|
},
|
|
|
|
|
2017-09-06 10:21:07 -04:00
|
|
|
@computed('post_actions.@each.name_key')
|
|
|
|
flaggedForSpam() {
|
2017-09-11 10:31:38 -04:00
|
|
|
return this.get('post_actions').every(action => action.name_key === 'spam');
|
2017-09-06 10:21:07 -04:00
|
|
|
},
|
2013-07-26 15:40:08 -04:00
|
|
|
|
2017-09-06 10:21:07 -04:00
|
|
|
@computed('post_actions.@each.targets_topic')
|
|
|
|
topicFlagged() {
|
2014-02-05 17:54:16 -05:00
|
|
|
return _.any(this.get('post_actions'), function(action) { return action.targets_topic; });
|
2017-09-06 10:21:07 -04:00
|
|
|
},
|
2014-02-05 17:54:16 -05:00
|
|
|
|
2017-09-06 10:21:07 -04:00
|
|
|
@computed('post_actions.@each.targets_topic')
|
|
|
|
postAuthorFlagged() {
|
2014-02-05 17:54:16 -05:00
|
|
|
return _.any(this.get('post_actions'), function(action) { return !action.targets_topic; });
|
2017-09-06 10:21:07 -04:00
|
|
|
},
|
2014-02-05 17:54:16 -05:00
|
|
|
|
2017-09-11 10:31:38 -04:00
|
|
|
@computed('flaggedForSpam')
|
2017-09-06 10:21:07 -04:00
|
|
|
canDeleteAsSpammer(flaggedForSpam) {
|
2017-09-11 10:31:38 -04:00
|
|
|
return flaggedForSpam &&
|
|
|
|
this.get('user.can_delete_all_posts') &&
|
|
|
|
this.get('user.can_be_deleted');
|
2017-09-06 10:21:07 -04:00
|
|
|
},
|
2013-07-26 15:40:08 -04:00
|
|
|
|
2017-09-06 10:21:07 -04:00
|
|
|
deletePost() {
|
2013-10-02 10:59:57 -04:00
|
|
|
if (this.get('post_number') === 1) {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax('/t/' + this.topic_id, { type: 'DELETE', cache: false });
|
2013-02-22 15:41:12 -05:00
|
|
|
} else {
|
2016-06-30 13:55:44 -04:00
|
|
|
return ajax('/posts/' + this.id, { type: 'DELETE', cache: false });
|
2013-02-20 13:15:50 -05:00
|
|
|
}
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2017-09-06 10:21:07 -04:00
|
|
|
disagreeFlags() {
|
2017-09-23 10:39:58 -04:00
|
|
|
return ajax('/admin/flags/disagree/' + this.id, { type: 'POST', cache: false }).catch(popupAjaxError);
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2017-09-06 10:21:07 -04:00
|
|
|
deferFlags(deletePost) {
|
2018-04-20 17:05:51 -04:00
|
|
|
const action = () => {
|
|
|
|
return ajax('/admin/flags/defer/' + this.id, {
|
|
|
|
type: 'POST', cache: false, data: { delete_post: deletePost }
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
if (deletePost && this._hasDeletableReplies()) {
|
|
|
|
return this._actOnFlagAndDeleteReplies(action);
|
|
|
|
} else {
|
|
|
|
return action().catch(popupAjaxError);
|
|
|
|
}
|
2013-06-20 03:42:15 -04:00
|
|
|
},
|
|
|
|
|
2017-09-06 10:21:07 -04:00
|
|
|
agreeFlags(actionOnPost) {
|
2018-04-20 17:05:51 -04:00
|
|
|
const action = () => {
|
|
|
|
return ajax('/admin/flags/agree/' + this.id, {
|
|
|
|
type: 'POST', cache: false, data: { action_on_post: actionOnPost }
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
if (actionOnPost === 'delete' && this._hasDeletableReplies()) {
|
|
|
|
return this._actOnFlagAndDeleteReplies(action);
|
|
|
|
} else {
|
|
|
|
return action().catch(popupAjaxError);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_hasDeletableReplies() {
|
|
|
|
return this.get('post_number') > 1 && this.get('reply_count') > 0;
|
|
|
|
},
|
|
|
|
|
|
|
|
_actOnFlagAndDeleteReplies(action) {
|
|
|
|
return new Ember.RSVP.Promise((resolve, reject) => {
|
|
|
|
return ajax(`/posts/${this.id}/reply-ids/all.json`).then(replies => {
|
|
|
|
const buttons = [];
|
|
|
|
|
|
|
|
buttons.push({
|
|
|
|
label: I18n.t('no_value'),
|
|
|
|
callback() {
|
|
|
|
action()
|
|
|
|
.then(resolve)
|
|
|
|
.catch(error => {
|
|
|
|
popupAjaxError(error);
|
|
|
|
reject();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
buttons.push({
|
|
|
|
label: I18n.t('yes_value'),
|
|
|
|
class: "btn-danger",
|
|
|
|
callback() {
|
|
|
|
Post.deleteMany(replies.map(r => r.id))
|
|
|
|
.then(action)
|
|
|
|
.then(resolve)
|
|
|
|
.catch(error => {
|
|
|
|
popupAjaxError(error);
|
|
|
|
reject();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
bootbox.dialog(I18n.t("admin.flags.delete_replies", { count: replies.length }), buttons);
|
|
|
|
}).catch(error => {
|
|
|
|
popupAjaxError(error);
|
|
|
|
reject();
|
|
|
|
});
|
|
|
|
});
|
2013-06-20 03:42:15 -04:00
|
|
|
},
|
|
|
|
|
2017-09-06 10:21:07 -04:00
|
|
|
postHidden: Ember.computed.alias('hidden'),
|
2013-06-20 03:42:15 -04:00
|
|
|
|
2017-09-11 14:01:59 -04:00
|
|
|
deleted: Ember.computed.or('deleted_at', 'topic_deleted_at'),
|
2017-09-14 12:44:49 -04:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|