2015-07-03 14:57:07 -04:00
|
|
|
import createStore from 'helpers/create-store';
|
2015-11-20 20:27:06 -05:00
|
|
|
import AdminUser from 'admin/models/admin-user';
|
2016-11-08 14:29:50 -05:00
|
|
|
import { mapRoutes } from 'discourse/mapping-router';
|
2015-07-03 14:57:07 -04:00
|
|
|
|
2013-07-26 15:40:08 -04:00
|
|
|
var buildPost = function(args) {
|
|
|
|
return Discourse.Post.create(_.merge({
|
|
|
|
id: 1,
|
|
|
|
can_delete: true,
|
|
|
|
version: 1
|
|
|
|
}, args || {}));
|
|
|
|
};
|
|
|
|
|
|
|
|
var buildAdminUser = function(args) {
|
2015-11-20 20:27:06 -05:00
|
|
|
return AdminUser.create(_.merge({
|
2013-07-26 15:40:08 -04:00
|
|
|
id: 11,
|
|
|
|
username: 'urist'
|
|
|
|
}, args || {}));
|
|
|
|
};
|
|
|
|
|
2014-07-30 18:56:01 -04:00
|
|
|
moduleFor("controller:flag", "controller:flag", {
|
2016-11-08 14:29:50 -05:00
|
|
|
setup() {
|
|
|
|
this.registry.register('router:main', mapRoutes());
|
|
|
|
},
|
2014-07-30 18:56:01 -04:00
|
|
|
needs: ['controller:modal']
|
|
|
|
});
|
2013-07-26 15:40:08 -04:00
|
|
|
|
|
|
|
test("canDeleteSpammer not staff", function(){
|
2015-07-03 14:57:07 -04:00
|
|
|
const store = createStore();
|
|
|
|
|
2014-07-30 18:56:01 -04:00
|
|
|
var flagController = this.subject({ model: buildPost() });
|
|
|
|
sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(false);
|
2015-07-03 14:57:07 -04:00
|
|
|
|
|
|
|
const spamFlag = store.createRecord('post-action-type', {name_key: 'spam'});
|
|
|
|
flagController.set('selected', spamFlag);
|
2013-07-26 15:40:08 -04:00
|
|
|
equal(flagController.get('canDeleteSpammer'), false, 'false if current user is not staff');
|
|
|
|
});
|
|
|
|
|
2014-07-30 18:56:01 -04:00
|
|
|
var canDeleteSpammer = function(flagController, postActionType, expected, testName) {
|
2015-07-03 14:57:07 -04:00
|
|
|
const store = createStore();
|
|
|
|
const flag = store.createRecord('post-action-type', {name_key: postActionType});
|
|
|
|
flagController.set('selected', flag);
|
|
|
|
|
2014-07-30 18:56:01 -04:00
|
|
|
equal(flagController.get('canDeleteSpammer'), expected, testName);
|
2013-07-26 15:40:08 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
test("canDeleteSpammer spam not selected", function(){
|
2014-07-30 18:56:01 -04:00
|
|
|
sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true);
|
|
|
|
var flagController = this.subject({ model: buildPost() });
|
|
|
|
flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: true}));
|
|
|
|
canDeleteSpammer(flagController, 'off_topic', false, 'false if current user is staff, but selected is off_topic');
|
|
|
|
canDeleteSpammer(flagController, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate');
|
|
|
|
canDeleteSpammer(flagController, 'notify_user', false, 'false if current user is staff, but selected is notify_user');
|
|
|
|
canDeleteSpammer(flagController, 'notify_moderators', false, 'false if current user is staff, but selected is notify_moderators');
|
2013-07-26 15:40:08 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test("canDeleteSpammer spam selected", function(){
|
2014-07-30 18:56:01 -04:00
|
|
|
sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true);
|
|
|
|
var flagController = this.subject({ model: buildPost() });
|
|
|
|
flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: true}));
|
|
|
|
canDeleteSpammer(flagController, 'spam', true, 'true if current user is staff, selected is spam, posts and user can be deleted');
|
2013-07-26 15:40:08 -04:00
|
|
|
|
2014-07-30 18:56:01 -04:00
|
|
|
flagController.set('userDetails', buildAdminUser({can_delete_all_posts: false, can_be_deleted: true}));
|
|
|
|
canDeleteSpammer(flagController, 'spam', false, 'false if current user is staff, selected is spam, posts cannot be deleted');
|
2013-07-26 15:40:08 -04:00
|
|
|
|
2014-07-30 18:56:01 -04:00
|
|
|
flagController.set('userDetails', buildAdminUser({can_delete_all_posts: true, can_be_deleted: false}));
|
|
|
|
canDeleteSpammer(flagController, 'spam', false, 'false if current user is staff, selected is spam, user cannot be deleted');
|
2013-07-26 15:40:08 -04:00
|
|
|
|
2014-07-30 18:56:01 -04:00
|
|
|
flagController.set('userDetails', buildAdminUser({can_delete_all_posts: false, can_be_deleted: false}));
|
|
|
|
canDeleteSpammer(flagController, 'spam', false, 'false if current user is staff, selected is spam, user cannot be deleted');
|
2013-07-26 15:40:08 -04:00
|
|
|
});
|
2016-04-03 20:26:42 -04:00
|
|
|
|
|
|
|
test("canSendWarning not staff", function(){
|
|
|
|
const store = createStore();
|
|
|
|
|
|
|
|
var flagController = this.subject({ model: buildPost() });
|
|
|
|
sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(false);
|
|
|
|
|
|
|
|
const notifyUserFlag = store.createRecord('post-action-type', {name_key: 'notify_user'});
|
|
|
|
flagController.set('selected', notifyUserFlag);
|
|
|
|
equal(flagController.get('canSendWarning'), false, 'false if current user is not staff');
|
|
|
|
});
|
|
|
|
|
|
|
|
var canSendWarning = function(flagController, postActionType, expected, testName) {
|
|
|
|
const store = createStore();
|
|
|
|
const flag = store.createRecord('post-action-type', {name_key: postActionType});
|
|
|
|
flagController.set('selected', flag);
|
|
|
|
|
|
|
|
equal(flagController.get('canSendWarning'), expected, testName);
|
|
|
|
};
|
|
|
|
|
|
|
|
test("canSendWarning notify_user not selected", function(){
|
|
|
|
sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true);
|
|
|
|
var flagController = this.subject({ model: buildPost() });
|
|
|
|
canSendWarning(flagController, 'off_topic', false, 'false if current user is staff, but selected is off_topic');
|
|
|
|
canSendWarning(flagController, 'inappropriate', false, 'false if current user is staff, but selected is inappropriate');
|
|
|
|
canSendWarning(flagController, 'spam', false, 'false if current user is staff, but selected is spam');
|
|
|
|
canSendWarning(flagController, 'notify_moderators', false, 'false if current user is staff, but selected is notify_moderators');
|
|
|
|
});
|
|
|
|
|
|
|
|
test("canSendWarning notify_user selected", function(){
|
|
|
|
sandbox.stub(Discourse.User, 'currentProp').withArgs('staff').returns(true);
|
|
|
|
var flagController = this.subject({ model: buildPost() });
|
|
|
|
canSendWarning(flagController, 'notify_user', true, 'true if current user is staff, selected is notify_user');
|
2016-11-08 14:29:50 -05:00
|
|
|
});
|