Skip to content

Commit

Permalink
Maintenance: Improve calendar subscription backends.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgruner committed Apr 17, 2024
1 parent ae6455f commit 41eb1a9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions i18n/zammad.pot
Expand Up @@ -1227,6 +1227,10 @@ msgstr ""
msgid "An unexpected error occurred during system setup."
msgstr ""

#: lib/calendar_subscriptions.rb
msgid "An unknown method name was requested."
msgstr ""

#: app/assets/javascripts/app/views/integration/exchange_wizard.jst.eco
#: app/assets/javascripts/app/views/integration/ldap_wizard.jst.eco
msgid "Analyzing entries with given configuration…"
Expand Down
5 changes: 4 additions & 1 deletion lib/calendar_subscriptions.rb
Expand Up @@ -46,7 +46,10 @@ def generic_call(object_name, method_name = 'all')
sub_class_name = object_name.to_s.capitalize
object = "CalendarSubscriptions::#{sub_class_name}".constantize
instance = object.new(@user, @preferences[ object_name ], @time_zone)
method = instance.method(method_name)

raise Exceptions::UnprocessableEntity, __('An unknown method name was requested.') if object::ALLOWED_METHODS.exclude?(method_name)

method = instance.method(method_name)
events_data += method.call
end
events_data
Expand Down
1 change: 1 addition & 0 deletions lib/calendar_subscriptions/tickets.rb
@@ -1,6 +1,7 @@
# Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/

class CalendarSubscriptions::Tickets
ALLOWED_METHODS = %w[all new_open pending escalation].freeze

def initialize(user, preferences, time_zone)
@user = user
Expand Down
34 changes: 34 additions & 0 deletions spec/requests/calendar_subscriptions_spec.rb
Expand Up @@ -52,4 +52,38 @@
expect(response.body).to match(%r{BEGIN:VCALENDAR})
end
end

describe 'methods', authenticated_as: :user do
let(:group) { create(:group) }
let(:user) { create(:agent) }
let(:ticket_1) { create(:ticket, title: SecureRandom.uuid, group: group, owner: user, state_name: 'open') }
let(:ticket_2) { create(:ticket, title: SecureRandom.uuid, group: group, owner: user, state_name: 'pending reminder', pending_time: 1.day.from_now) }

before do
user.groups << group
ticket_1
ticket_2
end

it 'returns open tickets', :aggregate_failures do
get '/ical/tickets/new_open'

expect(response.body).to include(ticket_1.title)
expect(response.body).not_to include(ticket_2.title)
end

it 'returns pending tickets', :aggregate_failures do
get '/ical/tickets/pending'

expect(response.body).not_to include(ticket_1.title)
expect(response.body).to include(ticket_2.title)
end

it 'raises error on unknown method', :aggregate_failures do
get '/ical/tickets/xxx'

expect(json_response['error']).to eq('An unknown method name was requested.')
expect(response).to have_http_status(:unprocessable_entity)
end
end
end

0 comments on commit 41eb1a9

Please sign in to comment.