Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing https://github.com/Cadasta/cadasta-platform/issues/632 #729

Merged
merged 1 commit into from
Sep 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cadasta/organization/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def __init__(self, user, *args, **kwargs):
super().__init__(*args, **kwargs)
self.user = user
choices = kwargs.get('choices', ())
self.widget = ProjectRoleWidget(user=user, choices=choices)
role = kwargs.get('initial', ())
self.widget = ProjectRoleWidget(user=user, role=role, choices=choices)


class PublicPrivateField(forms.CharField):
Expand Down
33 changes: 32 additions & 1 deletion cadasta/organization/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ def setUp(self):
email='[email protected]',
full_name='Bob Smith'
)
self.widget = ProjectRoleWidget(user=self.user, choices=FORM_CHOICES)
self.widget = ProjectRoleWidget(user=self.user,
role='A',
choices=FORM_CHOICES)

def test_render_with_admin(self):
html = self.widget.render(self.user.username, 'A')
Expand All @@ -34,7 +36,36 @@ def test_render_with_admin(self):
)
assert expected == html

def test_render_with_admin_next_page_submission(self):
"""
When admin user submit member permission page when clicking
previous and come back again to member permission page,
widget gets None as value for admin user. So additional
role parameter added to widget to check user is a Administrative
user or not
"""
html = self.widget.render(self.user.username, None)

expected = (
'<tr>'
' <td>'
' <p>Bob Smith</p>'
' <p>bob</p>'
' </td>'
' <td class="hidden-xs hidden-sm">[email protected]</td>'
' <td>'
' Administrator'
' </td>'
'</tr>'
)
assert expected == html

def test_render_with_manager(self):
"""
Setting widget role attribute to empty as it's initialize
as a Administrative user
"""
self.widget.role = ''
html = self.widget.render(self.user.username, 'PM')

expected = (
Expand Down
5 changes: 3 additions & 2 deletions cadasta/organization/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ class ProjectRoleWidget(Select):
'</tr>'
)

def __init__(self, user, *args, **kwargs):
def __init__(self, user, role, *args, **kwargs):
super().__init__(*args, **kwargs)
self.user = user
self.role = role

def render(self, name, value, attrs=None, choices=()):
if value == 'A':
if value == 'A' or self.role == 'A':
select = _("Administrator")
else:
select = super().render(name, value, attrs=attrs, choices=choices)
Expand Down