def get(self, project_id): try: user_id = get_jwt_identity() user = find_by_user_id(user_id) project = find_by_project_id(project_id) if user_id == project['admin_id']: response = { 'success': False, 'msg': 'Cannot leave own project', } return make_response(jsonify(response)), 401 team_ids = get_teams_of_user_in_project(user['id'], project_id) for id in team_ids: delete_by_user_id_team_id(user['id'], id) project_members = count_users_in_team(id) if project_members == 0: delete_team(id) response = { 'success': True, 'msg': 'Project left', } return make_response(jsonify(response)), 200 except Exception as err: print(err) response = { 'success': False, 'msg': 'Something went wrong', } return make_response(jsonify(response)), 500
def post(self, project_id): """ Handle POST request for this view. Url --> /api/v1/project/remove_project_member/<int:project_id> """ # getting JSON data from request post_data = request.get_json(silent=True, force=True) current_user = get_jwt_identity() roles = get_user_roles(current_user, project_id) if "admin" not in roles: print("Error occured: user not admin") response = {"success": False, "msg": "User not admin."} return make_response(jsonify(response)), 403 try: user_email = post_data["member_email"] except KeyError as err: response = { "success": False, "msg": f'{str(err)} key is not present' } return make_response(jsonify(response)), 400 try: user_obj = find_by_email(user_email) user = to_json(user_obj) if not user: response = {"success": False, "msg": "User not found."} return make_response(jsonify(response)), 404 try: team_ids = get_teams_of_user_in_project(user['id'], project_id) for id in team_ids: delete_by_user_id_team_id(user['id'], id) project_members = count_users_in_team(id) if project_members == 0: delete_team(id) response = {"success": True, "msg": "ProjectMember deleted."} return make_response(jsonify(response)), 200 except Exception: response = { "success": False, "msg": "Could not delete projectmember from all teams" } return make_response(jsonify(response)), 500 except Exception: response = {"success": False, "msg": "Something went wrong!!"} return make_response(jsonify(response)), 500
def delete(self, project_id, team_id): """Handle DELETE request for this view. Url --> /api/v1/team/team_info/<int:project_id>/<int:team_id>""" try: if not team_id: response = {"success": False, "msg": "Team id is missing"} return make_response(jsonify(response)), 400 delete_team(team_id) response = {"success": True, "msg": "Team deleted."} return make_response(jsonify(response)), 200 except Exception: response = {"success": False, "msg": "Something went wrong."} return make_response(jsonify(response)), 500
def delete(self, project_id, team_id): """Handle DELETE request for this view. Url --> /api/v1/team/team_info/<int:project_id>/<int:team_id>""" current_user = get_jwt_identity() roles = get_user_roles(current_user, project_id) if "admin" not in roles: print("Error occured: user not admin") response = {"success": False, "msg": "User not admin."} return make_response(jsonify(response)), 403 try: if not team_id: response = {"success": False, "msg": "Team id is missing"} return make_response(jsonify(response)), 400 delete_team(team_id) response = {"success": True, "msg": "Team deleted."} return make_response(jsonify(response)), 200 except Exception: response = {"success": False, "msg": "Something went wrong."} return make_response(jsonify(response)), 500
def post(self, project_id, team_id): """ Handle POST request for this view. Url --> /api/v1/team/remove_team_member/<int:project_id>/<int:team_id> """ # getting JSON data from request post_data = request.get_json(silent=True, force=True) try: user_email = post_data["member_email"] except KeyError as err: response = { "success": False, "msg": f'{str(err)} key is not present' } return make_response(jsonify(response)), 400 try: user_obj = find_by_email(user_email) user = to_json(user_obj) if not user: response = {"success": False, "msg": "User not found."} return make_response(jsonify(response)), 404 try: delete_by_user_id_team_id(user['id'], team_id) project_members = count_users_in_team(team_id) if project_members == 0: delete_team(team_id) response = {"success": True, "msg": "Team member deleted."} return make_response(jsonify(response)), 200 except Exception: response = { "success": False, "msg": "Could not delete projectmember from all teams" } return make_response(jsonify(response)), 500 except Exception: response = {"success": False, "msg": "Something went wrong!"} return make_response(jsonify(response)), 500