2013-02-22 15:41:12 -05:00
|
|
|
/**
|
|
|
|
Our data model for interacting with flagged posts.
|
2013-02-20 13:15:50 -05:00
|
|
|
|
2013-03-05 15:39:21 -05:00
|
|
|
@class FlaggedPost
|
2013-02-22 15:41:12 -05:00
|
|
|
@extends Discourse.Post
|
|
|
|
@namespace Discourse
|
|
|
|
@module Discourse
|
2013-03-05 15:39:21 -05:00
|
|
|
**/
|
2013-02-22 15:41:12 -05:00
|
|
|
Discourse.FlaggedPost = Discourse.Post.extend({
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-06-17 03:15:56 -04:00
|
|
|
summary: function(){
|
|
|
|
return _(this.post_actions)
|
2013-06-26 02:00:17 -04:00
|
|
|
.groupBy(function(a){ return a.post_action_type_id; })
|
2013-06-17 03:15:56 -04:00
|
|
|
.map(function(v,k){
|
2013-07-08 19:32:16 -04:00
|
|
|
return I18n.t('admin.flags.summary.action_type_' + k, {count: v.length});
|
2013-06-17 03:15:56 -04:00
|
|
|
})
|
2013-06-26 02:18:50 -04:00
|
|
|
.join(',');
|
2013-06-17 03:15:56 -04:00
|
|
|
}.property(),
|
|
|
|
|
2013-05-20 15:27:58 -04:00
|
|
|
flaggers: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
var r,
|
|
|
|
_this = this;
|
|
|
|
r = [];
|
2013-06-10 16:48:50 -04:00
|
|
|
_.each(this.post_actions, function(action) {
|
2013-06-26 03:01:39 -04:00
|
|
|
var user = _this.userLookup[action.user_id];
|
2014-06-23 23:20:57 -04:00
|
|
|
var deletedBy = null;
|
|
|
|
if(action.deleted_by_id){
|
|
|
|
deletedBy = _this.userLookup[action.deleted_by_id];
|
|
|
|
}
|
|
|
|
|
2013-07-08 19:32:16 -04:00
|
|
|
var flagType = I18n.t('admin.flags.summary.action_type_' + action.post_action_type_id, {count: 1});
|
2014-06-23 23:20:57 -04:00
|
|
|
|
|
|
|
r.push({
|
|
|
|
user: user, flagType: flagType, flaggedAt: action.created_at, deletedBy: deletedBy,
|
|
|
|
tookAction: action.staff_took_action, deletedAt: action.deleted_at
|
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
|
|
|
return r;
|
2013-05-20 15:27:58 -04:00
|
|
|
}.property(),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-05-20 15:27:58 -04:00
|
|
|
messages: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
var r,
|
|
|
|
_this = this;
|
|
|
|
r = [];
|
2013-06-10 16:48:50 -04:00
|
|
|
_.each(this.post_actions,function(action) {
|
|
|
|
if (action.message) {
|
|
|
|
r.push({
|
|
|
|
user: _this.userLookup[action.user_id],
|
|
|
|
message: action.message,
|
2013-10-16 11:47:01 -04:00
|
|
|
permalink: action.permalink,
|
|
|
|
bySystemUser: (action.user_id === -1 ? true : false)
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return r;
|
2013-05-20 15:27:58 -04:00
|
|
|
}.property(),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-04-03 16:06:55 -04:00
|
|
|
lastFlagged: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
return this.post_actions[0].created_at;
|
2013-04-03 16:06:55 -04:00
|
|
|
}.property(),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-04-03 16:06:55 -04:00
|
|
|
user: function() {
|
2013-02-22 15:41:12 -05:00
|
|
|
return this.userLookup[this.user_id];
|
2013-04-03 16:06:55 -04:00
|
|
|
}.property(),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-04-03 16:06:55 -04:00
|
|
|
topicHidden: function() {
|
2013-06-26 02:00:17 -04:00
|
|
|
return !this.get('topic_visible');
|
2013-04-03 16:06:55 -04:00
|
|
|
}.property('topic_hidden'),
|
2013-02-21 14:09:28 -05:00
|
|
|
|
2013-07-26 15:40:08 -04:00
|
|
|
flaggedForSpam: function() {
|
|
|
|
return !_.every(this.get('post_actions'), function(action) { return action.name_key !== 'spam'; });
|
|
|
|
}.property('post_actions.@each.name_key'),
|
|
|
|
|
2014-02-05 17:54:16 -05:00
|
|
|
topicFlagged: function() {
|
|
|
|
return _.any(this.get('post_actions'), function(action) { return action.targets_topic; });
|
|
|
|
}.property('post_actions.@each.targets_topic'),
|
|
|
|
|
|
|
|
postAuthorFlagged: function() {
|
|
|
|
return _.any(this.get('post_actions'), function(action) { return !action.targets_topic; });
|
|
|
|
}.property('post_actions.@each.targets_topic'),
|
|
|
|
|
2013-07-26 15:40:08 -04:00
|
|
|
canDeleteAsSpammer: function() {
|
2013-08-08 12:42:08 -04:00
|
|
|
return (Discourse.User.currentProp('staff') && this.get('flaggedForSpam') && this.get('user.can_delete_all_posts') && this.get('user.can_be_deleted'));
|
2013-07-26 15:40:08 -04:00
|
|
|
}.property('flaggedForSpam'),
|
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
deletePost: function() {
|
2013-10-02 10:59:57 -04:00
|
|
|
if (this.get('post_number') === 1) {
|
2013-06-26 02:18:50 -04:00
|
|
|
return Discourse.ajax('/t/' + this.topic_id, { type: 'DELETE', cache: false });
|
2013-02-22 15:41:12 -05:00
|
|
|
} else {
|
2013-06-26 02:18:50 -04:00
|
|
|
return Discourse.ajax('/posts/' + this.id, { type: 'DELETE', cache: false });
|
2013-02-20 13:15:50 -05:00
|
|
|
}
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2013-06-20 03:42:15 -04:00
|
|
|
disagreeFlags: function() {
|
2013-06-26 02:18:50 -04:00
|
|
|
return Discourse.ajax('/admin/flags/disagree/' + this.id, { type: 'POST', cache: false });
|
2013-02-22 15:41:12 -05:00
|
|
|
},
|
|
|
|
|
2013-06-20 03:42:15 -04:00
|
|
|
deferFlags: function() {
|
2013-06-26 02:18:50 -04:00
|
|
|
return Discourse.ajax('/admin/flags/defer/' + this.id, { type: 'POST', cache: false });
|
2013-06-20 03:42:15 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
agreeFlags: function() {
|
2013-06-26 02:18:50 -04:00
|
|
|
return Discourse.ajax('/admin/flags/agree/' + this.id, { type: 'POST', cache: false });
|
2013-06-20 03:42:15 -04:00
|
|
|
},
|
|
|
|
|
2013-07-09 15:20:18 -04:00
|
|
|
postHidden: Em.computed.alias('hidden'),
|
2013-06-20 03:42:15 -04:00
|
|
|
|
2013-06-26 02:18:50 -04:00
|
|
|
extraClasses: function() {
|
|
|
|
var classes = [];
|
|
|
|
if (this.get('hidden')) {
|
|
|
|
classes.push('hidden-post');
|
|
|
|
}
|
|
|
|
if (this.get('deleted')){
|
|
|
|
classes.push('deleted');
|
|
|
|
}
|
|
|
|
return classes.join(' ');
|
|
|
|
}.property(),
|
|
|
|
|
2013-07-09 15:20:18 -04:00
|
|
|
deleted: Em.computed.or('deleted_at', 'topic_deleted_at')
|
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
Discourse.FlaggedPost.reopenClass({
|
2013-08-19 07:14:26 -04:00
|
|
|
findAll: function(filter, offset) {
|
|
|
|
|
|
|
|
offset = offset || 0;
|
|
|
|
|
2013-04-03 16:06:55 -04:00
|
|
|
var result = Em.A();
|
2013-06-05 10:24:50 -04:00
|
|
|
result.set('loading', true);
|
2013-08-19 07:14:26 -04:00
|
|
|
return Discourse.ajax('/admin/flags/' + filter + '.json?offset=' + offset).then(function(data) {
|
2013-04-03 16:06:55 -04:00
|
|
|
var userLookup = {};
|
2013-06-10 16:48:50 -04:00
|
|
|
_.each(data.users,function(user) {
|
2013-06-27 02:32:03 -04:00
|
|
|
userLookup[user.id] = Discourse.AdminUser.create(user);
|
2013-04-03 16:06:55 -04:00
|
|
|
});
|
2013-06-10 16:48:50 -04:00
|
|
|
_.each(data.posts,function(post) {
|
|
|
|
var f = Discourse.FlaggedPost.create(post);
|
2013-04-03 16:06:55 -04:00
|
|
|
f.userLookup = userLookup;
|
|
|
|
result.pushObject(f);
|
|
|
|
});
|
2013-06-05 10:24:50 -04:00
|
|
|
result.set('loading', false);
|
2013-08-19 07:14:26 -04:00
|
|
|
return result;
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-02-20 13:15:50 -05:00
|
|
|
|