first_steps_controller.rb 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://zammad-foundation.org/
  2. class FirstStepsController < ApplicationController
  3. 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/Colleges 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 Modues',
  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: 'Additionals 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. owner_id: User.find_by(login: '-').id,
  179. title: result[:subject],
  180. state_id: Ticket::State.find_by(name: 'new').id,
  181. priority_id: Ticket::Priority.find_by(name: '2 normal').id,
  182. )
  183. article = Ticket::Article.create(
  184. ticket_id: ticket.id,
  185. type_id: Ticket::Article::Type.find_by(name: 'phone').id,
  186. sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
  187. from: from,
  188. body: result[:body],
  189. content_type: 'text/html',
  190. internal: false,
  191. )
  192. UserInfo.current_user_id = original_user_id
  193. overview = test_overview
  194. assets = ticket.assets({})
  195. assets = article.assets(assets)
  196. assets = overview.assets(assets)
  197. render json: {
  198. overview_id: overview.id,
  199. ticket_id: ticket.id,
  200. assets: assets,
  201. }
  202. end
  203. private
  204. def test_overview
  205. Overview.find_by(name: 'Unassigned & Open')
  206. end
  207. def test_customer
  208. User.find_by(login: 'nicole.braun@zammad.org')
  209. end
  210. def access?
  211. return true if current_user.permissions?(['admin', 'ticket.agent'])
  212. render json: []
  213. false
  214. end
  215. def check_availability(result)
  216. test_ticket_active = true
  217. overview = test_overview
  218. if !overview
  219. test_ticket_active = false
  220. elsif overview.updated_by_id != 1
  221. test_ticket_active = false
  222. end
  223. if !test_customer
  224. test_ticket_active = false
  225. end
  226. if Group.where(active: true, name: 'Users').count.zero?
  227. test_ticket_active = false
  228. end
  229. return result if test_ticket_active
  230. result.each { |item|
  231. items = []
  232. item[:items].each { |local_item|
  233. next if local_item[:name] == 'Create a Test Ticket'
  234. items.push local_item
  235. }
  236. item[:items] = items
  237. }
  238. result
  239. end
  240. end