allow flagging the post of a deleted user (#7897)

* Allowing the flagging of messages that were written by user accounts that have since been deleted

* replacing ternary operator with else if, else paradigm

* formatting fixes

* fixing message in tests
This commit is contained in:
Travis 2016-08-15 20:14:52 -07:00 committed by Blade Barringer
parent 12f1aae2dd
commit 1a409848a8
4 changed files with 34 additions and 23 deletions

View file

@ -30,7 +30,7 @@ describe('POST /chat/:chatId/flag', () => {
});
it('Returns an error when user tries to flag their own message', async () => {
let message = await user.post(`/groups/${group._id}/chat`, { message: TEST_MESSAGE });
let message = await user.post(`/groups/${group._id}/chat`, {message: TEST_MESSAGE});
await expect(user.post(`/groups/${group._id}/chat/${message.message.id}/flag`))
.to.eventually.be.rejected.and.eql({
code: 404,
@ -40,8 +40,24 @@ describe('POST /chat/:chatId/flag', () => {
});
it('Flags a chat', async () => {
let message = await anotherUser.post(`/groups/${group._id}/chat`, { message: TEST_MESSAGE});
message = message.message;
let { message } = await anotherUser.post(`/groups/${group._id}/chat`, {message: TEST_MESSAGE});
let flagResult = await user.post(`/groups/${group._id}/chat/${message.id}/flag`);
expect(flagResult.flags[user._id]).to.equal(true);
expect(flagResult.flagCount).to.equal(1);
let groupWithFlags = await admin.get(`/groups/${group._id}`);
let messageToCheck = find(groupWithFlags.chat, {id: message.id});
expect(messageToCheck.flags[user._id]).to.equal(true);
});
it('Flags a chat when the author\'s account was deleted', async () => {
let deletedUser = await generateUser();
let { message } = await deletedUser.post(`/groups/${group._id}/chat`, {message: TEST_MESSAGE});
await deletedUser.del('/user', {
password: 'password',
});
let flagResult = await user.post(`/groups/${group._id}/chat/${message.id}/flag`);
expect(flagResult.flags[user._id]).to.equal(true);
@ -54,8 +70,7 @@ describe('POST /chat/:chatId/flag', () => {
});
it('Flags a chat with a higher flag acount when an admin flags the message', async () => {
let message = await user.post(`/groups/${group._id}/chat`, { message: TEST_MESSAGE});
message = message.message;
let { message } = await user.post(`/groups/${group._id}/chat`, {message: TEST_MESSAGE});
let flagResult = await admin.post(`/groups/${group._id}/chat/${message.id}/flag`);
expect(flagResult.flags[admin._id]).to.equal(true);
@ -69,8 +84,7 @@ describe('POST /chat/:chatId/flag', () => {
});
it('Returns an error when user tries to flag a message that is already flagged', async () => {
let message = await anotherUser.post(`/groups/${group._id}/chat`, { message: TEST_MESSAGE});
message = message.message;
let { message } = await anotherUser.post(`/groups/${group._id}/chat`, {message: TEST_MESSAGE});
await user.post(`/groups/${group._id}/chat/${message.id}/flag`);

View file

@ -96,20 +96,10 @@ habitrpg.controller('ChatCtrl', ['$scope', 'Groups', 'Chat', 'User', '$http', 'A
$scope.groupId = groupId;
$scope.isSystemMessage = message.uuid === 'system';
if (message.uuid === 'system') {
$rootScope.openModal('abuse-flag',{
controller:'MemberModalCtrl',
scope: $scope
});
} else {
Members.selectMember(message.uuid)
.then(function () {
$rootScope.openModal('abuse-flag',{
controller:'MemberModalCtrl',
scope: $scope
});
});
}
$rootScope.openModal('abuse-flag',{
controller:'MemberModalCtrl',
scope: $scope
});
}
};

View file

@ -217,7 +217,14 @@ api.flagChat = {
let reporterEmailContent = getUserInfo(user, ['email']).email;
let authorEmailContent = author ? getUserInfo(author, ['email']).email : 'system';
let authorEmailContent;
if (author) {
authorEmailContent = getUserInfo(author, ['email']).email;
} else if (message.uuid === 'system') {
authorEmailContent = 'system';
} else {
authorEmailContent = 'Author Account Deleted';
}
let groupUrl = getGroupUrl(group);

View file

@ -102,7 +102,7 @@ script(type='text/ng-template', id='modals/send-gift.html')
script(type='text/ng-template', id='modals/abuse-flag.html')
.modal-header
h4!=env.t('abuseFlagModalHeading', {name: "<span class='text-danger'>{{isSystemMessage ? env.t('systemMessage') : profile.profile.name}}</span>"})
h4!=env.t('abuseFlagModalHeading', {name: "<span class='text-danger'>{{isSystemMessage ? env.t('systemMessage') : abuseObject.user}}</span>"})
.modal-body
blockquote
markdown(text="abuseObject.text")