forked from papyri/sosol
-
Notifications
You must be signed in to change notification settings - Fork 6
/
apis_identifiers_controller.rb
68 lines (59 loc) · 2.39 KB
/
apis_identifiers_controller.rb
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
class APISIdentifiersController < IdentifiersController
before_action :authorize
before_action :ownership_guard, only: %i[update updatexml]
require 'pp'
def edit
find_identifier
@is_editor_view = true
end
def update
find_identifier
# strip carriage returns
xml_content = params[@identifier.class.to_s.underscore][:xml_content].gsub(/\r\n?/, "\n")
# if user fills in comment box at top, it overrides the bottom
params[:comment] = params[:commenttop] if !params[:commenttop].nil? && params[:commenttop].strip != ''
begin
commit_sha = @identifier.set_xml_content(xml_content,
comment: params[:comment])
if !params[:comment].nil? && params[:comment].strip != ''
@comment = Comment.new({ git_hash: commit_sha, user_id: @current_user.id,
identifier_id: @identifier.origin.id, publication_id: @identifier.publication.origin.id, comment: params[:comment].to_s, reason: 'commit' })
@comment.save
end
flash[:notice] = 'File updated.'
expire_leiden_cache
expire_publication_cache
if %w[new editing].include? @identifier.publication.status
flash[:notice] += " Go to the <a href='#{url_for(@identifier.publication)}'>publication overview</a> if you would like to submit."
end
rescue JRubyXML::ParseError => e
flash[:error] = "#{e.to_str}. This file was NOT SAVED."
end
redirect_to action: :edit, id: @identifier.id
end
def preview
find_identifier
@is_editor_view = true
end
def xml
find_identifier
send_data(@identifier.xml_content, filename: @identifier.title, type: 'application/xml')
end
private
def generate_flash_message
flash[:notice] = 'File updated.'
if %w[new editing].include? @identifier.publication.status
flash[:notice] += " Go to the <a href='#{url_for(@identifier.publication)}'>publication overview</a> if you would like to submit."
end
end
def save_comment(comment, commit_sha)
if !comment.nil? && comment.strip != ''
@comment = Comment.new({ git_hash: commit_sha, user_id: @current_user.id, identifier_id: @identifier.id,
publication_id: @identifier.publication_id, comment: comment, reason: 'commit' })
@comment.save
end
end
def find_identifier
@identifier = APISIdentifier.find(params[:id].to_s)
end
end