Esempio n. 1
0
 def delete(self):
     """Delete all votes (ADMIN)"""
     if not is_admin():
         vote_ns.abort(
             403,
             'You don\'t have sufficient rights to access this resource')
     delete_all_votes()
     return '', 204
Esempio n. 2
0
 def post(self):
     """Create a new idea for the current user"""
     if is_admin():
         idea_ns.abort(403, 'Admin is not allowed to create ideas')
     json_data = request.get_json(force=True)
     if idea_title_exists(json_data['title']):
         idea_ns.abort(409, "Idea already exists")
     future_idea = save_idea_by_json(json_data, g.current_user)
     return marshal(future_idea.as_dict(), idea), 201, {'Location': '{}/{}'.format(request.url, future_idea.id)}
Esempio n. 3
0
 def delete(self, user_id):
     """Delete the user with the selected user_id (ADMIN)"""
     if not is_admin():
         users_ns.abort(403, 'You don\'t have sufficient rights to access this resource')
     if g.current_user.id == user_id:
         users_ns.abort(403, 'Admin user can not be deleted')
     if get_user_by_id(user_id) is None:
         users_ns.abort(404, 'User not found')
     delete_user_by_id(user_id)
     return '', 204
Esempio n. 4
0
 def put(self, vote_id):
     """Update the vote with the selected vote_id"""
     if is_admin():
         vote_ns.abort(403, 'Admin is not allowed to change votes')
     queried_vote = get_vote_by_id(vote_id)
     if queried_vote is None:
         vote_ns.abort(404, 'Vote not found')
     check_for_vote_ownership(queried_vote)
     json_data = request.get_json(force=True)
     edit_vote(vote_id, json_data['value'])
     return '', 204
Esempio n. 5
0
 def put(self, idea_id):
     """Update the idea with the selected idea_id"""
     if is_admin():
         idea_ns.abort(403, 'Admin is not allowed to modify ideas')
     if not idea_exists(idea_id):
         idea_ns.abort(404, 'Idea not found')
     check_for_idea_ownership(get_idea(idea_id))
     json_data = request.get_json(force=True)
     if idea_title_exists(json_data['title']):
         idea_ns.abort(409, "Idea already exists")
     edit_idea_by_json(idea_id, json_data)
     return '', 204
Esempio n. 6
0
 def post(self):
     """Create a new vote for the current user"""
     if is_admin():
         vote_ns.abort(403, 'Admin is not allowed to vote')
     json_data = request.get_json(force=True)
     idea_id = json_data['target']
     if idea_exists(idea_id) is None:
         vote_ns.abort(409, 'Target not found')
     if vote_exists(g.current_user.id, idea_id):
         vote_ns.abort(409, 'Vote already exists')
     future_vote = Vote(user_id=g.current_user.id,
                        idea_id=idea_id,
                        value=json_data['value'])
     save_vote(future_vote)
     return marshal(future_vote.as_dict(), vote), 201, {
         'Location': '{}/{}'.format(request.url, future_vote.id)
     }
Esempio n. 7
0
 def delete(self):
     """Delete all votes for the current user"""
     if is_admin():
         user_ns.abort(403, 'Admin has no votes')
     delete_votes_for_user(g.current_user.id)
     return '', 204
Esempio n. 8
0
 def get(self):
     """Show all votes for the current user"""
     if is_admin():
         user_ns.abort(403, 'Admin has no votes')
     return marshal(collection_as_dict(g.current_user.votes), vote), 200
Esempio n. 9
0
 def get(self):
     """Show all ideas for the current user"""
     if is_admin():
         user_ns.abort(403, 'Admin has no ideas')
     return marshal(collection_as_dict(g.current_user.ideas), idea), 200
Esempio n. 10
0
 def delete(self):
     """Delete the current user"""
     if is_admin():
         user_ns.abort(403, 'Admin user can not be deleted')
     delete_user_by_id(g.current_user.id)
     return '', 204