Skip to content

Commit

Permalink
Maintenance: Hide experimental mobile app behind an ENV switch.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgruner authored and dominikklein committed May 6, 2022
1 parent cc963eb commit 1ddec70
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 29 deletions.
2 changes: 2 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ variables:
MAIL_SERVER_EMAIL: "[email protected]"
KEEP_ON_MAIL_SERVER: "mail"
KEEP_ON_MAIL_SERVER_ACCOUNT: "[email protected]:zammad"
# Temporary switch to enable the mobile front end for testing.
ENABLE_EXPERIMENTAL_MOBILE_FRONTEND: 'true'

# Cache gems in between jobs and pipelines
# ATTENTION: We use a combination of the Ruby major and minor version number
Expand Down
5 changes: 3 additions & 2 deletions .gitlab/configure_environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ def self.configure_database # rubocop:disable Metrics/AbcSize, Metrics/Cyclomati
File.write(File.join(__dir__, '../config/database.yml'), Psych.dump(cnf))
end

def self.configure_redis
if ENV['REDIS_URL'].nil? || ENV['REDIS_URL'].empty? # rubocop:disable Rails/Blank
def self.configure_redis # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
puts 'ENABLING THE NEW EXPERIMENTAL MOBILE FRONTEND.' if ENV['ENABLE_EXPERIMENTAL_MOBILE_FRONTEND'] == 'true'
if ENV['ENABLE_EXPERIMENTAL_MOBILE_FRONTEND'] == 'true' && (ENV['REDIS_URL'].nil? || ENV['REDIS_URL'].empty?) # rubocop:disable Rails/Blank
if database_type == 'mysql'
raise 'Redis was not found, but is required for ActionCable on MySQL based systems.'
end
Expand Down
13 changes: 13 additions & 0 deletions app/graphql/gql/zammad_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,16 @@ def self.unauthorized_field(error)
raise GraphQL::ExecutionError.new(err.message, extensions: extensions)
end
end

# Temporary Hack: only process trigger events if ActionCable is enabled.
# TODO: Remove when this switch is not needed any more.
module GraphQL
class Subscriptions
alias orig_trigger trigger
def trigger(...)
return if ENV['ENABLE_EXPERIMENTAL_MOBILE_FRONTEND'] != 'true'

orig_trigger(...)
end
end
end
7 changes: 7 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
require 'rails/all'
require_relative 'issue_2656_workaround_for_rails_issue_33600'

# Temporary Hack: skip vite build if ENABLE_EXPERIMENTAL_MOBILE_FRONTEND is not set.
# This must be called before ViteRuby is loaded by Bundler.
# TODO: Remove when this switch is not needed any more.
if ENV['ENABLE_EXPERIMENTAL_MOBILE_FRONTEND'] != 'true'
ENV['VITE_RUBY_SKIP_ASSETS_PRECOMPILE_EXTENSION'] = 'true'
end

# DO NOT REMOVE THIS LINE - see issue #2037
Bundler.setup

Expand Down
44 changes: 23 additions & 21 deletions config/initializers/action_cable_preferences.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/

if ENV['REDIS_URL'].present?
Rails.application.config.action_cable.cable = {
'adapter' => 'redis',
'url' => ENV['REDIS_URL'],
'channel_prefix' => "zammad_#{Rails.env}"
}
Rails.logger.info 'Using the "Redis" adapter for ActionCable.'
else
if ActiveRecord::Base.connection_config[:adapter] == 'mysql'
raise 'Please provide a working redis instance via REDIS_URL - this is required on MySQL databases.'
end

# The 'postgresql' adapter does not work correctly in Capybara currently, so use
# 'test' instead.
if Rails.env.test?
if ENV['ENABLE_EXPERIMENTAL_MOBILE_FRONTEND'] == 'true'
if ENV['REDIS_URL'].present?
Rails.application.config.action_cable.cable = {
'adapter' => 'test',
'adapter' => 'redis',
'url' => ENV['REDIS_URL'],
'channel_prefix' => "zammad_#{Rails.env}"
}
Rails.logger.info 'Using the "test" adapter for ActionCable.'
Rails.logger.info 'Using the "Redis" adapter for ActionCable.'
else
Rails.application.config.action_cable.cable = {
'adapter' => 'postgresql',
}
Rails.logger.info 'Using the "PostgreSQL" adapter for ActionCable.'
if ActiveRecord::Base.connection_db_config.configuration_hash[:adapter] == 'mysql'
raise 'Please provide a working redis instance via REDIS_URL - this is required on MySQL databases.'
end

# The 'postgresql' adapter does not work correctly in Capybara currently, so use
# 'test' instead.
if Rails.env.test?
Rails.application.config.action_cable.cable = {
'adapter' => 'test',
}
Rails.logger.info 'Using the "test" adapter for ActionCable.'
else
Rails.application.config.action_cable.cable = {
'adapter' => 'postgresql',
}
Rails.logger.info 'Using the "PostgreSQL" adapter for ActionCable.'
end
end
end
9 changes: 7 additions & 2 deletions config/routes/graphql.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/

Zammad::Application.routes.draw do
match '/graphql', to: 'graphql#execute', via: %i[options post]
# Temporary Hack: only process trigger events if ActionCable is enabled.
# TODO: Remove when this switch is not needed any more.

if ENV['ENABLE_EXPERIMENTAL_MOBILE_FRONTEND'] == 'true'
Zammad::Application.routes.draw do
match '/graphql', to: 'graphql#execute', via: %i[options post]
end
end
11 changes: 8 additions & 3 deletions config/routes/mobile.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/

Zammad::Application.routes.draw do
get '/mobile', to: 'mobile#index'
get '/mobile/*path', to: 'mobile#index'
# Temporary Hack: only process trigger events if ActionCable is enabled.
# TODO: Remove when this switch is not needed any more.

if ENV['ENABLE_EXPERIMENTAL_MOBILE_FRONTEND'] == 'true'
Zammad::Application.routes.draw do
get '/mobile', to: 'mobile#index'
get '/mobile/*path', to: 'mobile#index'
end
end
6 changes: 6 additions & 0 deletions spec/graphql/gql/mutations/login_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
# Login and logout work only via controller, so use type: request.
RSpec.describe Gql::Mutations::Login, type: :request do

# Temporary Hack: skip tests if ENABLE_EXPERIMENTAL_MOBILE_FRONTEND is not set.
# TODO: Remove when this switch is not needed any more.
around do |example|
example.run if ENV['ENABLE_EXPERIMENTAL_MOBILE_FRONTEND'] == 'true'
end

context 'when logging on' do
let(:agent_password) { 'some_test_password' }
let(:agent) { create(:agent, password: agent_password) }
Expand Down
6 changes: 6 additions & 0 deletions spec/graphql/gql/mutations/logout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
# Login and logout work only via controller, so use type: request.
RSpec.describe Gql::Mutations::Logout, type: :request do

# Temporary Hack: skip tests if ENABLE_EXPERIMENTAL_MOBILE_FRONTEND is not set.
# TODO: Remove when this switch is not needed any more.
around do |example|
example.run if ENV['ENABLE_EXPERIMENTAL_MOBILE_FRONTEND'] == 'true'
end

context 'when logging out' do
let(:agent) { create(:agent) }
let(:query) { File.read(Rails.root.join('app/frontend/common/graphql/mutations/logout.graphql')) }
Expand Down
4 changes: 3 additions & 1 deletion spec/graphql/gql/record_loader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,15 @@ def trace_queries(total_queries, uncached_queries)
}
)

adapter = ActiveRecord::Base.connection_db_config.configuration_hash[:adapter]

expect(uncached_queries).to include(
{
'Permission Load' => 3,
'Permission Exists?' => 3,
'Group Load' => 2,
'UserGroup Exists?' => 1,
'Ticket Load' => 2,
'Ticket Load' => adapter == 'mysql2' ? 1 : 2, # differs for some reason, not sure why
'Ticket::Article Load' => 1,
'User Load' => 1,
'Organization Load' => 1,
Expand Down
7 changes: 7 additions & 0 deletions spec/support/capybara/websocket_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
RSpec.configure do |config|
config.around(:each, type: :system) do |example|

# Temporary Hack: skip tests if ENABLE_EXPERIMENTAL_MOBILE_FRONTEND is not set.
# TODO: Remove when this switch is not needed any more.
if example.metadata[:app] == :mobile && ENV['ENABLE_EXPERIMENTAL_MOBILE_FRONTEND'] != 'true'
example.skip
next
end

server_required = example.metadata.fetch(:websocket, true)

if server_required
Expand Down
6 changes: 6 additions & 0 deletions spec/support/graphql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,10 @@ def read_graphql_file(filename)
config.before(:each, :authenticated_as, type: :graphql) do |example|
self.graphql_current_user = authenticated_as_get_user example.metadata[:authenticated_as], return_type: :user
end

# Temporary Hack: skip tests if ENABLE_EXPERIMENTAL_MOBILE_FRONTEND is not set.
# TODO: Remove when this switch is not needed any more.
config.around(:each, type: :graphql) do |example|
example.run if ENV['ENABLE_EXPERIMENTAL_MOBILE_FRONTEND'] == 'true'
end
end

0 comments on commit 1ddec70

Please sign in to comment.