Skip to content

Commit 080badf

Browse files
committed
Add workflow export functionality to the REST API
1 parent 5dbac68 commit 080badf

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

CHANGELOG.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [current]
9+
### Added
10+
- Workflow export functionality via the REST API (so workflows can be imported later).
11+
912
### Changed
10-
- Replace agent type dropdown with card based selector.
13+
- UI: replace agent type dropdown with card-based selector.
1114

1215
### Removed
1316
Removed third party agents:
@@ -28,7 +31,7 @@ Removed third party agents:
2831
- Human task agent (mechanical turk).
2932

3033
### Fixed
31-
- Support official image on rootles docker (or podman).
34+
- Support official image on rootless docker (or podman).
3235

3336

3437
## [0.9.12] - 2020-11-23
@@ -42,7 +45,7 @@ Removed third party agents:
4245
to install on MacOS.
4346
- Updated `puma` - MacOS related [issue](https://github.com/puma/puma/issues/2304).
4447
- Renamed `headers_to_save` to `headers_to_include` in HTTP Status Agent.
45-
- Replace `working` with `issues` and add desctiptions.
48+
- Replace `working` with `issues` and add descriptions.
4649
- Update `bundler` to 2.1.4.
4750
- Numerous UI improvements.
4851

@@ -56,7 +59,7 @@ Removed third party agents:
5659
job control functionality of bash. Fixes #9.
5760

5861
### Changed
59-
- Both docker-compose and deployment to heroku (via single button deployment)
62+
- Both docker-compose and deployment to Heroku (via single button deployment)
6063
switched to using official docker images of ActiveWorkflow by default instead
6164
of building images from source - mostly to save time spent building docker
6265
image every single time. Of course, you can still build your own images from
@@ -185,7 +188,7 @@ Removed third party agents:
185188

186189
## [0.9.2] - 2019-08-07
187190
### Fixed
188-
- Docker compose doesn't restart container anymore.
191+
- Docker compose doesn't restart container any more.
189192
- Updated dependencies.
190193

191194

app/api/api/v1/root.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ class Root < Grape::API
5656
workflow = current_user.workflows.find(params[:workflow_id])
5757
present workflow, with: API::V1::Entities::Workflow, with_agents: true
5858
end
59+
60+
get ':workflow_id/export' do
61+
workflow = current_user.workflows.find(params[:workflow_id])
62+
exporter = AgentsExporter.new(name: workflow.name,
63+
description: workflow.description,
64+
guid: workflow.guid,
65+
tag_fg_color: workflow.tag_fg_color,
66+
tag_bg_color: workflow.tag_bg_color,
67+
icon: workflow.icon,
68+
agents: workflow.agents)
69+
header 'Content-Disposition', 'attachment; filename="' + exporter.filename + '"'
70+
exporter.as_json
71+
end
5972
end
6073
end
6174
end

app/views/devise/registrations/edit.html.erb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
<div class="container">
44
<div class="row">
5+
<p>If you want to access ActiveWorkflow via the REST API the token for your user is:
6+
<pre><code class="text-info"><%= JsonWebToken.encode(user_id: current_user.id) %></code></pre>
7+
</p>
8+
59
<div class="col-md-6">
610

711
<h2>Edit <%= resource_name.to_s.humanize %></h2>
8-
912
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, class: 'form-horizontal' }) do |f| %>
1013
<%= render 'devise/shared/error_messages', resource: resource %>
1114

spec/requests/api/v1/root_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,22 @@
123123
))
124124
end
125125
end
126+
127+
context '/api/v1/workflows/:workflow_id/export' do
128+
let(:workflow) { workflows(:bob_status) }
129+
130+
it 'returns full workflow as json' do
131+
get "/api/v1/workflows/#{workflow.id}/export", headers: headers
132+
result = JSON.parse(response.body)
133+
expect(result['name']).to eq workflow.name
134+
expect(result['agents'])
135+
.to include(include('type' => 'Agents::HttpStatusAgent'))
136+
end
137+
138+
it 'sets content-disposition header (filename)' do
139+
get "/api/v1/workflows/#{workflow.id}/export", headers: headers
140+
expect(response.headers['Content-Disposition'])
141+
.to eq 'attachment; filename="bob-s-status-alert-workflow.json"'
142+
end
143+
end
126144
end

0 commit comments

Comments
 (0)