Example #1
0
def flag_node(request, path):
    assert_authentication(request)
    assert_permissions(request, ["node_storage.add_spamflag"])
    user = request.user
    node = assert_node_for_path(path)

    marks = node.spam_flags.filter(user=user.id).all()
    if marks.count() == 0:
        new_mark = backend.SpamFlag()
        new_mark.node = node
        new_mark.user_id = request.user.id
        new_mark.save()
        node.update_favorite_for_all_parents()

    # microblog alert
    post_node_was_flagged_message(path, user)
    return json_response({"markNodeResponse": {}})
Example #2
0
def flag_node(request, path):
    assert_authentication(request)
    assert_permissions(request, ['node_storage.add_spamflag'])
    user = request.user
    node = assert_node_for_path(path)

    marks = node.spam_flags.filter(user=user.id).all()
    if marks.count() == 0:
        new_mark = backend.SpamFlag()
        new_mark.node = node
        new_mark.user_id = request.user.id
        new_mark.save()
        node.update_favorite_for_all_parents()

    # microblog alert
    post_node_was_flagged_message(path, user)
    return json_response({'markNodeResponse': {}})
Example #3
0
 def test_post_node_was_flagged_message(self):
     hugo = create_user('Hugo')
     post = post_node_was_flagged_message('/', hugo)
     self.assertEqual(post.author, get_system_user())
     self.assertEqual(post.location, get_root_node())
     self.assertEqual(post.post_type, Post.SPAM_MARKED)
     self.assertIn(hugo, post.mentions.all())
     self.assertEqual(
         post.text_cache, '<span style="color: gray;">Hinweis:</span> ' +
         '<a href="/user/Hugo">@Hugo</a> hat <a href="/">ROOT'
         '<span class="nodeIndex">1</span></a> als Spam markiert.')
 def test_post_node_was_flagged_message(self):
     hugo = create_user('Hugo')
     post = post_node_was_flagged_message('/', hugo)
     self.assertEqual(post.author, get_system_user())
     self.assertEqual(post.location, get_root_node())
     self.assertEqual(post.post_type, Post.SPAM_MARKED)
     self.assertIn(hugo, post.mentions.all())
     self.assertEqual(
         post.text_cache,
         '<span style="color: gray;">Hinweis:</span> ' +
         '<a href="/user/Hugo">@Hugo</a> hat <a href="/">ROOT'
         '<span class="nodeIndex">1</span></a> als Spam markiert.')