def setUp(self): session = Session() # make sure NOT to run in UTC. Only postgres supports storing # timezone information in the datetime field if session.bind.dialect.name == "postgresql": session.execute("SET timezone='Europe/Amsterdam'") self.session = session
def get_filter_by_user_dagids_detail(): res=get_filter_by_user() curr_user = airflow.login.current_user session = Session() dags=[] if res : result = session.execute(""" SELECT dag_name FROM dcmp_dag WHERE last_editor_user_id IN ( select user_id from dcmp_user_profile where user_id = %s ) """ % curr_user.user.id ) if result.rowcount > 0: records = result.fetchall() session.close() for x in records: dags.append(x.dag_name) return dags
def get_filter_by_user_dagid(dagid): res=get_filter_by_user() curr_user = airflow.login.current_user session = Session() if res : result = session.execute(""" SELECT dag_name FROM dcmp_dag WHERE last_editor_user_id = %s """ % curr_user.user.id ) if result.rowcount > 0: records = result.fetchall() dags=[] for x in records: dags.append(x.dag_name) return ( dagid in dags ) # dagid 是否为用为的dagid else: return False session.close() else: # 无限制 return True
def get_filter_by_user(): FILTER_BY_OWNER = False curr_user = airflow.login.current_user if configuration.getboolean('webserver', 'FILTER_BY_OWNER'): # filter_by_owner if authentication is enabled and filter_by_owner is true FILTER_BY_OWNER = True do_filter = FILTER_BY_OWNER and (not curr_user.is_superuser() ) owner_mode = configuration.get('webserver', 'OWNER_MODE').strip().lower() session = Session() # dcmp插件是否存在 dcmp_flag = False try: res = session.execute(""" SELECT dag_name FROM dcmp_dag WHERE last_editor_user_id IN ( select user_id from dcmp_user_profile ) """ ) dcmp_flag = True except Exception, e: dcmp_flag = False