-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into issues/show-updated-affected-list
- Loading branch information
Showing
13 changed files
with
210 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module AttachmentsCopier | ||
def copy_attachments(record) | ||
record.content.scan(Attachment::SCREENSHOT_REGEX).each do |screenshot_path| | ||
full_screenshot_path, _, _, _, project_id, node_id, filename, _ = screenshot_path | ||
|
||
attachment = Attachment.find_by(filename: CGI::unescape(filename), node_id: record.node_id_was) | ||
|
||
if attachment | ||
new_attachment = attachment.copy_to(record.node) | ||
new_filename = new_attachment.url_encoded_filename | ||
new_path = full_screenshot_path.gsub( | ||
/nodes\/[0-9]+\/attachments\/.+/, | ||
"nodes/#{new_attachment.node_id}/attachments/#{new_filename}" | ||
) | ||
|
||
record.content = record.content.gsub(full_screenshot_path, new_path) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
class LiquidCachedAssigns < Hash | ||
AVAILABLE_PROJECT_ASSIGNS = %w{ evidences issues nodes notes project tags }.freeze | ||
|
||
attr_accessor :assigns, :project | ||
|
||
def initialize(project:) | ||
@project = project | ||
|
||
@assigns = { 'project' => ProjectDrop.new(project) } | ||
@assigns.merge!(assigns_pro) | ||
end | ||
|
||
def [](record_type) | ||
assigns[record_type] ||= cached_drops(record_type) | ||
end | ||
|
||
# SEE: https://github.com/Shopify/liquid/blob/77bc56/lib/liquid/context.rb#L211 | ||
# Liquid is checking if the variable is present in the assigns hash by | ||
# calling the `key?` method. Since we're lazily loading the keys, the variable | ||
# may not yet be present in the assigns hash. | ||
def key?(key) | ||
AVAILABLE_PROJECT_ASSIGNS.include?(key.to_s) || assigns.key?(key) | ||
end | ||
|
||
def merge(hash) | ||
lca = LiquidCachedAssigns.new(project: project) | ||
lca.assigns = @assigns.merge(hash) | ||
lca | ||
end | ||
|
||
def merge!(hash) | ||
@assigns.merge!(hash) | ||
self | ||
end | ||
|
||
private | ||
|
||
def assigns_pro | ||
{} | ||
end | ||
|
||
def cached_drops(record_type) | ||
records = project_records(record_type) | ||
|
||
return [] if records.empty? | ||
|
||
cache_key = ActiveSupport::Cache.expand_cache_key([project.id, records], 'liquid') | ||
drop_class = "#{record_type.singularize.camelize}Drop".constantize | ||
|
||
Rails.cache.fetch(cache_key) do | ||
records.map { |record| drop_class.new(record) } | ||
end | ||
end | ||
|
||
def project_records(record_type) | ||
return [] unless AVAILABLE_PROJECT_ASSIGNS.include?(record_type) | ||
|
||
case record_type | ||
when 'evidences' | ||
project.evidence | ||
when 'nodes' | ||
project.nodes.user_nodes | ||
when 'notes' | ||
# FIXME - ISSUE/NOTE INHERITANCE | ||
project.notes.where.not(node_id: project.issue_library.id) | ||
else | ||
project.send(record_type.to_sym) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.