Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #2777: Knowledge Base - Attachments not working for internal re…
…aders.
- Loading branch information
1 parent
86a90d2
commit d24a7c5
Showing
6 changed files
with
232 additions
and
4 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
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,206 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe 'KnowledgeBase attachments', type: :request do | ||
include_context 'basic Knowledge Base' | ||
|
||
let(:attachment) do | ||
attachment_file = File.open 'spec/fixtures/upload/hello_world.txt' | ||
|
||
Store.add( | ||
object: object.class.to_s, | ||
o_id: object.id, | ||
data: attachment_file.read, | ||
filename: 'hello_world.txt', | ||
preferences: {}, | ||
created_by_id: 1, | ||
) | ||
end | ||
|
||
let(:endpoint) { "/api/v1/attachments/#{attachment.id}" } | ||
|
||
describe 'visible when attached to' do | ||
shared_examples 'a visible resource' do | ||
it 'and returns correct status code' do | ||
get endpoint | ||
expect(response).to have_http_status(:ok) | ||
end | ||
end | ||
|
||
shared_examples 'a non-existent resource' do | ||
it 'and returns correct status code' do | ||
get endpoint | ||
expect(response).to have_http_status(:not_found) | ||
end | ||
end | ||
|
||
describe 'draft answer' do | ||
let(:object) { draft_answer } | ||
|
||
describe 'as agent', authenticated_as: :agent_user do | ||
it_behaves_like 'a non-existent resource' | ||
end | ||
|
||
context 'as admin', authenticated_as: :admin_user do | ||
it_behaves_like 'a visible resource' | ||
end | ||
|
||
context 'as customer', authenticated_as: :customer_user do | ||
it_behaves_like 'a non-existent resource' | ||
end | ||
|
||
context 'as guest' do | ||
it_behaves_like 'a non-existent resource' | ||
end | ||
end | ||
|
||
describe 'internal answer' do | ||
let(:object) { internal_answer } | ||
|
||
describe 'as agent', authenticated_as: :agent_user do | ||
it_behaves_like 'a visible resource' | ||
end | ||
|
||
context 'as admin', authenticated_as: :admin_user do | ||
it_behaves_like 'a visible resource' | ||
end | ||
|
||
context 'as customer', authenticated_as: :customer_user do | ||
it_behaves_like 'a non-existent resource' | ||
end | ||
|
||
context 'as guest' do | ||
it_behaves_like 'a non-existent resource' | ||
end | ||
end | ||
|
||
describe 'published answer' do | ||
let(:object) { published_answer } | ||
|
||
describe 'as agent', authenticated_as: :agent_user do | ||
it_behaves_like 'a visible resource' | ||
end | ||
|
||
context 'as admin', authenticated_as: :admin_user do | ||
it_behaves_like 'a visible resource' | ||
end | ||
|
||
context 'as customer', authenticated_as: :customer_user do | ||
it_behaves_like 'a visible resource' | ||
end | ||
|
||
context 'as guest' do | ||
it_behaves_like 'a visible resource' | ||
end | ||
end | ||
|
||
describe 'archived answer' do | ||
let(:object) { archived_answer } | ||
|
||
describe 'as agent', authenticated_as: :agent_user do | ||
it_behaves_like 'a non-existent resource' | ||
end | ||
|
||
context 'as admin', authenticated_as: :admin_user do | ||
it_behaves_like 'a visible resource' | ||
end | ||
|
||
context 'as customer', authenticated_as: :customer_user do | ||
it_behaves_like 'a non-existent resource' | ||
end | ||
|
||
context 'as guest' do | ||
it_behaves_like 'a non-existent resource' | ||
end | ||
end | ||
end | ||
|
||
describe 'deletable when attached to' do | ||
shared_examples 'a deletable resource' do | ||
it { expect { delete endpoint }.to change { Store.exists? attachment.id }.from(true).to(false) } | ||
end | ||
|
||
shared_examples 'a non-deletable resource' do | ||
it { expect { delete endpoint }.not_to change { Store.exists? attachment.id }.from(true) } | ||
end | ||
|
||
describe 'draft answer' do | ||
let(:object) { draft_answer } | ||
|
||
describe 'as agent', authenticated_as: :agent_user do | ||
it_behaves_like 'a non-deletable resource' | ||
end | ||
|
||
context 'as admin', authenticated_as: :admin_user do | ||
it_behaves_like 'a deletable resource' | ||
end | ||
|
||
context 'as customer', authenticated_as: :customer_user do | ||
it_behaves_like 'a non-deletable resource' | ||
end | ||
|
||
context 'as guest' do | ||
it_behaves_like 'a non-deletable resource' | ||
end | ||
end | ||
|
||
describe 'internal answer' do | ||
let(:object) { internal_answer } | ||
|
||
describe 'as agent', authenticated_as: :agent_user do | ||
it_behaves_like 'a non-deletable resource' | ||
end | ||
|
||
context 'as admin', authenticated_as: :admin_user do | ||
it_behaves_like 'a deletable resource' | ||
end | ||
|
||
context 'as customer', authenticated_as: :customer_user do | ||
it_behaves_like 'a non-deletable resource' | ||
end | ||
|
||
context 'as guest' do | ||
it_behaves_like 'a non-deletable resource' | ||
end | ||
end | ||
|
||
describe 'published answer' do | ||
let(:object) { published_answer } | ||
|
||
describe 'as agent', authenticated_as: :agent_user do | ||
it_behaves_like 'a non-deletable resource' | ||
end | ||
|
||
context 'as admin', authenticated_as: :admin_user do | ||
it_behaves_like 'a deletable resource' | ||
end | ||
|
||
context 'as customer', authenticated_as: :customer_user do | ||
it_behaves_like 'a non-deletable resource' | ||
end | ||
|
||
context 'as guest' do | ||
it_behaves_like 'a non-deletable resource' | ||
end | ||
end | ||
|
||
describe 'archived answer' do | ||
let(:object) { archived_answer } | ||
|
||
describe 'as agent', authenticated_as: :agent_user do | ||
it_behaves_like 'a non-deletable resource' | ||
end | ||
|
||
context 'as admin', authenticated_as: :admin_user do | ||
it_behaves_like 'a deletable resource' | ||
end | ||
|
||
context 'as customer', authenticated_as: :customer_user do | ||
it_behaves_like 'a non-deletable resource' | ||
end | ||
|
||
context 'as guest' do | ||
it_behaves_like 'a non-deletable resource' | ||
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
d24a7c5
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.
Hello @mantas and @thorsteneckel !
Thanks a lot for providing a solution. I only got one little question, even if it's because I missed reading some explanation and that's because I don't know.
Why could it be that I miss the last two files in my installation? And not only these specific files, I miss also the folder spec/requests/knowledge_base/
Do I need to install a specific package or do I have to create some folders and files?
Thanks a lot and greetings,
Mathias.
d24a7c5
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.
Hi @MathiasVolkmer - I assume you're running Zammad on the stable branch? Because we fixed this within develop so it will be part of the next release (3.3) coming next week.
d24a7c5
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.
Hi @thorsteneckel !
Thanks a lot! That I didn't know. Then I will wait for the next updates and will edit the files with Mantas' fixes 👍