first_steps_controller.rb 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class FirstStepsController < ApplicationController
  3. prepend_before_action :authentication_check
  4. def index
  5. return if !access?
  6. invite_agents = false
  7. #if User.of_role('Agent').count > 2
  8. # invite_agents = true
  9. #end
  10. invite_customers = false
  11. #if User.of_role('Customer').count > 2
  12. # invite_customers = true
  13. #end
  14. chat_active = false
  15. if Setting.get('chat')
  16. chat_active = true
  17. end
  18. from_active = false
  19. if Setting.get('form_ticket_create')
  20. from_active = true
  21. end
  22. twitter_active = false
  23. if Channel.where(area: 'Twitter::Account').count.positive?
  24. twitter_active = true
  25. end
  26. facebook_active = false
  27. if Channel.where(area: 'Facebook::Account').count.positive?
  28. facebook_active = true
  29. end
  30. email_active = false
  31. if Channel.where(area: 'Email::Account').count.positive?
  32. email_active = true
  33. end
  34. text_module_active = false
  35. if TextModule.count.positive?
  36. text_module_active = true
  37. end
  38. macro_active = false
  39. if Macro.count > 1
  40. macro_active = true
  41. end
  42. if current_user.permissions?('admin')
  43. result = [
  44. {
  45. name: 'Configuration',
  46. items: [
  47. {
  48. name: 'Branding',
  49. checked: true,
  50. location: '#settings/branding',
  51. },
  52. {
  53. name: 'Your Email Configuration',
  54. checked: email_active,
  55. location: '#channels/email',
  56. },
  57. {
  58. name: 'Invite agents/colleagues to help working on tickets',
  59. checked: invite_agents,
  60. location: '#',
  61. class: 'js-inviteAgent',
  62. },
  63. {
  64. name: 'Invite customers to create issues in Zammad',
  65. checked: invite_customers,
  66. location: '#',
  67. class: 'js-inviteCustomer',
  68. },
  69. ],
  70. },
  71. {
  72. name: 'How to use it',
  73. items: [
  74. {
  75. name: 'Intro',
  76. checked: true,
  77. location: '#clues',
  78. },
  79. {
  80. name: 'Create a Test Ticket',
  81. checked: false,
  82. location: '#',
  83. class: 'js-testTicket',
  84. },
  85. {
  86. name: 'Create Text Modules',
  87. checked: text_module_active,
  88. location: '#manage/text_modules',
  89. },
  90. {
  91. name: 'Create Macros',
  92. checked: macro_active,
  93. location: '#manage/macros',
  94. },
  95. #{
  96. # name: 'Create Overviews',
  97. # checked: false,
  98. # location: '#manage/overviews',
  99. #},
  100. ],
  101. },
  102. {
  103. name: 'Additional Channels',
  104. items: [
  105. {
  106. name: 'Twitter',
  107. checked: twitter_active,
  108. location: '#channels/twitter',
  109. },
  110. {
  111. name: 'Facebook',
  112. checked: facebook_active,
  113. location: '#channels/facebook',
  114. },
  115. {
  116. name: 'Chat',
  117. checked: chat_active,
  118. location: '#channels/chat',
  119. },
  120. {
  121. name: 'Online Forms',
  122. checked: from_active,
  123. location: '#channels/form',
  124. },
  125. ],
  126. },
  127. ]
  128. check_availability(result)
  129. render json: result
  130. return
  131. end
  132. result = [
  133. {
  134. name: 'How to use it',
  135. items: [
  136. {
  137. name: 'Intro',
  138. checked: true,
  139. location: '#clues',
  140. },
  141. {
  142. name: 'Create a Test Ticket',
  143. checked: false,
  144. location: '#',
  145. class: 'js-testTicket',
  146. },
  147. {
  148. name: 'Invite customers to create issues in Zammad',
  149. checked: invite_customers,
  150. location: '#',
  151. class: 'js-inviteCustomer',
  152. },
  153. ],
  154. },
  155. ]
  156. check_availability(result)
  157. render json: result
  158. end
  159. def test_ticket
  160. return if !access?
  161. agent = current_user
  162. customer = test_customer
  163. from = "#{customer.fullname} <#{customer.email}>"
  164. original_user_id = UserInfo.current_user_id
  165. result = NotificationFactory::Mailer.template(
  166. template: 'test_ticket',
  167. locale: agent.preferences[:locale] || 'en-us',
  168. objects: {
  169. agent: agent,
  170. customer: customer,
  171. },
  172. raw: true,
  173. )
  174. UserInfo.current_user_id = customer.id
  175. ticket = Ticket.create(
  176. group_id: Group.find_by(active: true, name: 'Users').id,
  177. customer_id: customer.id,
  178. title: result[:subject],
  179. )
  180. article = Ticket::Article.create(
  181. ticket_id: ticket.id,
  182. type_id: Ticket::Article::Type.find_by(name: 'phone').id,
  183. sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
  184. from: from,
  185. body: result[:body],
  186. content_type: 'text/html',
  187. internal: false,
  188. )
  189. UserInfo.current_user_id = original_user_id
  190. overview = test_overview
  191. assets = ticket.assets({})
  192. assets = article.assets(assets)
  193. assets = overview.assets(assets)
  194. render json: {
  195. overview_id: overview.id,
  196. ticket_id: ticket.id,
  197. assets: assets,
  198. }
  199. end
  200. private
  201. def test_overview
  202. Overview.find_by(name: 'Unassigned & Open')
  203. end
  204. def test_customer
  205. User.find_by(login: 'nicole.braun@zammad.org')
  206. end
  207. def access?
  208. return true if current_user.permissions?(['admin', 'ticket.agent'])
  209. render json: []
  210. false
  211. end
  212. def check_availability(result)
  213. test_ticket_active = true
  214. overview = test_overview
  215. if !overview
  216. test_ticket_active = false
  217. elsif overview.updated_by_id != 1
  218. test_ticket_active = false
  219. end
  220. if !test_customer
  221. test_ticket_active = false
  222. end
  223. if Group.where(active: true, name: 'Users').count.zero?
  224. test_ticket_active = false
  225. end
  226. return result if test_ticket_active
  227. result.each { |item|
  228. items = []
  229. item[:items].each { |local_item|
  230. next if local_item[:name] == 'Create a Test Ticket'
  231. items.push local_item
  232. }
  233. item[:items] = items
  234. }
  235. result
  236. end
  237. end