def get(self, id): current_user_id = get_jwt_identity() project = ProjectModel.find_by_id(id) if not project: return {"message": "project not found"}, 404 if project.is_archived == True: return {"message": "project already archived"} if project.user_id != current_user_id: return {"message": "Unauthorized"}, 401 # tasks = Comment.query.filter_by(thread_id=thread.id)\ # .order_by(Comment.created_at.desc())\ # .all() tasks = TaskModel.query.filter(TaskModel.project_id==id)\ .all() print(tasks) # current_user_id = get_jwt_identity() # if current_user_id: # tasks = [x.json() for x in TaskModel.query.filter(TaskModel.user_id==current_user_id).all()] # # task_termined = [r._asdict() for r in tasks] for row in tasks: print(row) return {"message": "project_task_termined"}, 200
def put(self, id): current_user_id = get_jwt_identity() project = ProjectModel.find_by_id(id) if not project: return {"message": "project not found"}, 404 if current_user_id != project.user_id: return {"message": "Unauthorized"}, 401 data = Project.parser.parse_args() project_name = data["project_name"] if not project_name: project_name = project.project_name description = data['description'] if not description: description = project.description try: project.project_name = project_name project.description = description project.save_to_db() except: return {"message": "An error occured updating the Project"}, 500 project_id = project.id project_name = project.project_name description = project.description is_archived = project.is_archived return { "project_id": project_id, "project_name": project_name, "description": description, "is_archived": is_archived }, 201
def delete(self, name): # user id,project id,task_name parse = reqparse.RequestParser() parse.add_argument('uuid', type=non_empty_string, required=True, help='uuid Required..') data = parse.parse_args() project = ProjectModel.find_by_id(data['uuid']) if project: task = TaskModel.query.filter( and_(TaskModel.uuid == data['uuid'], TaskModel.task_name == name)).first() if task: if project.created_by_id == get_jwt_identity(): # owner task.delete_from_db() return {"Message": "Task Deleted", "status": 200} else: collaborator = ShareProjectModel.query.filter( and_( ShareProjectModel.share_with_id == get_jwt_identity(), ShareProjectModel.uuid == project.uuid)).first() if collaborator: if collaborator.permission == 'Delete': # share with permission to delete task.delete_from_db() return {"Message": "Task Deleted", "status": 200} return { "UnauthorizedError": { "message": "You don't have permission to Delete Task.", "status": 401 } } return { "CollaboratorNotExistsError": { "message": "User with given id is not a part of this project or not owner", "status": 400 } } return { "TaskNotExistsError": { "message": "Task with given name doesn't exists", "status": 400 } } return { "ProjectNotExistsError": { "message": "Project with given id doesn't exists", "status": 400 } }
def get(self, project_id, id): if len(ProjectModel.find_by_id(project_id)) == 0: return {'message': 'Project not found'}, 404 executions = ExecutionModel.find_by_id_and_project_id(id, project_id) if executions: return {'execution': executions[0].json()} return {'message': 'Execution not found'}, 404
def get(self, id): current_user_id = get_jwt_identity() project = ProjectModel.find_by_id(id) if not project: return {"message": "project not found"}, 404 if project.user_id != current_user_id: return {"message": "Unauthorized"}, 401 number_tasks = (db.session.query( func.count(TaskModel.id).label('total_task')).join( ProjectModel, TaskModel.project_id == ProjectModel.id).filter( TaskModel.project_id == project.id).filter( TaskModel.user_id == current_user_id).scalar()) number_tasks_termined = (db.session.query( func.count(TaskModel.id).label('total_task_temined')).filter( TaskModel.project_id == project.id).filter( TaskModel.status == False).filter( TaskModel.user_id == current_user_id).scalar()) if number_tasks == 0: return {"message": "Not task"} percentage = number_tasks_termined * 100 / number_tasks return { "number_tasks": number_tasks, "number_tasks_termined": number_tasks_termined, "percentage": percentage }, 200
def post(self, name): data = Task.parse.parse_args() project = ProjectModel.query.filter_by(uuid=data['uuid']).first() if project: if project.created_by_id == get_jwt_identity(): # owner if TaskModel.find_by_name(name): return { "TaskAlreadyExistsError": { "message": "Task with given name alredy exists.", "status": 401 } } task = TaskModel(name, data['task_desc'], data["uuid"]) task.save_to_db() project = ProjectModel.find_by_id(data['uuid']) project.task_id = task project.save_to_db() return {"Message": "Task Added...", "status": 200} else: return { "UnauthorizedError": { "message": "Project Owner can only create task.", "status": 401 } } return { "ProjectNotExistsError": { "message": "Project with given id doesn't exists", "status": 400 } }
def put(self, id): data = Project.parser.parse_args() project = ProjectModel.find_by_id(id) if project: project.name = data['name'] else: project = ProjectModel(None, **data) project.save_to_db() return project.json()
def test_find_by_id(self): with self.app_context: self.role_1.save_to_db() self.member_1.save_to_db() poject_id = self.project_1.save_to_db().id project = ProjectModel.find_by_id(poject_id) self.assertEqual(project.title, "REST API para sitio web")
def get(self, project_id): if len(ProjectModel.find_by_id(project_id)) == 0: return {'message': 'Project not found'}, 404 return { 'executions': list( map(lambda x: x.json(), ExecutionModel.find_executions_by_project_id(project_id))) }
def get(self, project_id, id): data = ExecutionOutput.parser.parse_args() if len(ProjectModel.find_by_id(project_id)) == 0: return {'message': 'Project not found'}, 404 exec_output = ExecutionModel.get_output(id, project_id, data['first_requested_byte'], data['last_requested_byte']) if exec_output: return {'output': exec_output.json()} return {'message': 'Execution not found'}, 404
def delete(self, id): current_user_id = get_jwt_identity() project = ProjectModel.find_by_id(id) if not project: return {"message": "project not found"}, 404 if project.user_id != current_user_id: return {"message": "Unauthorized"}, 401 project.delete_from_db() return {"message": "Project deleted"}, 200
def delete(self, id): project = ProjectModel.find_by_id(id) if project: if current_identity.id == project.user_id: project.delete_from_db() return {'message': 'Project deleted'} else: return { 'message': 'Sorry, this project was not created by you.' } else: return {'message': 'Sorry, this project was not found.'}
def get(self): # remaining task -> join user & project projects = [ project.json() for project in ProjectModel.query.filter_by( created_by_id=get_jwt_identity()).all() ] share = [ project.uuid for project in ShareProjectModel.query.filter_by( share_with_id=get_jwt_identity()).all() ] Sharing_Projects = [ ProjectModel.find_by_id(uuid).json() for uuid in share if ProjectModel.find_by_id(uuid) != None ] return { "Created Projects": projects, "Sharing_Projects": Sharing_Projects, "status": 200 }
def test_projects_members_relation(self): with self.app_context: self.role_1.save_to_db() self.member_1.save_to_db() project_id = self.project_1.save_to_db().id member_id = self.member_1.save_to_db().id project = ProjectModel.find_by_id(project_id) member = MemberModel.find_by_id(member_id) project.members.append(member) self.assertEqual(project.members[0].email, "*****@*****.**")
def put(self, id): current_user_id = get_jwt_identity() task = TaskModel.find_by_id(id) if not task: return {"message": "task not found"}, 404 if current_user_id != task.user_id: return {"message": "Unauthorized"}, 401 data = Task.parser.parse_args() task_name = data['task_name'] if not task_name: task_name = task.task_name project_id = task.project_id project = ProjectModel.find_by_id(project_id) if not project: return {"message": "project not found"}, 404 if project.is_archived: return {"message": "Close Unauthorized"}, 401 is_open = data['is_open'] print(is_open) if is_open: task.is_open = is_open # is_open = task.is_open try: task.task_name = task_name task.is_open = is_open task.save_to_db() except: return {"message": "An error occured creating the Project"}, 500 project_id = task.project_id is_open = task.is_open task_name = task.task_name return { "project_id": project_id, "task_name": task_name, "is_open": is_open }, 201
def put(self, id): data = Project.parser.parse_args() project = ProjectModel.find_by_id(id) if project: if current_identity.id == project.user_id: project.name = data['name'] project.save_to_db() return project.json() else: return { 'message': 'Sorry, this project was not created by you.' } else: return {'message': 'Project not found'}, 404
def get_project(project_id: int) -> ApiResponse: project = ProjectModel.find_by_id(project_id) if not project: abort( 404, description=ERROR_404.format("Project", "id", project_id), ) return ( jsonify({ "project": project_schema.dump(project), }), 200, )
def post(self, project_id): if not ProjectModel.find_by_id(project_id): return { 'message': "A project with id '{}' does not exist.".format(project_id) }, 404 # Create a new execution execution = ExecutionModel(project_id=project_id) try: execution.exec() except Exception as e: logging.error(repr(e)) return {"message": "An error occurred running the item."}, 500 return {'execution': execution.json()}, 201
def post(self, project_id): projects = ProjectModel.find_by_id(project_id) if not projects: return { 'message': "A project with id '{}' does not exist.".format(project_id) }, 404 data = NewEnvironment.parser.parse_args() # Check if it is the owner project_maps = UserProjectMap.find_user_id_by_project_id(project_id) if get_jwt_identity() != project_maps[0].user_id: return {'message': "You must be the owner of the project"}, 403 # Check if the environment already exists if ProjectEnvironmentMap.find_environment_id_by_project_and_name( project_id, data['name']): return { 'message': "A variable with this name for this project already esists" }, 400 # Create a new environment env = EnvironmentModel(name=data['name'], id=None, value=data.get('value', None), description=data.get('description', None)) try: env.save_to_db() except Exception as e: logging.error(e) return {"message": "An error occurred inserting the env."}, 500 # Map the env to the project mapping_project = ProjectEnvironmentMap(name=data['name'], project_id=projects[0].id, environment_id=env.id) try: mapping_project.save_to_db() except: logging.error(sys.exc_info()) env.delete_from_db() return { "message": "An error occurred mapping the environment to the project." }, 500 return {'environment': env.json()}, 201
def get(self, project_id): if len(ProjectModel.find_by_id(project_id)) == 0: return {'message': 'Project not found'}, 404 # Check if it is the owner project_map = UserProjectMap.find_user_id_by_project_id(project_id) if get_jwt_identity() != project_map[0].user_id: return {'message': "You must be the owner of the project"}, 403 return { 'environments': list( map( lambda x: x.json(), ProjectEnvironmentMap.get_environments_by_project_id( project_id))) }
def post(self): data = Task.parser.parse_args() current_user_id = get_jwt_identity() task_name = data["task_name"] if not task_name: return {"message": "Please enter the name of task 'task_name' "} is_open = data["is_open"] project_id = data["project_id"] if not project_id: return {"message": "Please enter the id of project 'project_id' "} project = ProjectModel.find_by_id(project_id) if not project: return {"message": "project not found"}, 404 if current_user_id != project.user_id: return {"message": "Unauthorized"}, 401 if project.is_archived == True: return {"message": "Project Closed"}, 401 task = TaskModel(**data) task.user_id = get_jwt_identity() task.save_to_db() # try: # task = TaskModel(**data) # task.user_id = get_jwt_identity() # task.save_to_db() # except: # return {"message": "An error occured creating the Task"}, 500 task_id = task.id task_name = task.task_name is_open = task.is_open return { "task_id": task_id, "task_name": task_name, "is_open": is_open }, 201
def get(self, id): current_user_id = get_jwt_identity() project = ProjectModel.find_by_id(id) if not project: return {"message": "project not found"}, 404 if project.is_archived == True: return {"message": "project already archived"} if project.user_id != current_user_id: return {"message": "Unauthorized"}, 401 project.is_archived = True project.save_to_db() return {"message": "Project Archived"}, 200
def delete_project(project_id: int) -> ApiResponse: project = ProjectModel.find_by_id(project_id) if not project: abort( 404, description=ERROR_404.format("Project", "id", project_id), ) project.delete_from_db() return ( jsonify({ "message": DELETED.format("project"), "project": project_schema.dump(project), }), 200, )
def get(self, id): project = ProjectModel.find_by_id(id) current_user_id = get_jwt_identity() if not project: return {"message": "project not found"}, 404 if current_user_id == project.user_id: project_id = project.id preject_name = project.project_name description = project.description is_archived = project.is_archived return { "project_id": project_id, "project_name": preject_name, "description": description, "is_archived": is_archived }, 200 return {"message": "Unauthorized"}, 401
def post(self): data = Todos.parser.parse_args() todo = TodoModel(desc=data['desc'], done='false', project_id=data['project_id'], user_id=data['user_id']) if (ProjectModel.find_by_id(todo.project_id)): if (UserModel.find_by_id(todo.user_id)): try: todo.save_to_db() return todo.json(), 201 except: return { "message": "An error occurred inserting the todo." }, 500 else: return {"message": "The associated user does not exist."}, 500 else: return {"message": "The associated project does not exist."}, 500
def put_project(project_id: int) -> ApiResponse: project = ProjectModel.find_by_id(project_id) if not project: abort( 404, description=ERROR_404.format("Project", "id", project_id), ) project_json = request.get_json() project_by_title = ProjectModel.find_by_title(project_json.get("title")) if project_by_title and project_by_title.id != project_id: abort( 409, description=ERROR_409.format( "Project", "title", project_json.get("title"), ), ) project.start_date = project_json.get("start_date") project.end_date = project_json.get("end_date") project.title = project_json.get("title") project.description = project_json.get("description") project.goals = project_json.get("goals") project.status = project_json.get("status") project.admin_id = project_json.get("admin_id") project.save_to_db() return ( jsonify({ "message": MODIFIED.format("Project"), "project": project_schema.dump(project), }), 200, )
def get(self, project_id): if len(ProjectModel.find_by_id(project_id)) == 0: return {'message': 'Project not found'}, 404 return {'settings': list(map(lambda x: x.json(), ProjectSettingMap.get_settings_by_project_id(project_id)))}
def delete(self, id): project = ProjectModel.find_by_id(id) if project: project.delete_from_db() return {'message': 'Item deleted.'} return {'message': 'Item not found.'}, 404
def get(self, id): project = ProjectModel.find_by_id(id) if project: return {'project': project[0].json()} return {'message': 'Item not found'}, 404
def get(self, id): project = ProjectModel.find_by_id(id) if project: return project.json() return {'message': 'Project not found'}, 404