-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathworkflows_controller.rb
More file actions
127 lines (109 loc) · 3.69 KB
/
Copy pathworkflows_controller.rb
File metadata and controls
127 lines (109 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# The controller for actions related to the Workflows model
class WorkflowsController < ApplicationController
before_action :ensure_feature_enabled
layout 'application'
before_action :set_workflow, only: [:show, :edit, :update, :destroy, :fork, :embed]
before_action :set_breadcrumbs
after_action :allow_embedding, only: [:embed]
include SearchableIndex
# GET /workflows
# GET /workflows.json
def index
respond_to do |format|
format.html
format.json
format.json_api { render({ json: @workflows }.merge(api_collection_properties)) }
end
end
# GET /workflows/1
# GET /workflows/1.json
def show
authorize @workflow
respond_to do |format|
format.html { render layout: 'workflows' }
format.json
format.json_api { render json: @workflow }
end
end
# GET /workflows/new
def new
authorize Workflow
@workflow = Workflow.new
render layout: 'workflows'
end
# GET /workflows/1/edit
def edit
authorize @workflow
render layout: 'workflows'
end
# POST /workflows
# POST /workflows.json
def create
authorize Workflow
@workflow = Workflow.new(workflow_params)
@workflow.user = current_user
@workflow.space = current_space
respond_to do |format|
if @workflow.save
@workflow.create_activity :create, owner: current_user
format.html { redirect_to @workflow, notice: 'Workflow was successfully created.' }
format.json { render :show, status: :created, location: @workflow }
else
format.html { render :new }
format.json { render json: @workflow.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /workflows/1
# PATCH/PUT /workflows/1.json
def update
authorize @workflow
respond_to do |format|
if @workflow.update(workflow_params)
@workflow.create_activity(:update, owner: current_user) if @workflow.log_update_activity?
format.html { redirect_to @workflow, notice: 'Workflow was successfully updated.' }
format.json { render :show, status: :ok, location: @workflow }
else
format.html { render :edit }
format.json { render json: @workflow.errors, status: :unprocessable_entity }
end
end
end
# DELETE /workflows/1
# DELETE /workflows/1.json
def destroy
authorize @workflow
@workflow.create_activity :destroy, owner: current_user
@workflow.destroy
respond_to do |format|
format.html { redirect_to workflows_path, notice: 'Workflow was successfully destroyed.' }
format.json { head :no_content }
end
end
def fork
@workflow = @workflow.new_fork(current_user)
respond_to do |format|
format.html { render :new }
end
end
def embed
authorize @workflow, :show?
render layout: 'embed'
end
private
# Use callbacks to share common setup or constraints between actions.
def set_workflow
@workflow = Workflow.friendly.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def workflow_params
params.require(:workflow).permit(:title, :description, :user_id, :workflow_content, :doi,
:remote_created_date, :remote_updated_date, { keywords: [] },
{ scientific_topic_names: [] }, { scientific_topic_uris: [] }, :licence,
:difficulty_level, { target_audience: [] },
:hide_child_nodes, :public,
{ authors: [:name, :orcid] }, { contributors: [:name, :orcid] }, # Structured
{ authors: [] }, { contributors: [] } # as strings
)
end
end