123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
- class FirstStepsController < ApplicationController
- prepend_before_action :authentication_check
- before_action -> { render json: [] }, if: -> { !authorized? }
- def index
- invite_agents = false
- # if User.of_role('Agent').count > 2
- # invite_agents = true
- # end
- invite_customers = false
- # if User.of_role('Customer').count > 2
- # invite_customers = true
- # end
- chat_active = false
- if Setting.get('chat')
- chat_active = true
- end
- form_active = false
- if Setting.get('form_ticket_create')
- form_active = true
- end
- twitter_active = false
- if Channel.where(area: 'Twitter::Account').count.positive?
- twitter_active = true
- end
- facebook_active = false
- if Channel.where(area: 'Facebook::Account').count.positive?
- facebook_active = true
- end
- email_active = false
- if Channel.where(area: 'Email::Account').count.positive?
- email_active = true
- end
- text_module_active = false
- if TextModule.count.positive?
- text_module_active = true
- end
- macro_active = false
- if Macro.count > 1
- macro_active = true
- end
- if current_user.permissions?('admin')
- result = [
- {
- name: __('Configuration'),
- items: [
- {
- name: __('Branding'),
- checked: true,
- location: '#settings/branding',
- },
- {
- name: __('Your Email Configuration'),
- checked: email_active,
- location: '#channels/email',
- },
- {
- name: __('Invite agents/colleagues to help working on tickets'),
- checked: invite_agents,
- location: '#',
- class: 'js-inviteAgent',
- },
- {
- name: __('Invite customers to create issues in Zammad'),
- checked: invite_customers,
- location: '#',
- class: 'js-inviteCustomer',
- },
- ],
- },
- {
- name: __('How to use it'),
- items: [
- {
- name: __('Intro'),
- checked: true,
- location: '#clues',
- },
- {
- name: __('Create a Test Ticket'),
- checked: false,
- location: '#',
- class: 'js-testTicket',
- },
- {
- name: __('Create Text Modules'),
- checked: text_module_active,
- location: '#manage/text_modules',
- },
- {
- name: __('Create Macros'),
- checked: macro_active,
- location: '#manage/macros',
- },
- # {
- # name: 'Create Overviews',
- # checked: false,
- # location: '#manage/overviews',
- # },
- ],
- },
- {
- name: __('Additional Channels'),
- items: [
- {
- name: __('Twitter'),
- checked: twitter_active,
- location: '#channels/twitter',
- },
- {
- name: __('Facebook'),
- checked: facebook_active,
- location: '#channels/facebook',
- },
- {
- name: __('Chat'),
- checked: chat_active,
- location: '#channels/chat',
- },
- {
- name: __('Online Forms'),
- checked: form_active,
- location: '#channels/form',
- },
- ],
- },
- ]
- check_availability(result)
- render json: result
- return
- end
- result = [
- {
- name: __('How to use it'),
- items: [
- {
- name: __('Intro'),
- checked: true,
- location: '#clues',
- },
- {
- name: __('Create a Test Ticket'),
- checked: false,
- location: '#',
- class: 'js-testTicket',
- },
- {
- name: __('Invite customers to create issues in Zammad'),
- checked: invite_customers,
- location: '#',
- class: 'js-inviteCustomer',
- },
- ],
- },
- ]
- check_availability(result)
- render json: result
- end
- def test_ticket
- agent = current_user
- customer = test_customer
- from = Channel::EmailBuild.recipient_line customer.fullname, customer.email
- original_user_id = UserInfo.current_user_id
- result = NotificationFactory::Mailer.template(
- template: 'test_ticket',
- locale: agent.locale,
- objects: {
- agent: agent,
- customer: customer,
- },
- raw: true,
- )
- UserInfo.current_user_id = customer.id
- ticket = Ticket.create!(
- group_id: Group.find_by(active: true, name: 'Users').id,
- customer_id: customer.id,
- title: result[:subject],
- )
- article = Ticket::Article.create!(
- ticket_id: ticket.id,
- type_id: Ticket::Article::Type.find_by(name: 'phone').id,
- sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
- from: from,
- body: result[:body],
- content_type: 'text/html',
- internal: false,
- )
- UserInfo.current_user_id = original_user_id
- overview = test_overview
- assets = ticket.assets({})
- assets = article.assets(assets)
- assets = overview.assets(assets)
- render json: {
- overview_id: overview.id,
- ticket_id: ticket.id,
- assets: assets,
- }
- end
- private
- def test_overview
- Overview.find_by(name: __('Unassigned & Open Tickets'))
- end
- def test_customer
- User.find_by(login: 'nicole.braun@zammad.org')
- end
- def check_availability(result)
- return result if test_ticket_active?
- result.each do |item|
- items = []
- item[:items].each do |local_item|
- next if local_item[:name] == 'Create a Test Ticket'
- items.push local_item
- end
- item[:items] = items
- end
- result
- end
- def test_ticket_active?
- overview = test_overview
- return false if !overview
- return false if overview.updated_by_id != 1
- return false if !test_customer
- return false if Group.where(active: true, name: 'Users').count.zero?
- true
- end
- end
|