Commit 65a172f2 authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

Merge branch 'clean-redirect-when-back-to-private' into 'master'

redirect to data source list when curator switch back to private a datasource...

See merge request !91
parents e692c587 c91bd12c
......@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-02-18 14:46+0100\n"
"POT-Creation-Date: 2022-02-03 17:26+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......@@ -574,8 +574,7 @@ msgstr "Public"
msgid "public__help_text"
msgstr ""
"Is the data source publicly readable? Otherwise you can allow specific "
"users."
"Is the data source publicly readable? Otherwise you can allow specific users."
msgid "data_source__name__verbose_name"
msgstr "Name"
......@@ -1035,9 +1034,6 @@ msgstr ""
msgid "Responses"
msgstr ""
msgid "Update content"
msgstr ""
msgid "Download it"
msgstr ""
......@@ -1047,6 +1043,9 @@ msgstr ""
msgid "How to fill it"
msgstr ""
msgid "Update content"
msgstr ""
msgid "Mapping used"
msgstr "Response scheme used"
......@@ -1430,6 +1429,10 @@ msgstr ""
msgid "Update the data source"
msgstr ""
#, python-format
msgid "Data source \"%s\" went private, you can not longer access to it."
msgstr ""
msgid "History of a data source"
msgstr ""
......
......@@ -181,15 +181,35 @@ class DataSourceUpdateViewTestCase(ViewTestCase):
set([(gu.user.pk, gu.can_write) for gu in granted_users]),
set([(gu.user.pk, gu.can_write) for gu in self.public_data_source_of_user.granteduser_set.all()]))
is_curator = business_process.is_curator(self.user)
def test_back_to_private_by_curator(self):
url = reverse('viralhostrangedb:data-source-update', args=[self.public_data_source_of_user.pk])
granted_users = set(self.public_data_source_of_user.granteduser_set.all())
self.client.force_login(self.toto)
business_process.set_curator(self.toto, True)
form_data = dict(
name=self.public_data_source_of_user.name,
life_domain="bacteria",
description="a "*20,
public=True,
allowed_users_editor=
"\n".join(["%s %s;%i;%s" % (gu.user.last_name, gu.user.first_name, gu.user.pk, gu.can_write)
for gu in granted_users]),
)
self.assertEqual(form_data["provider_first_name"] if is_curator else None,
self.public_data_source_of_user.provider_first_name)
self.assertEqual(form_data["provider_last_name"] if is_curator else None,
self.public_data_source_of_user.provider_last_name)
response = self.client.post(url, form_data)
self.write_in_tmp_file(response)
self.assertRedirects(
response,
expected_url=reverse('viralhostrangedb:data-source-detail', args=[self.public_data_source_of_user.pk])
)
form_data['public'] = False
def test_update_work_for_curator(self):
self.test_update_work()
response = self.client.post(url, form_data)
self.assertRedirects(
response,
expected_url=reverse('viralhostrangedb:data-source-list')
)
def test_new_user_granted_by_email(self):
url = reverse('viralhostrangedb:data-source-update', args=[self.public_data_source_of_user.pk])
......
......@@ -46,6 +46,7 @@ from viralhostrangedb import forms, business_process, views_api
from viralhostrangedb import mixins
from viralhostrangedb import models
from viralhostrangedb.business_process import MessageImportationObserver
from viralhostrangedb.templatetags.viralhostrange_tags import can_see
from viralhostrangedb.utils import order_queryset_specifically
logger = logging.getLogger(__name__)
......@@ -372,6 +373,11 @@ class DataSourceUpdateView(mixins.OnlyEditorOrCuratorOrOwnedMixin, UpdateView):
form_class = forms.DataSourceUserCreateOrUpdateForm
template_name = 'basetheme_bootstrap/small_form_host.html'
def get_success_url(self):
if can_see(self.request.user, self.object):
return super().get_success_url()
return reverse('viralhostrangedb:data-source-list')
def get_context_data(self, *, object_list=None, **kwargs):
context = super().get_context_data(object_list=object_list, **kwargs)
context["page_title"] = _("Editing a data source")
......@@ -396,6 +402,12 @@ class DataSourceUpdateView(mixins.OnlyEditorOrCuratorOrOwnedMixin, UpdateView):
change_fields=changed_data,
altered_data=business_process.DataSourceAlteredData.INNER_INFORMATION,
)
if 'public' in changed_data and not self.object.public and not can_see(self.request.user, self.object):
messages.add_message(
request=self.request,
level=messages.SUCCESS,
message=ugettext('Data source "%s" went private, you can not longer access to it.') % self.object.name,
)
return r
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment