Skip to content

Commit

Permalink
Check "everyone_contributes" setting when updating project from publi…
Browse files Browse the repository at this point in the history
…c to private

Fixes #338.
  • Loading branch information
Julius O committed Feb 4, 2016
1 parent a056673 commit b1b5aee
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
13 changes: 13 additions & 0 deletions geokey/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ def create(cls, name, description, isprivate, islocked,

return project

def save(self, *args, **kwargs):
"""
Checks if project is set to private, but everyone_contributes is set
to `TRUE` and makes the option set to `AUTH`.
We are not allowing anonymous contributions for private projects.
"""
if (self.isprivate and
self.everyone_contributes == EVERYONE_CONTRIB.true):
self.everyone_contributes = EVERYONE_CONTRIB.auth

super(Project, self).save(*args, **kwargs)

def delete(self):
"""
Deletes the project by setting its status to `DELETED`. Also deletes
Expand Down
13 changes: 13 additions & 0 deletions geokey/projects/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,19 @@ def test(self):
self.assertTrue(project.can_contribute(AnonymousUser()))


class PublicToPrivateWithEveryoneContributesTest(TestCase):
def test(self):
project = ProjectFactory.create(**{
'isprivate': False,
'everyone_contributes': 'true'
})

project.isprivate = True
project.save()

self.assertEqual(project.everyone_contributes, 'auth')


class PublicProjectTest(TestCase):
def setUp(self):
self.moderator_view = UserFactory.create()
Expand Down
6 changes: 5 additions & 1 deletion geokey/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,20 @@ def put(self, request, project_id):
"""

project = Project.objects.as_admin(request.user, project_id)

serializer = ProjectSerializer(
project, data=request.data, partial=True,
fields=(
'id', 'name', 'description', 'status', 'isprivate', 'islocked',
'everyone_contributes'
)
)

if serializer.is_valid():
serializer.save()
return Response(serializer.data)
data = serializer.data
data['everyone_contributes'] = project.everyone_contributes
return Response(data)

return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

Expand Down
5 changes: 5 additions & 0 deletions geokey/static/js/admin.ui.updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ $(function(global) {
}
}

if (toToggle == 'everyone_contributes') {
$('input[name="everyone_contributes"][value="' + result + '"]').prop('checked', true);
}

if (toToggle === 'locked') {
if (result === 'locked') {
$('.glyphicon-lock').removeClass('hidden');
Expand Down Expand Up @@ -136,6 +140,7 @@ $(function(global) {
var result = (response.isprivate ? 'private' : 'public');

updateUi('private', result);
updateUi('everyone_contributes', response.everyone_contributes);
displaySuccess('private', 'The ' + name + ' is now ' + result + '.');
}

Expand Down

0 comments on commit b1b5aee

Please sign in to comment.