Browse Source

cannot add non-members places to the group

master
Julio Biason 11 years ago
parent
commit
21551c8ccf
  1. 5
      luncho/blueprints/groups.py
  2. 6
      tests/group_tests.py

5
luncho/blueprints/groups.py

@ -454,7 +454,8 @@ def group_add_places(group_id):
not_found = [] not_found = []
rejected = [] rejected = []
LOG.debug('Users in the group: {users}'.format(users=group.users)) group_users = [user.username for user in group.users]
LOG.debug('Users in the group: {users}'.format(users=group_users))
for place_id in request.as_json.get('places', []): for place_id in request.as_json.get('places', []):
place = Place.query.get(place_id) place = Place.query.get(place_id)
if not place: if not place:
@ -464,7 +465,7 @@ def group_add_places(group_id):
LOG.debug('Place {place_id} owner: {owner}'.format( LOG.debug('Place {place_id} owner: {owner}'.format(
place_id=place_id, place_id=place_id,
owner=place.owner)) owner=place.owner))
if place.owner not in group.users: if place.owner not in group_users:
rejected.append(place_id) rejected.append(place_id)
continue continue

6
tests/group_tests.py

@ -426,7 +426,7 @@ class TestPlacesInGroup(LunchoTests):
user = self.user user = self.user
place = Place(name='Place', place = Place(name='Place',
owner=self.user) owner=user)
server.db.session.add(place) server.db.session.add(place)
server.db.session.commit() server.db.session.commit()
return place return place
@ -470,6 +470,7 @@ class TestPlacesInGroup(LunchoTests):
verified=True) verified=True)
group = self._group() # group belongs to self.user group = self._group() # group belongs to self.user
place = self._place(new_user) # place belongs to new_user place = self._place(new_user) # place belongs to new_user
place_id = place.id
request = {'places': [place.id]} request = {'places': [place.id]}
group_id = group.id group_id = group.id
@ -477,6 +478,9 @@ class TestPlacesInGroup(LunchoTests):
request, request,
token=self.user.token) token=self.user.token)
self.assertJsonOk(rv) self.assertJsonOk(rv)
json = loads(rv.data)
self.assertTrue('rejected' in json)
self.assertTrue(place_id in json['rejected'])
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

Loading…
Cancel
Save