'User can copy a plugin if he has change permissions
on the Page model, add permissions on the plugin model
and global change permissions.'

def test_user_can_copy_plugin(self):

    page = self.get_permissions_test_page()
    staff_user = self.get_staff_user_with_no_permissions()
    plugin = self._add_plugin_to_page(page)
    translation = self._add_translation_to_page(page)
    endpoint = self.get_copy_plugin_uri(plugin)
    source_placeholder = plugin.placeholder
    target_placeholder = page.placeholders.get(slot='right-column')
    data = {'source_plugin_id': plugin.pk, 'source_placeholder_id': source_placeholder.pk, 'source_language': plugin.language, 'target_language': translation.language, 'target_placeholder_id': target_placeholder.pk}
    self.add_permission(staff_user, 'change_page')
    self.add_permission(staff_user, 'add_link')
    self.add_global_permission(staff_user, can_change=True)
    with self.login_user_context(staff_user):
        response = self.client.post(endpoint, data)
        self.assertEqual(response.status_code, 200)
        self.assertTrue(source_placeholder.get_plugins('en').filter(pk=plugin.pk).exists())
        self.assertTrue(target_placeholder.get_plugins(translation.language).filter(plugin_type=plugin.plugin_type).exists())
