From 1571439b46e71cb1fb07a0cf13a5e727d2daab21 Mon Sep 17 00:00:00 2001 From: Oliver Roick Date: Thu, 25 May 2017 19:14:35 +0200 Subject: [PATCH] Public user project roles are not create with new project (#1515) --- .../0004_remove_Pb_project_roles.py | 22 +++++++++++++++++++ .../tests/test_views_default_projects.py | 7 ++++-- cadasta/organization/views/default.py | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 cadasta/organization/migrations/0004_remove_Pb_project_roles.py diff --git a/cadasta/organization/migrations/0004_remove_Pb_project_roles.py b/cadasta/organization/migrations/0004_remove_Pb_project_roles.py new file mode 100644 index 000000000..8cd6a8a40 --- /dev/null +++ b/cadasta/organization/migrations/0004_remove_Pb_project_roles.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.7 on 2017-05-19 08:14 +from __future__ import unicode_literals + +from django.db import migrations + + +def remove_public_user_role(apps, schema_editor): + ProjectRole = apps.get_model("organization", "ProjectRole") + ProjectRole.objects.filter(role='Pb').delete() + + +class Migration(migrations.Migration): + + dependencies = [ + ('organization', '0003_add_organizationrole_unique'), + ] + + operations = [ + migrations.RunPython( + remove_public_user_role, migrations.RunPython.noop), + ] diff --git a/cadasta/organization/tests/test_views_default_projects.py b/cadasta/organization/tests/test_views_default_projects.py index a836c9f08..c338a6393 100644 --- a/cadasta/organization/tests/test_views_default_projects.py +++ b/cadasta/organization/tests/test_views_default_projects.py @@ -488,11 +488,12 @@ def setUp(self): {'username': 'org_member_1'}, {'username': 'org_member_2'}, {'username': 'org_member_3'}, + {'username': 'org_member_4'}, {'username': 'org_non_member_1'}, {'username': 'org_non_member_2'}, {'username': 'org_non_member_3'}, {'username': 'org_non_member_4'}]) - for idx in range(5): + for idx in range(6): OrganizationRole.objects.create(organization=self.org, user=self.users[idx], admin=(idx < 2)) @@ -588,13 +589,15 @@ def test_get_from_initial_with_no_org(self): 'project_add_wizard-current_step': 'permissions', 'permissions-org_member_1': 'PM', 'permissions-org_member_2': 'DC', - 'permissions-org_member_3': 'PU' + 'permissions-org_member_3': 'PU', + 'permissions-org_member_4': 'Pb' } PERMISSIONS_POST_DATA_BAD = { 'project_add_wizard-current_step': 'permissions', 'permissions-org_member_1': 'PM', 'permissions-org_member_2': 'DC', 'permissions-org_member_3': 'PU', + 'permissions-org_member_4': 'Pb', 'permissions-bad_user': 'PU' } DETAILS_POST_DATA_MANIPULATED = { diff --git a/cadasta/organization/views/default.py b/cadasta/organization/views/default.py index 3c080ac2a..58e764e58 100644 --- a/cadasta/organization/views/default.py +++ b/cadasta/organization/views/default.py @@ -550,7 +550,7 @@ def done(self, form_list, form_dict, **kwargs): user_roles = [] for user in org.users.all(): role = form_data[2].get(user.username, None) - if role: + if role and role != 'Pb': user_roles.append((user, role)) try: with transaction.atomic():