1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-30 22:21:13 +03:00

change up a few activity stream and approval drawer issues

This commit is contained in:
Ryan Petrello 2019-08-15 15:52:29 -04:00
parent aac8c9fb04
commit dd89e46ee6
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777
6 changed files with 30 additions and 27 deletions

View File

@ -3441,6 +3441,17 @@ class WorkflowApprovalSerializer(UnifiedJobSerializer):
return res
class WorkflowApprovalActivityStreamSerializer(WorkflowApprovalSerializer):
"""
timed_out and status are usually read-only fields
However, when we generate an activity stream record, we *want* to record
these types of changes. This serializer allows us to do so.
"""
status = serializers.ChoiceField(choices=JobTemplate.JOB_TEMPLATE_STATUS_CHOICES)
timed_out = serializers.BooleanField()
class WorkflowApprovalListSerializer(WorkflowApprovalSerializer, UnifiedJobListSerializer):
class Meta:

View File

@ -681,38 +681,16 @@ class WorkflowApproval(UnifiedJob):
return 'workflow_approval_template'
def approve(self, request=None):
from awx.main.signals import model_serializer_mapping # circular import
self.status = 'successful'
self.save()
self.websocket_emit_status(self.status)
changes = model_to_dict(self, model_serializer_mapping())
changes['status'] = ['pending', 'successful']
activity_entry = ActivityStream(
operation='update',
object1='workflow_approval',
actor=request.user,
changes=json.dumps(changes),
)
activity_entry.save()
getattr(activity_entry, 'workflow_approval').add(self.pk)
schedule_task_manager()
return reverse('api:workflow_approval_approve', kwargs={'pk': self.pk}, request=request)
def deny(self, request=None):
from awx.main.signals import model_serializer_mapping # circular import
self.status = 'failed'
self.save()
self.websocket_emit_status(self.status)
changes = model_to_dict(self, model_serializer_mapping())
changes['status'] = ['pending', 'failed']
activity_entry = ActivityStream(
operation='update',
object1='workflow_approval',
actor=request.user,
changes=json.dumps(changes),
)
activity_entry.save()
getattr(activity_entry, 'workflow_approval').add(self.pk)
schedule_task_manager()
return reverse('api:workflow_approval_deny', kwargs={'pk': self.pk}, request=request)

View File

@ -430,7 +430,7 @@ def model_serializer_mapping():
models.Label: serializers.LabelSerializer,
models.WorkflowJobTemplate: serializers.WorkflowJobTemplateWithSpecSerializer,
models.WorkflowJobTemplateNode: serializers.WorkflowJobTemplateNodeSerializer,
models.WorkflowApproval: serializers.WorkflowApprovalSerializer,
models.WorkflowApproval: serializers.WorkflowApprovalActivityStreamSerializer,
models.WorkflowApprovalTemplate: serializers.WorkflowApprovalTemplateSerializer,
models.WorkflowJob: serializers.WorkflowJobSerializer,
models.OAuth2AccessToken: serializers.OAuth2TokenSerializer,

View File

@ -30,11 +30,19 @@
<div class="at-Row-container">
<at-row-item
header-value="{{ approval.summary_fields.source_workflow_job.name }}"
header-state="workflowResults({id: {{approval.summary_fields.source_workflow_job.id}}})"
header-state="workflowResults({pid: {{approval.summary_fields.source_workflow_job.id}}})"
header-tag="{{:: vm.strings.get('approvals.WORKFLOW_TEMPLATE') }}">
</at-row-item>
</div>
</div>
<div class="at-Row-container--wrapped">
<at-row-item
value-bind-html="<b>Pause Node</b>">
</at-row-item>
<at-row-item
value-bind-html="{{ approval.name }}">
</at-row-item>
</div>
<div class="at-Row-container--wrapped">
<at-row-item
value-bind-html="{{ approval.created | longDate }}">
@ -78,4 +86,4 @@
hide-view-per-page="true">
</paginate>
</div>
</div>
</div>

View File

@ -95,7 +95,7 @@ export default function BuildAnchor($log, $filter) {
break;
case 'workflow_approval':
url += `workflows/${activity.summary_fields.workflow_job[0].id}`;
name = activity.summary_fields.workflow_job[0].name;
name = activity.summary_fields.workflow_job[0].name + ' | ' + activity.summary_fields.workflow_approval[0].name;
break;
default:
url += resource + 's/' + obj.id + '/';

View File

@ -132,7 +132,13 @@ export default function BuildDescription(BuildAnchor, $log, i18n) {
if (activity.changes.status[1] === 'successful') {
operationText = i18n._('approved');
} else if (activity.changes.status[1] === 'failed') {
operationText = i18n._('denied');
if (activity.changes.timed_out && activity.changes.timed_out[1] === true) {
operationText = i18n._('timed out');
} else {
operationText = i18n._('denied');
}
} else {
operationText = i18n._('updated');
}
activity.description = `${operationText} ${activity.object1} ${BuildAnchor(activity.summary_fields[activity.object1][0], activity.object1, activity)}`;
} else {