Skip to content

Commit

Permalink
Fixes to options.
Browse files Browse the repository at this point in the history
  • Loading branch information
teleyinex committed May 8, 2017
1 parent 746c898 commit d76347b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pybossa/api/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ def _filter_private_data(self, data):
return tmp

def _select_attributes(self, data):
if current_user.is_anonymous():
data = self._filter_private_data(data)
return data
if (current_user.is_authenticated and
(current_user.id == data['owner_id'] or current_user.admin)):
return data
else:
data = self._filter_private_data(data)
return data

7 changes: 5 additions & 2 deletions test/test_api/test_project_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,10 @@ def test_project_post(self):

# test update
data = {'name': 'My New Title', 'links': 'hateoas'}
data = dict(name='My New Title', links='hateoas', info=dict(onesignal='new', onesignal_app_id=1))
datajson = json.dumps(data)
## anonymous
res = self.app.put('/api/project/%s' % id_, data=data)
res = self.app.put('/api/project/%s' % id_, data=datajson)
error_msg = 'Anonymous should not be allowed to update'
assert_equal(res.status, '401 UNAUTHORIZED', error_msg)
error = json.loads(res.data)
Expand Down Expand Up @@ -433,6 +434,8 @@ def test_project_post(self):
out = json.loads(res.data)
assert out.get('status') is None, error
assert out.get('id') == id_, error
assert out.get('info')['onesignal_app_id'] == 1, error
assert out.get('info')['onesignal'] == 'new', error

# without hateoas links
del data['links']
Expand Down Expand Up @@ -501,7 +504,7 @@ def test_project_post(self):
assert err['exception_cls'] == 'DBIntegrityError', err

# With not JSON data
datajson = data
datajson = {'foo': 'bar'}
res = self.app.put('/api/project/%s?api_key=%s' % (id_, users[1].api_key),
data=datajson)
err = json.loads(res.data)
Expand Down

0 comments on commit d76347b

Please sign in to comment.