From 043a0af9f2655f6daa73066514f047420a2b70b4 Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Tue, 15 Jan 2019 14:11:57 +0100 Subject: [PATCH] Add Null email driver (support workaround for #224) --- .../channel/email_account_overview.jst.eco | 8 +++++-- app/models/channel/driver/null.rb | 22 +++++++++++++++++++ spec/factories/channel.rb | 14 ++++++++++++ spec/system/admin/channel/email_spec.rb | 17 ++++++++++++++ 4 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 app/models/channel/driver/null.rb create mode 100644 spec/system/admin/channel/email_spec.rb diff --git a/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco b/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco index 912dd5ac6..cdeb70351 100644 --- a/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco +++ b/app/assets/javascripts/app/views/channel/email_account_overview.jst.eco @@ -46,7 +46,9 @@

<%- @Icon('status', channel.status_in + " inline") %> <%- @T('Inbound') %>

-
<%- @T('Edit') %>
+ <% if channel.preferences.editable isnt false: %> +
<%- @T('Edit') %>
+ <% end %>
@@ -89,7 +91,9 @@

<%- @Icon('status', channel.status_out + " inline") %> <%- @T('Outbound') %>

-
<%- @T('Edit') %>
+ <% if channel.preferences.editable isnt false: %> +
<%- @T('Edit') %>
+ <% end %>
<% if channel.options.outbound && channel.options.outbound.options: %> diff --git a/app/models/channel/driver/null.rb b/app/models/channel/driver/null.rb new file mode 100644 index 000000000..15fe81622 --- /dev/null +++ b/app/models/channel/driver/null.rb @@ -0,0 +1,22 @@ +# Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/ +class Channel::Driver::Null + def fetchable?(_channel) + false + end + + def fetch(*) + { + result: 'ok', + fetched: 0, + notice: '', + } + end + + def disconnect + true + end + + def self.streamable? + false + end +end diff --git a/spec/factories/channel.rb b/spec/factories/channel.rb index 9166b4c2f..2b727e977 100644 --- a/spec/factories/channel.rb +++ b/spec/factories/channel.rb @@ -8,6 +8,20 @@ FactoryBot.define do updated_by_id 1 created_by_id 1 + factory :email_channel do + area 'Email::Account' + options do + { + inbound: { + adapter: 'null', options: {} + }, + outbound: { + adapter: 'sendmail' + } + } + end + end + factory :twitter_channel do transient do custom_options { {} } diff --git a/spec/system/admin/channel/email_spec.rb b/spec/system/admin/channel/email_spec.rb new file mode 100644 index 000000000..fecb405da --- /dev/null +++ b/spec/system/admin/channel/email_spec.rb @@ -0,0 +1,17 @@ +require 'rails_helper' + +RSpec.describe 'Admin Panel > Channels > Email', type: :system, authenticated: true do + # https://github.com/zammad/zammad/issues/224 + it 'hides "Edit" links when Channel#preferences[:editable] == false' do + # ensure that the only existing email channel + # has preferences == { editable: false } + Channel.destroy_all + create(:email_channel, preferences: { editable: false }) + + visit '/#channels/email' + expect(page).to have_css('#c-account h3', text: 'Inbound') # Wait for frontend to load + expect(page).to have_css('#c-account h3', text: 'Outbound') # Wait for frontend to load + + expect(page).not_to have_css('.js-editInbound, .js-editOutbound', text: 'Edit') + end +end