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 = []
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', []):
place = Place.query.get(place_id)
if not place:
@ -464,7 +465,7 @@ def group_add_places(group_id):
LOG.debug('Place {place_id} owner: {owner}'.format(
place_id=place_id,
owner=place.owner))
if place.owner not in group.users:
if place.owner not in group_users:
rejected.append(place_id)
continue

6
tests/group_tests.py

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

Loading…
Cancel
Save