sharingan-no-kakashi commented on a change in pull request #16953:
URL: https://github.com/apache/airflow/pull/16953#discussion_r669922136
##########
File path: airflow/www/views.py
##########
@@ -1354,6 +1356,82 @@ def xcom(self, session=None):
title=title,
)
+ @expose('/task_note', methods=['POST', 'GET'])
+ @auth.has_access(
+ [
+ (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
+ (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
+ (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_NOTE),
+ ]
+ )
+ @action_logging
+ @provide_session
+ def task_note(self, session=None):
+ """Retrieve and store task notes"""
+ dag_id = request.args.get('dag_id')
+ task_id = request.args.get('task_id')
+ execution_date = request.args.get('execution_date')
+ dttm = timezone.parse(execution_date)
+ form = DateTimeForm(data={'execution_date': dttm})
+ root = request.args.get('root', '')
+ dm_db = models.DagModel
+ ti_db = models.TaskInstance
+ request_note = request.values.get('note')
+ default_user = "Anonymous"
+ title = "Notes"
+
+ dag = session.query(dm_db).filter(dm_db.dag_id == dag_id).first()
+
+ ti = (
+ session.query(ti_db)
+ .filter(and_(ti_db.dag_id == dag_id, ti_db.task_id == task_id,
ti_db.execution_date == dttm))
+ .first()
+ )
+
+ if not ti:
+ flash(f"Task [{dag_id}.{task_id}.{execution_date}] doesn't seem to
exist at the moment", "error")
+ return redirect(url_for('Airflow.index'))
+
+ can_add_note = current_app.appbuilder.sm.has_access(
+ permissions.ACTION_CAN_CREATE, permissions.RESOURCE_TASK_NOTE
+ )
+
+ if request.method == 'GET':
+ notes = (
+ TaskNote.get_many(dag_ids=dag_id, task_ids=task_id,
execution_date=dttm)
+ .order_by(TaskNote.timestamp.asc())
+ .all()
+ )
+
+ attributes = [(note.task_note, note.timestamp, note.user_name) for
note in notes]
+
+ return self.render_template(
+ 'airflow/task_notes.html',
+ attributes=attributes,
+ task_id=task_id,
+ execution_date=execution_date,
+ form=form,
+ can_add_note=can_add_note,
+ root=root,
+ dag=dag,
+ title=title,
+ )
+
+ if request.method == 'POST':
+ if not can_add_note:
+ flash("Current user cannot add notes")
+ else:
+ TaskNote.set(
Review comment:
true, I'll take care
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]