admin_role_test.rb 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. require 'browser_test_helper'
  2. class AdminRoleTest < TestCase
  3. def test_role_device
  4. @browser = browser_instance
  5. login(
  6. username: 'master@example.com',
  7. password: 'test',
  8. url: browser_url,
  9. )
  10. tasks_close_all()
  11. rand = rand(99_999_999).to_s
  12. login = "agent-role-#{rand}"
  13. firstname = "Role#{rand}"
  14. lastname = "Module#{rand}"
  15. email = "agent-role-#{rand}@example.com"
  16. password = 'agentpw'
  17. user_create(
  18. data: {
  19. login: login,
  20. firstname: firstname,
  21. lastname: lastname,
  22. email: email,
  23. password: password,
  24. },
  25. )
  26. name = "somerole#{rand}"
  27. role_create(
  28. data: {
  29. name: name,
  30. default_at_signup: false,
  31. permission: [
  32. 'admin.group',
  33. 'user_preferences.device',
  34. ],
  35. member: [login],
  36. }
  37. )
  38. logout()
  39. # flanky
  40. login(
  41. username: email,
  42. password: password,
  43. url: browser_url,
  44. )
  45. tasks_close_all()
  46. click(css: 'a[href="#current_user"]')
  47. click(css: 'a[href="#profile"]')
  48. match(
  49. css: '.content .NavBarProfile',
  50. value: 'Password',
  51. )
  52. match(
  53. css: '.content .NavBarProfile',
  54. value: 'Language',
  55. )
  56. match_not(
  57. css: '.content .NavBarProfile',
  58. value: 'Notifications',
  59. )
  60. match_not(
  61. css: '.content .NavBarProfile',
  62. value: 'Calendar',
  63. )
  64. match_not(
  65. css: '.content .NavBarProfile',
  66. value: 'Token Access',
  67. )
  68. match(
  69. css: '.content .NavBarProfile',
  70. value: 'Devices',
  71. )
  72. logout()
  73. login(
  74. username: 'master@example.com',
  75. password: 'test',
  76. url: browser_url,
  77. )
  78. role_edit(
  79. data: {
  80. name: name,
  81. active: false,
  82. }
  83. )
  84. logout()
  85. login(
  86. username: email,
  87. password: password,
  88. url: browser_url,
  89. )
  90. tasks_close_all()
  91. click(css: 'a[href="#current_user"]')
  92. click(css: 'a[href="#profile"]')
  93. match(
  94. css: '.content .NavBarProfile',
  95. value: 'Password',
  96. )
  97. match(
  98. css: '.content .NavBarProfile',
  99. value: 'Language',
  100. )
  101. match_not(
  102. css: '.content .NavBarProfile',
  103. value: 'Notifications',
  104. )
  105. match_not(
  106. css: '.content .NavBarProfile',
  107. value: 'Calendar',
  108. )
  109. match_not(
  110. css: '.content .NavBarProfile',
  111. value: 'Token Access',
  112. )
  113. match_not(
  114. css: '.content .NavBarProfile',
  115. value: 'Devices',
  116. )
  117. end
  118. def test_role_admin_user
  119. @browser = browser_instance
  120. login(
  121. username: 'agent1@example.com',
  122. password: 'test',
  123. url: browser_url,
  124. )
  125. # check if admin exists
  126. exists_not(css: '[href="#manage"]')
  127. logout()
  128. # add admin.user to agent role
  129. login(
  130. username: 'master@example.com',
  131. password: 'test',
  132. url: browser_url,
  133. )
  134. tasks_close_all()
  135. role_edit(
  136. data: {
  137. name: 'Agent',
  138. active: true,
  139. permission: {
  140. 'admin.user' => true,
  141. 'chat.agent' => true,
  142. 'cti.agent' => true,
  143. 'ticket.agent' => true,
  144. 'user_preferences' => true,
  145. },
  146. }
  147. )
  148. logout()
  149. # check if admin exists
  150. login(
  151. username: 'agent1@example.com',
  152. password: 'test',
  153. url: browser_url,
  154. )
  155. tasks_close_all()
  156. # create user
  157. random = rand(999_999_999)
  158. user_email = "admin.user.#{rand}@example.com"
  159. user_create(
  160. data: {
  161. #login: "some login #{random}",
  162. firstname: "Admin.User Firstname #{random}",
  163. lastname: "Admin.User Lastname #{random}",
  164. email: user_email,
  165. password: 'some-pass',
  166. },
  167. )
  168. # create ticket for user
  169. ticket_create(
  170. data: {
  171. customer: user_email,
  172. group: 'Users',
  173. title: 'some changes',
  174. body: 'some body 123äöü - admin.user',
  175. },
  176. )
  177. # revoke admin.user
  178. logout()
  179. login(
  180. username: 'master@example.com',
  181. password: 'test',
  182. url: browser_url,
  183. )
  184. tasks_close_all()
  185. role_edit(
  186. data: {
  187. name: 'Agent',
  188. active: true,
  189. permission: {
  190. 'admin.user' => false,
  191. 'chat.agent' => true,
  192. 'cti.agent' => true,
  193. 'ticket.agent' => true,
  194. 'user_preferences' => true,
  195. },
  196. }
  197. )
  198. logout()
  199. login(
  200. username: 'agent1@example.com',
  201. password: 'test',
  202. url: browser_url,
  203. )
  204. # check if admin exists
  205. exists_not(css: '[href="#manage"]')
  206. end
  207. # regression test for issue #2332 - Role-Filter shows inactive Roles
  208. def test_inactive_roles_do_not_show_in_role_filter
  209. name = "some role #{rand(99_999_999)}"
  210. @browser = browser_instance
  211. login(
  212. username: 'master@example.com',
  213. password: 'test',
  214. url: browser_url,
  215. )
  216. tasks_close_all()
  217. role_create(
  218. data: {
  219. name: name,
  220. active: false
  221. }
  222. )
  223. click(
  224. css: '.content.active a[href="#manage/users"]',
  225. )
  226. # an inactive role should not appear in the role filter tabs
  227. match_not(
  228. css: '.content.active .userSearch',
  229. value: name,
  230. )
  231. end
  232. end