-
-
Notifications
You must be signed in to change notification settings - Fork 277
feature: add open attachment without download #3681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Nevelito
wants to merge
15
commits into
avo-hq:main
Choose a base branch
from
Nevelito:open_field_attachments
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+84
−2
Open
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f688aa0
add open attachment without download
Nevelito 227ba54
fix standardrb spec
Nevelito 04add95
fix specs
Nevelito 3a5238d
fix standardrb spec fails
Nevelito ff44672
delete changes in yarn lock
Nevelito 88fc94c
request changes
Nevelito a759251
Merge branch 'main' into open_field_attachments
Paul-Bob ecc62c3
request changes
Nevelito 7597bbe
fix bug
Nevelito b99dbde
fix spec
Nevelito c22904d
fix spec
Nevelito e5f1ab6
fix spec
Nevelito 898f26b
tweak
Paul-Bob f77cfe3
Merge branch 'main' into open_field_attachments
Paul-Bob a94cc41
Merge branch 'main' into open_field_attachments
Paul-Bob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions
2
app/components/avo/fields/common/files/view_type/grid_item_component.rb
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
Empty file.
Empty file.
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,52 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "OpenFieldAttachment", type: :system do | ||
let!(:user) { User.first } | ||
let!(:cv_file) { Rails.root.join("app", "assets", "pdfs", "cv_sample.pdf") } | ||
let!(:csv_file) { Rails.root.join("app", "assets", "csvs", "sample.csv") } | ||
let(:path) { "/admin/resources/field_discovery_users/#{user.slug}" } | ||
|
||
context "with PDF attachment" do | ||
before do | ||
user.cv.attach(io: File.open(cv_file), filename: "cv_sample.pdf", content_type: "application/pdf") | ||
end | ||
|
||
it "opens attachment in new window without download" do | ||
test_open_PDF_attachment(path) | ||
end | ||
end | ||
|
||
context "with CSV attachment" do | ||
before do | ||
user.cv.attach(io: File.open(csv_file), filename: "sample.csv", content_type: "application/csv") | ||
end | ||
|
||
it "can not open or download attachment in new window" do | ||
test_open_CSV_attachment(path) | ||
end | ||
end | ||
|
||
def test_open_PDF_attachment(path) | ||
visit path | ||
|
||
link = find('a[rel="noopener noreferrer"][target="_blank"]', visible: :all) | ||
expect(link).to be_present | ||
link.click | ||
|
||
expect(page.driver.browser.current_url).not_to include("download") | ||
expect(page.driver.browser.window_handles.length).to eq 2 | ||
end | ||
|
||
def test_open_CSV_attachment(path) | ||
visit path | ||
|
||
link = first('a.relative', visible: :all) | ||
Check failure on line 43 in spec/system/avo/open_field_attachment_spec.rb
|
||
|
||
expect(link).to be_present | ||
expect(link[:target]).to eq("") | ||
expect(link[:rel]).to eq("") | ||
|
||
expect(page.driver.browser.current_url).not_to include("download") | ||
expect(page.driver.browser.window_handles.length).to eq 1 | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's important to check
can_download_file?
to enforce authorization properly. Otherwise, users without download permissions could still open and inspect the PDF.