trabajo-afectivo/app/controllers/first_steps_controller.rb

248 lines
6.3 KiB
Ruby
Raw Normal View History

2022-01-01 13:38:12 +00:00
# Copyright (C) 2012-2022 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
2019-08-14 08:15:36 +00:00
form_active = false
if Setting.get('form_ticket_create')
2019-08-14 08:15:36 +00:00
form_active = true
end
twitter_active = false
2016-10-24 21:59:18 +00:00
if Channel.where(area: 'Twitter::Account').count.positive?
twitter_active = true
end
facebook_active = false
2016-10-24 21:59:18 +00:00
if Channel.where(area: 'Facebook::Account').count.positive?
facebook_active = true
end
email_active = false
2016-10-24 21:59:18 +00:00
if Channel.where(area: 'Email::Account').count.positive?
email_active = true
end
text_module_active = false
2016-10-24 21:59:18 +00:00
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,
2016-02-29 23:52:51 +00:00
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'),
2019-08-14 08:15:36 +00:00
checked: form_active,
location: '#channels/form',
},
],
},
]
2016-02-29 23:52:51 +00:00
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,
2016-02-29 23:52:51 +00:00
location: '#',
class: 'js-testTicket',
},
{
name: __('Invite customers to create issues in Zammad'),
checked: invite_customers,
location: '#',
class: 'js-inviteCustomer',
},
],
},
]
2016-02-29 23:52:51 +00:00
check_availability(result)
render json: result
end
2016-02-29 23:52:51 +00:00
def test_ticket
agent = current_user
customer = test_customer
from = "#{customer.fullname} <#{customer.email}>"
original_user_id = UserInfo.current_user_id
2016-04-13 23:40:37 +00:00
result = NotificationFactory::Mailer.template(
2016-02-29 23:52:51 +00:00
template: 'test_ticket',
locale: agent.locale,
2016-02-29 23:52:51 +00:00
objects: {
agent: agent,
2016-02-29 23:52:51 +00:00
customer: customer,
},
raw: true,
2016-02-29 23:52:51 +00:00
)
UserInfo.current_user_id = customer.id
2017-06-16 23:02:13 +00:00
ticket = Ticket.create!(
group_id: Group.find_by(active: true, name: 'Users').id,
2016-02-29 23:52:51 +00:00
customer_id: customer.id,
title: result[:subject],
2016-02-29 23:52:51 +00:00
)
2017-06-16 23:02:13 +00:00
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],
2016-02-29 23:52:51 +00:00
content_type: 'text/html',
internal: false,
2016-02-29 23:52:51 +00:00
)
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,
2016-02-29 23:52:51 +00:00
}
end
private
def test_overview
Overview.find_by(name: __('Unassigned & Open Tickets'))
2016-02-29 23:52:51 +00:00
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|
2016-02-29 23:52:51 +00:00
items = []
item[:items].each do |local_item|
2016-02-29 23:52:51 +00:00
next if local_item[:name] == 'Create a Test Ticket'
2016-02-29 23:52:51 +00:00
items.push local_item
end
2016-02-29 23:52:51 +00:00
item[:items] = items
end
2016-02-29 23:52:51 +00:00
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