def handle_submission_transaction(program, project, *doc_args, **tx_kwargs): """ Create and execute a single (not bulk) transaction. Return: Tuple[flask.Response, int]: (API response json, status code) """ is_async = tx_kwargs.pop("is_async", utils.is_flag_set(FLAG_IS_ASYNC)) db_driver = tx_kwargs.pop("db_driver", flask.current_app.db) smtp_conf = None if utils.should_send_email(flask.current_app.config): smtp_conf = flask.current_app.get_smtp_conf() transaction = SubmissionTransaction(smtp_conf=smtp_conf, program=program, project=project, logger=flask.current_app.logger, signpost=flask.current_app.signpost, db_driver=db_driver, **tx_kwargs) if is_async: session = transaction.db_driver.session_scope() with session, transaction: response = { "code": 200, "message": "Transaction submitted.", "transaction_id": transaction.transaction_id, } flask.current_app.async_pool.schedule(transaction_worker, transaction) return flask.jsonify(response), 200 else: response, code = transaction_worker(transaction) return flask.jsonify(response), code
def __init__(self, smtp_conf=None, **kwargs): super(SubmissionTransaction, self).__init__(role='submit', **kwargs) self.app_config = capp.config if utils.should_send_email(self.app_config): self.smtp_conf = smtp_conf if ROLE_SUBMIT not in self.user.roles.get(self.project_id, []): self.record_error( 'You do not have submit permission for project {}' .format(self.project_id), type=EntityErrors.INVALID_PERMISSIONS) return self.project_node = utils.lookup_project( self.db_driver, self.program, self.project)
def __init__(self, smtp_conf=None, **kwargs): super(SubmissionTransaction, self).__init__(role="submit", **kwargs) self.app_config = capp.config if utils.should_send_email(self.app_config): self.smtp_conf = smtp_conf try: program, project = self.transaction.project_id.split("-", 1) authorize(program, project, [ROLE_SUBMIT]) except AuthZError: return self.record_error( "You do not have submit permission for project {}".format( self.project_id), type=EntityErrors.INVALID_PERMISSIONS, ) self.project_node = utils.lookup_project(self.db_driver, self.program, self.project)
def take_action(self): """ For the current project, attempt to transition all nodes from their current states to ``submitted``. """ self.assert_project_state() nodes = self.lookup_submittable_nodes() self.entities = [SubmissionEntity(self, n) for n in nodes] for entity in self.entities: entity.submit() project_node = self.session.merge(self.project_node) project_node.state = "submitted" project_node.releasable = True if self.success and utils.should_send_email(self.app_config): self.send_submission_notification_email() self.commit()
def __init__(self, smtp_conf=None, **kwargs): super(SubmissionTransaction, self).__init__(role="submit", **kwargs) self.app_config = capp.config if utils.should_send_email(self.app_config): self.smtp_conf = smtp_conf roles = get_program_project_roles(*self.project_id.split("-", 1)) if ROLE_SUBMIT not in roles: self.record_error( "You do not have submit permission for project {}".format( self.project_id ), type=EntityErrors.INVALID_PERMISSIONS, ) return self.project_node = utils.lookup_project( self.db_driver, self.program, self.project )