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
|
# File 'lib/active_versioning/workflow/controller.rb', line 4
def self.included(dsl)
dsl.instance_eval do
member_action :commit, method: :put do
if resource.commit(commit_params)
set_resource_ivar(resource.class.find(resource.id))
redirect_to resource_path, notice: I18n.t('active_versioning.notices.commit')
else
redirect_to resource_path, alert: I18n.t('active_versioning.errors.commit')
end
end
member_action :create_draft, method: :post do
if resource.create_draft_from_version(params[:version_id])
redirect_to edit_resource_path,
notice: I18n.t('active_versioning.notices.create_draft_from_version')
else
redirect_to [active_admin_namespace.name, resource, :versions],
alert: I18n.t('active_versioning.errors.create_draft_from_version')
end
end
member_action :discard_draft, method: :delete do
resource.destroy_draft
redirect_to resource_path, notice: I18n.t('active_versioning.notices.discard_draft')
end
controller do
before_action :assign_version_params, only: [:create, :update]
before_action :set_draft_as_resource, only: [:edit, :update, :commit, :preview]
private
def renderer_for(action)
if action == :show
ShowResource
else
super
end
end
def assign_version_params
resource_params.first.merge!(version_author: committer)
end
def set_draft_as_resource
set_resource_ivar(resource.current_draft)
end
def committer
current_admin_user.email
end
def commit_params
params.permit(:commit_message).merge(committer: committer)
end
end
end
end
|