2016-02-11 01:57:27 +00:00
|
|
|
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
|
|
|
class FirstStepsController < ApplicationController
|
|
|
|
before_action :authentication_check
|
|
|
|
|
|
|
|
def index
|
2016-02-29 23:52:51 +00:00
|
|
|
return if !access?
|
2016-02-11 01:57:27 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
from_active = false
|
|
|
|
if Setting.get('form_ticket_create')
|
|
|
|
from_active = true
|
|
|
|
end
|
|
|
|
twitter_active = false
|
|
|
|
if Channel.where(area: 'Twitter::Account').count > 0
|
|
|
|
twitter_active = true
|
|
|
|
end
|
|
|
|
facebook_active = false
|
|
|
|
if Channel.where(area: 'Facebook::Account').count > 0
|
|
|
|
facebook_active = true
|
|
|
|
end
|
|
|
|
email_active = false
|
|
|
|
if Channel.where(area: 'Email::Account').count > 0
|
|
|
|
email_active = true
|
|
|
|
end
|
|
|
|
text_module_active = false
|
|
|
|
if TextModule.count > 0
|
|
|
|
text_module_active = true
|
|
|
|
end
|
|
|
|
macro_active = false
|
|
|
|
if Macro.count > 1
|
|
|
|
macro_active = true
|
|
|
|
end
|
|
|
|
|
|
|
|
if current_user.role?('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/Colleges to help working on Tickets',
|
|
|
|
checked: invite_agents,
|
2016-02-17 18:36:33 +00:00
|
|
|
location: '#',
|
|
|
|
class: 'js-inviteAgent',
|
2016-02-11 01:57:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Invite Customers to create issues in Zammad',
|
|
|
|
checked: invite_customers,
|
2016-02-17 18:36:33 +00:00
|
|
|
location: '#',
|
|
|
|
class: 'js-inviteCustomer',
|
2016-02-11 01:57:27 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
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',
|
2016-02-11 01:57:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Create Text Modues',
|
|
|
|
checked: text_module_active,
|
|
|
|
location: '#manage/text_modules',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Create Macros',
|
|
|
|
checked: macro_active,
|
|
|
|
location: '#manage/macros',
|
|
|
|
},
|
2016-03-04 11:01:26 +00:00
|
|
|
#{
|
|
|
|
# name: 'Create Overviews',
|
|
|
|
# checked: false,
|
|
|
|
# location: '#manage/overviews',
|
|
|
|
#},
|
2016-02-11 01:57:27 +00:00
|
|
|
],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Additionals 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: from_active,
|
|
|
|
location: '#channels/form',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2016-02-29 23:52:51 +00:00
|
|
|
check_availability(result)
|
|
|
|
|
2016-02-11 01:57:27 +00:00
|
|
|
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',
|
2016-02-11 01:57:27 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Invite Customers to create issues in Zammad',
|
|
|
|
checked: invite_customers,
|
2016-02-17 18:36:33 +00:00
|
|
|
location: '#',
|
|
|
|
class: 'js-inviteCustomer',
|
2016-02-11 01:57:27 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2016-02-29 23:52:51 +00:00
|
|
|
check_availability(result)
|
|
|
|
|
2016-02-11 01:57:27 +00:00
|
|
|
render json: result
|
|
|
|
end
|
|
|
|
|
2016-02-29 23:52:51 +00:00
|
|
|
def test_ticket
|
|
|
|
return if !access?
|
|
|
|
|
|
|
|
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.preferences[:locale] || 'en-us',
|
|
|
|
objects: {
|
|
|
|
agent: agent,
|
|
|
|
customer: customer,
|
|
|
|
},
|
|
|
|
raw: true,
|
|
|
|
)
|
|
|
|
UserInfo.current_user_id = customer.id
|
|
|
|
ticket = Ticket.create(
|
2016-03-09 07:03:34 +00:00
|
|
|
group_id: Group.find_by(active: true, name: 'Users').id,
|
2016-02-29 23:52:51 +00:00
|
|
|
customer_id: customer.id,
|
|
|
|
owner_id: User.find_by(login: '-').id,
|
|
|
|
title: result[:subject],
|
|
|
|
state_id: Ticket::State.find_by(name: 'new').id,
|
|
|
|
priority_id: Ticket::Priority.find_by(name: '2 normal').id,
|
|
|
|
)
|
|
|
|
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')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_customer
|
|
|
|
User.find_by(login: 'nicole.braun@zammad.org')
|
|
|
|
end
|
|
|
|
|
|
|
|
def access?
|
|
|
|
return true if current_user.role?(%w(Agent Admin))
|
|
|
|
render json: []
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_availability(result)
|
|
|
|
test_ticket_active = true
|
|
|
|
overview = test_overview
|
|
|
|
|
|
|
|
if !overview
|
|
|
|
test_ticket_active = false
|
|
|
|
elsif overview.updated_by_id != 1
|
|
|
|
test_ticket_active = false
|
|
|
|
end
|
|
|
|
if !test_customer
|
|
|
|
test_ticket_active = false
|
|
|
|
end
|
2016-07-26 22:02:28 +00:00
|
|
|
if Group.where(active: true, name: 'Users').count.zero?
|
2016-02-29 23:52:51 +00:00
|
|
|
test_ticket_active = false
|
|
|
|
end
|
|
|
|
return result if test_ticket_active
|
2016-06-30 20:04:48 +00:00
|
|
|
result.each { |item|
|
2016-02-29 23:52:51 +00:00
|
|
|
items = []
|
2016-06-30 20:04:48 +00:00
|
|
|
item[:items].each { |local_item|
|
2016-02-29 23:52:51 +00:00
|
|
|
next if local_item[:name] == 'Create a Test Ticket'
|
|
|
|
items.push local_item
|
|
|
|
}
|
|
|
|
item[:items] = items
|
|
|
|
}
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2016-02-11 01:57:27 +00:00
|
|
|
end
|