first_steps_controller.rb 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class FirstStepsController < ApplicationController
  3. prepend_before_action :authentication_check
  4. before_action -> { render json: [] }, if: -> { !authorized? }
  5. def index
  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. form_active = false
  19. if Setting.get('form_ticket_create')
  20. form_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: form_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. agent = current_user
  161. customer = test_customer
  162. from = Channel::EmailBuild.recipient_line customer.fullname, customer.email
  163. original_user_id = UserInfo.current_user_id
  164. result = NotificationFactory::Mailer.template(
  165. template: 'test_ticket',
  166. locale: agent.locale,
  167. objects: {
  168. agent: agent,
  169. customer: customer,
  170. },
  171. raw: true,
  172. )
  173. UserInfo.current_user_id = customer.id
  174. ticket = Ticket.create!(
  175. group_id: Group.find_by(active: true, name: 'Users').id,
  176. customer_id: customer.id,
  177. title: result[:subject],
  178. )
  179. article = Ticket::Article.create!(
  180. ticket_id: ticket.id,
  181. type_id: Ticket::Article::Type.find_by(name: 'phone').id,
  182. sender_id: Ticket::Article::Sender.find_by(name: 'Customer').id,
  183. from: from,
  184. body: result[:body],
  185. content_type: 'text/html',
  186. internal: false,
  187. )
  188. UserInfo.current_user_id = original_user_id
  189. overview = test_overview
  190. assets = ticket.assets({})
  191. assets = article.assets(assets)
  192. assets = overview.assets(assets)
  193. render json: {
  194. overview_id: overview.id,
  195. ticket_id: ticket.id,
  196. assets: assets,
  197. }
  198. end
  199. private
  200. def test_overview
  201. Overview.find_by(name: __('Unassigned & Open Tickets'))
  202. end
  203. def test_customer
  204. User.find_by(login: 'nicole.braun@zammad.org')
  205. end
  206. def check_availability(result)
  207. return result if test_ticket_active?
  208. result.each do |item|
  209. items = []
  210. item[:items].each do |local_item|
  211. next if local_item[:name] == 'Create a Test Ticket'
  212. items.push local_item
  213. end
  214. item[:items] = items
  215. end
  216. result
  217. end
  218. def test_ticket_active?
  219. overview = test_overview
  220. return false if !overview
  221. return false if overview.updated_by_id != 1
  222. return false if !test_customer
  223. return false if Group.where(active: true, name: 'Users').count.zero?
  224. true
  225. end
  226. end