def refresh(self): label_response = requests.get( f'{COMPUTESERVER}/api/workflows/v1/{self.id}/labels') if label_response.status_code == 404 or label_response.status_code == 400: raise NotFoundException( f'No job with id {self.id} found on jobserver.') label_response.raise_for_status() label_data = label_response.json()['labels'] job_response = requests.get( f'{COMPUTESERVER}/api/workflows/v1/query?id={self.id}') job_data = job_response.json()['results'][0] if len( job_response.json()['results']) else {} job_data.update(label_data) self.owner_id = job_data['owner_id'] if 'owner_id' in job_data else None self.owner = User.query.filter_by(id=job_data['owner_id']).first( ) if 'owner_id' in job_data else None self.user_group = self.owner.primary_user_group if 'owner_id' in job_data else None self.type = job_data['type'] if 'type' in job_data else None self.submission = datetime.strptime( job_data['submission'], '%Y-%m-%dT%H:%M:%S.%fZ') if 'submission' in job_data else None self.start = datetime.strptime( job_data['start'], '%Y-%m-%dT%H:%M:%S.%fZ') if 'start' in job_data else None self.end = datetime.strptime( job_data['end'], '%Y-%m-%dT%H:%M:%S.%fZ') if 'end' in job_data else None self.status = job_data['status'] if 'status' in job_data else None self.active = True
def get_user_password_hash(email: str) -> str: """ Get the password hash for a user based on their email address :param email: :return: """ user = User.query.filter_by(email=email).first() if user is None: raise NotFoundException(f'No user with email {email}.') return user.password
def get_user_by_email(email: str) -> User: """ Get the user record for a user based on their email address :param email: :return: """ user = User.query.filter_by(email=email).first() if user is None: raise NotFoundException(f'No user with email {email}') return user
def get_user_group(user: User, user_group_id: int) -> UserGroup: """ Get a user group. :param user :param user_group_id: :return: """ user_group = UserGroup.query.filter_by(id=user_group_id).first() if user_group is None: raise NotFoundException(f'No user group with id {user_group_id}') if user_group.all_can_read or user in user_group.members: return user_group
def get_collection(user: User, collection_id: int) -> Collection: """ Get the attributes and dataset information of a collection :param user: :param collection_id: :return: """ collection = Collection.query.filter_by(id=collection_id).first() if collection is None: raise NotFoundException(f'No collection with id {collection_id}') if is_read_permitted(user, collection): return collection raise AuthException(f'User {user.email} is not authorized to view collection {collection.id}')
def get_sample_group(user: User, group_id: int) -> SampleGroup: """ Get a sample group. :param user: :param group_id: :return: """ sample_group = SampleGroup.query.filter_by(id=group_id).first() if sample_group is None: raise NotFoundException(f'Sample group with id {group_id} not found.') if is_read_permitted(user, sample_group): return sample_group raise AuthException(f'User {user.email} is not authorized to view sample group {group_id}')
def get_workflow(user: User, workflow_id: int) -> Workflow: """ Get workflow metadata. :param user: :param workflow_id: :return: """ workflow = Workflow.query.filter_by(id=workflow_id).first() if workflow is None: raise NotFoundException(f'No workflow with id {workflow_id}.') if is_read_permitted(user, workflow): return workflow raise AuthException( f'User {user.email} is not permitted to access workflow {workflow_id}')
def get_sample(user: User, sample_id: int) -> Sample: """ Get the attributes and dataset paths of the sample with sample_id :param user: :param sample_id: :return: """ sample = Sample.query.filter_by(id=sample_id).first() if sample is None: raise NotFoundException(f'No sample with id {sample_id}') if is_read_permitted(user, sample): return sample raise AuthException( f'User {user.email} is not permitted to access sample {sample_id}')
def get_user(user: User, target_user_id: int) -> User: """ Get the record for one user :param user: :param target_user_id: :return: """ target_user = User.query.filter_by(id=target_user_id).first() if target_user is None: raise NotFoundException(f'No user with id {target_user_id}.') if is_read_permitted(user, target_user): return target_user raise AuthException( f'User with id {target_user_id} does not exist or is not visible to {user.email}' )
def get_external_file(user: User, external_file_id: int) -> ExternalFile: """ Get a record corresponding to an external file :param user: :param external_file_id: :return: """ external_file = ExternalFile.query.filter_by(id=external_file_id).first() if external_file is None: raise NotFoundException(f'No external file with id {external_file_id}') if is_read_permitted(user, external_file): return external_file raise AuthException( f'User {user.id} is not authorized to view external file {external_file.id}' )
def get_external_file_by_path(user: User, filename: str) -> ExternalFile: """ Get the external file record for the file with path filename :param user: :param filename: :return: """ external_file = ExternalFile.query.filter_by(filename=filename).first() if external_file is None: raise NotFoundException( f'No external file record exists for {filename}') if is_read_permitted(user, external_file): return external_file raise AuthException( f'User {user.id} is not authorized to view external file record for {filename}' )
def render_submit_job(): try: if request.args.get('workflow_id') is None: raise NotFoundException(f'No workflow id provided') current_user = get_current_user() workflow = get_workflow(current_user, request.args.get('workflow_id')) workflow_data = workflow.get_file_info() if request.method == 'POST': job_params, workflow_data, labels, options = prepare_job_params(workflow_data, process_input_dict(request.form), current_user, workflow.id) job = start_job(workflow_data, job_params, current_user, 'analysis', labels, options) return redirect(url_for('jobs.render_job', job_id=job.id)) page_data = SubmitFormData(current_user, workflow_data, f'Workflow {workflow.id}') return render_template('pages/submit_job.html', page_data=page_data) except Exception as e: return handle_exception_browser(e)