users_controller.rb 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  1. # Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
  2. class UsersController < ApplicationController
  3. before_action :authentication_check, except: [:create, :password_reset_send, :password_reset_verify, :image]
  4. # @path [GET] /users
  5. #
  6. # @summary Returns a list of User records.
  7. # @notes The requester has to be in the role 'Admin' or 'Agent' to
  8. # get a list of all Users. If the requester is in the
  9. # role 'Customer' only just the own User record will be returned.
  10. #
  11. # @response_message 200 [Array<User>] List of matching User records.
  12. # @response_message 401 Invalid session.
  13. def index
  14. # only allow customer to fetch him self
  15. if role?(Z_ROLENAME_CUSTOMER) && !role?(Z_ROLENAME_ADMIN) && !role?('Agent')
  16. users = User.where( id: current_user.id )
  17. else
  18. users = User.all
  19. end
  20. users_all = []
  21. users.each {|user|
  22. users_all.push User.lookup( id: user.id ).attributes_with_associations
  23. }
  24. render json: users_all, status: :ok
  25. end
  26. # @path [GET] /users/{id}
  27. #
  28. # @summary Returns the User record with the requested identifier.
  29. # @notes The requester has to be in the role 'Admin' or 'Agent' to
  30. # access all User records. If the requester is in the
  31. # role 'Customer' just the own User record is accessable.
  32. #
  33. # @parameter id(required) [Integer] The identifier matching the requested User.
  34. # @parameter full [Bool] If set a Asset structure with all connected Assets gets returned.
  35. #
  36. # @response_message 200 [User] User record matching the requested identifier.
  37. # @response_message 401 Invalid session.
  38. def show
  39. # access deny
  40. return if !permission_check
  41. if params[:full]
  42. full = User.full( params[:id] )
  43. render json: full
  44. return
  45. end
  46. user = User.find( params[:id] )
  47. render json: user
  48. end
  49. # @path [POST] /users
  50. #
  51. # @summary Creates a User record with the provided attribute values.
  52. # @notes TODO.
  53. #
  54. # @parameter User(required,body) [User] The attribute value structure needed to create a User record.
  55. #
  56. # @response_message 200 [User] Created User record.
  57. # @response_message 401 Invalid session.
  58. def create
  59. user = User.new( User.param_cleanup(params, true) )
  60. begin
  61. # check if it's first user
  62. count = User.all.count()
  63. # if it's a signup, add user to customer role
  64. if !current_user
  65. user.updated_by_id = 1
  66. user.created_by_id = 1
  67. # check if feature is enabled
  68. if !Setting.get('user_create_account')
  69. render json: { error: 'Feature not enabled!' }, status: :unprocessable_entity
  70. return
  71. end
  72. # add first user as admin/agent and to all groups
  73. group_ids = []
  74. role_ids = []
  75. if count <= 2
  76. Role.where( name: [ Z_ROLENAME_ADMIN, 'Agent', 'Chat'] ).each { |role|
  77. role_ids.push role.id
  78. }
  79. Group.all().each { |group|
  80. group_ids.push group.id
  81. }
  82. # everybody else will go as customer per default
  83. else
  84. role_ids.push Role.where( name: Z_ROLENAME_CUSTOMER ).first.id
  85. end
  86. user.role_ids = role_ids
  87. user.group_ids = group_ids
  88. # else do assignment as defined
  89. else
  90. # permission check by role
  91. return if !permission_check_by_role
  92. if params[:role_ids]
  93. user.role_ids = params[:role_ids]
  94. end
  95. if params[:group_ids]
  96. user.group_ids = params[:group_ids]
  97. end
  98. end
  99. # check if user already exists
  100. if user.email
  101. exists = User.where( email: user.email ).first
  102. if exists
  103. render json: { error: 'User already exists!' }, status: :unprocessable_entity
  104. return
  105. end
  106. end
  107. user.save!
  108. # if first user was added, set system init done
  109. if count <= 2
  110. Setting.set( 'system_init_done', true )
  111. # fetch org logo
  112. if user.email
  113. Service::Image.organization_suggest(user.email)
  114. end
  115. end
  116. # send inviteation if needed / only if session exists
  117. if params[:invite] && current_user
  118. # generate token
  119. token = Token.create( action: 'PasswordReset', user_id: user.id )
  120. # send mail
  121. data = {}
  122. data[:subject] = 'Invitation to #{config.product_name} at #{config.fqdn}'
  123. data[:body] = 'Hi #{user.firstname},
  124. I (#{current_user.firstname} #{current_user.lastname}) invite you to #{config.product_name} - the customer support / ticket system platform.
  125. Click on the following link and set your password:
  126. #{config.http_type}://#{config.fqdn}/#password_reset_verify/#{token.name}
  127. Enjoy,
  128. #{current_user.firstname} #{current_user.lastname}
  129. Your #{config.product_name} Team
  130. '
  131. # prepare subject & body
  132. [:subject, :body].each { |key|
  133. data[key.to_sym] = NotificationFactory.build(
  134. locale: user.preferences[:locale],
  135. string: data[key.to_sym],
  136. objects: {
  137. token: token,
  138. user: user,
  139. current_user: current_user,
  140. }
  141. )
  142. }
  143. # send notification
  144. NotificationFactory.send(
  145. recipient: user,
  146. subject: data[:subject],
  147. body: data[:body]
  148. )
  149. end
  150. user_new = User.find( user.id )
  151. render json: user_new, status: :created
  152. rescue => e
  153. render json: { error: e.message }, status: :unprocessable_entity
  154. end
  155. end
  156. # @path [PUT] /users/{id}
  157. #
  158. # @summary Updates the User record matching the identifier with the provided attribute values.
  159. # @notes TODO.
  160. #
  161. # @parameter id(required) [Integer] The identifier matching the requested User record.
  162. # @parameter User(required,body) [User] The attribute value structure needed to update a User record.
  163. #
  164. # @response_message 200 [User] Updated User record.
  165. # @response_message 401 Invalid session.
  166. def update
  167. # access deny
  168. return if !permission_check
  169. user = User.find( params[:id] )
  170. begin
  171. user.update_attributes( User.param_cleanup(params) )
  172. # only allow Admin's and Agent's
  173. if role?(Z_ROLENAME_ADMIN) && role?('Agent') && params[:role_ids]
  174. user.role_ids = params[:role_ids]
  175. end
  176. # only allow Admin's
  177. if role?(Z_ROLENAME_ADMIN) && params[:group_ids]
  178. user.group_ids = params[:group_ids]
  179. end
  180. # only allow Admin's and Agent's
  181. if role?(Z_ROLENAME_ADMIN) && role?('Agent') && params[:organization_ids]
  182. user.organization_ids = params[:organization_ids]
  183. end
  184. # get new data
  185. user_new = User.find( params[:id] )
  186. render json: user_new, status: :ok
  187. rescue => e
  188. render json: { error: e.message }, status: :unprocessable_entity
  189. end
  190. end
  191. # @path [DELETE] /users/{id}
  192. #
  193. # @summary Deletes the User record matching the given identifier.
  194. # @notes The requester has to be in the role 'Admin' to be able to delete a User record.
  195. #
  196. # @parameter id(required) [User] The identifier matching the requested User record.
  197. #
  198. # @response_message 200 User successfully deleted.
  199. # @response_message 401 Invalid session.
  200. def destroy
  201. return if deny_if_not_role(Z_ROLENAME_ADMIN)
  202. model_destory_render(User, params)
  203. end
  204. # @path [GET] /users/search
  205. #
  206. # @tag Search
  207. # @tag User
  208. #
  209. # @summary Searches the User matching the given expression(s).
  210. # @notes TODO: It's possible to use the SOLR search syntax.
  211. # The requester has to be in the role 'Admin' or 'Agent' to
  212. # be able to search for User records.
  213. #
  214. # @parameter term [String] The search term.
  215. # @parameter limit [Integer] The limit of search results.
  216. # @parameter role_ids(multi) [Array<String>] A list of Role identifiers to which the Users have to be allocated to.
  217. # @parameter full [Boolean] Defines if the result should be
  218. # true: { user_ids => [1,2,...], assets => {...} }
  219. # or false: [{:id => user.id, :label => "firstname lastname <email>", :value => "firstname lastname <email>"},...].
  220. #
  221. # @response_message 200 [Array<User>] A list of User records matching the search term.
  222. # @response_message 401 Invalid session.
  223. def search
  224. if role?(Z_ROLENAME_CUSTOMER) && !role?(Z_ROLENAME_ADMIN) && !role?('Agent')
  225. response_access_deny
  226. return
  227. end
  228. query_params = {
  229. query: params[:term],
  230. limit: params[:limit],
  231. current_user: current_user,
  232. }
  233. if params[:role_ids] && !params[:role_ids].empty?
  234. query_params[:role_ids] = params[:role_ids]
  235. end
  236. # do query
  237. user_all = User.search(query_params)
  238. # build result list
  239. if !params[:full]
  240. users = []
  241. user_all.each { |user|
  242. realname = user.firstname.to_s + ' ' + user.lastname.to_s
  243. if user.email && user.email.to_s != ''
  244. realname = realname + ' <' + user.email.to_s + '>'
  245. end
  246. a = { id: user.id, label: realname, value: realname }
  247. users.push a
  248. }
  249. # return result
  250. render json: users
  251. return
  252. end
  253. user_ids = []
  254. assets = {}
  255. user_all.each { |user|
  256. assets = user.assets(assets)
  257. user_ids.push user.id
  258. }
  259. # return result
  260. render json: {
  261. assets: assets,
  262. user_ids: user_ids.uniq,
  263. }
  264. end
  265. # @path [GET] /users/recent
  266. #
  267. # @tag Search
  268. # @tag User
  269. #
  270. # @summary Recent creates Users.
  271. # @notes Recent creates Users.
  272. #
  273. # @parameter limit [Integer] The limit of search results.
  274. # @parameter role_ids(multi) [Array<String>] A list of Role identifiers to which the Users have to be allocated to.
  275. # @parameter full [Boolean] Defines if the result should be
  276. # true: { user_ids => [1,2,...], assets => {...} }
  277. # or false: [{:id => user.id, :label => "firstname lastname <email>", :value => "firstname lastname <email>"},...].
  278. #
  279. # @response_message 200 [Array<User>] A list of User records matching the search term.
  280. # @response_message 401 Invalid session.
  281. def recent
  282. if role?(Z_ROLENAME_CUSTOMER) && !role?(Z_ROLENAME_ADMIN)
  283. response_access_deny
  284. return
  285. end
  286. # do query
  287. if params[:role_ids] && !params[:role_ids].empty?
  288. user_all = User.joins(:roles).where( 'roles.id' => params[:role_ids] ).where('users.id != 1').order('users.created_at DESC').limit( params[:limit] || 20 )
  289. else
  290. user_all = User.where('id != 1').order('created_at DESC').limit( params[:limit] || 20 )
  291. end
  292. # build result list
  293. if !params[:full]
  294. users = []
  295. user_all.each { |user|
  296. realname = user.firstname.to_s + ' ' + user.lastname.to_s
  297. if user.email && user.email.to_s != ''
  298. realname = realname + ' <' + user.email.to_s + '>'
  299. end
  300. a = { id: user.id, label: realname, value: realname }
  301. users.push a
  302. }
  303. # return result
  304. render json: users
  305. return
  306. end
  307. user_ids = []
  308. assets = {}
  309. user_all.each { |user|
  310. assets = user.assets(assets)
  311. user_ids.push user.id
  312. }
  313. # return result
  314. render json: {
  315. assets: assets,
  316. user_ids: user_ids.uniq,
  317. }
  318. end
  319. # @path [GET] /users/history/{id}
  320. #
  321. # @tag History
  322. # @tag User
  323. #
  324. # @summary Returns the History records of a User record matching the given identifier.
  325. # @notes The requester has to be in the role 'Admin' or 'Agent' to
  326. # get the History records of a User record.
  327. #
  328. # @parameter id(required) [Integer] The identifier matching the requested User record.
  329. #
  330. # @response_message 200 [History] The History records of the requested User record.
  331. # @response_message 401 Invalid session.
  332. def history
  333. # permissin check
  334. if !role?(Z_ROLENAME_ADMIN) && !role?('Agent')
  335. response_access_deny
  336. return
  337. end
  338. # get user data
  339. user = User.find( params[:id] )
  340. # get history of user
  341. history = user.history_get(true)
  342. # return result
  343. render json: history
  344. end
  345. =begin
  346. Resource:
  347. POST /api/v1/users/password_reset
  348. Payload:
  349. {
  350. "username": "some user name"
  351. }
  352. Response:
  353. {
  354. :message => 'ok'
  355. }
  356. Test:
  357. curl http://localhost/api/v1/users/password_reset.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"username": "some_username"}'
  358. =end
  359. def password_reset_send
  360. # check if feature is enabled
  361. if !Setting.get('user_lost_password')
  362. render json: { error: 'Feature not enabled!' }, status: :unprocessable_entity
  363. return
  364. end
  365. token = User.password_reset_send( params[:username] )
  366. if token
  367. # only if system is in develop mode, send token back to browser for browser tests
  368. if Setting.get('developer_mode') == true
  369. render json: { message: 'ok', token: token.name }, status: :ok
  370. return
  371. end
  372. # token sent to user, send ok to browser
  373. render json: { message: 'ok' }, status: :ok
  374. return
  375. end
  376. # unable to generate token
  377. render json: { message: 'failed' }, status: :ok
  378. end
  379. =begin
  380. Resource:
  381. POST /api/v1/users/password_reset_verify
  382. Payload:
  383. {
  384. "token": "SoMeToKeN",
  385. "password": "new_password"
  386. }
  387. Response:
  388. {
  389. :message => 'ok'
  390. }
  391. Test:
  392. curl http://localhost/api/v1/users/password_reset_verify.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"token": "SoMeToKeN", "password" "new_password"}'
  393. =end
  394. def password_reset_verify
  395. if params[:password]
  396. # check password policy
  397. result = password_policy(params[:password])
  398. if result != true
  399. render json: { message: 'failed', notice: result }, status: :ok
  400. return
  401. end
  402. # set new password with token
  403. user = User.password_reset_via_token( params[:token], params[:password] )
  404. else
  405. user = User.password_reset_check( params[:token] )
  406. end
  407. if user
  408. render json: { message: 'ok', user_login: user.login }, status: :ok
  409. else
  410. render json: { message: 'failed' }, status: :ok
  411. end
  412. end
  413. =begin
  414. Resource:
  415. POST /api/v1/users/password_change
  416. Payload:
  417. {
  418. "password_old": "some_password_old",
  419. "password_new": "some_password_new"
  420. }
  421. Response:
  422. {
  423. :message => 'ok'
  424. }
  425. Test:
  426. curl http://localhost/api/v1/users/password_change.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"password_old": "password_old", "password_new": "password_new"}'
  427. =end
  428. def password_change
  429. # check old password
  430. if !params[:password_old]
  431. render json: { message: 'failed', notice: ['Current password needed!'] }, status: :ok
  432. return
  433. end
  434. user = User.authenticate( current_user.login, params[:password_old] )
  435. if !user
  436. render json: { message: 'failed', notice: ['Current password is wrong!'] }, status: :ok
  437. return
  438. end
  439. # set new password
  440. if !params[:password_new]
  441. render json: { message: 'failed', notice: ['Please supply your new password!'] }, status: :ok
  442. return
  443. end
  444. # check password policy
  445. result = password_policy(params[:password_new])
  446. if result != true
  447. render json: { message: 'failed', notice: result }, status: :ok
  448. return
  449. end
  450. user.update_attributes( password: params[:password_new] )
  451. render json: { message: 'ok', user_login: user.login }, status: :ok
  452. end
  453. =begin
  454. Resource:
  455. PUT /api/v1/users/preferences.json
  456. Payload:
  457. {
  458. "language": "de",
  459. "notification": true
  460. }
  461. Response:
  462. {
  463. :message => 'ok'
  464. }
  465. Test:
  466. curl http://localhost/api/v1/users/preferences.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X PUT -d '{"language": "de", "notifications": true}'
  467. =end
  468. def preferences
  469. if !current_user
  470. render json: { message: 'No current user!' }, status: :unprocessable_entity
  471. return
  472. end
  473. if params[:user]
  474. user = User.find(current_user.id)
  475. params[:user].each {|key, value|
  476. user.preferences[key.to_sym] = value
  477. }
  478. user.save
  479. end
  480. render json: { message: 'ok' }, status: :ok
  481. end
  482. =begin
  483. Resource:
  484. DELETE /api/v1/users/account.json
  485. Payload:
  486. {
  487. "provider": "twitter",
  488. "uid": 581482342942
  489. }
  490. Response:
  491. {
  492. :message => 'ok'
  493. }
  494. Test:
  495. curl http://localhost/api/v1/users/account.json -v -u #{login}:#{password} -H "Content-Type: application/json" -X PUT -d '{"provider": "twitter", "uid": 581482342942}'
  496. =end
  497. def account_remove
  498. if !current_user
  499. render json: { message: 'No current user!' }, status: :unprocessable_entity
  500. return
  501. end
  502. # provider + uid to remove
  503. if !params[:provider]
  504. render json: { message: 'provider needed!' }, status: :unprocessable_entity
  505. return
  506. end
  507. if !params[:uid]
  508. render json: { message: 'uid needed!' }, status: :unprocessable_entity
  509. return
  510. end
  511. # remove from database
  512. record = Authorization.where(
  513. user_id: current_user.id,
  514. provider: params[:provider],
  515. uid: params[:uid],
  516. )
  517. if !record.first
  518. render json: { message: 'No record found!' }, status: :unprocessable_entity
  519. return
  520. end
  521. record.destroy_all
  522. render json: { message: 'ok' }, status: :ok
  523. end
  524. =begin
  525. Resource:
  526. GET /api/v1/users/image/8d6cca1c6bdc226cf2ba131e264ca2c7
  527. Response:
  528. <IMAGE>
  529. Test:
  530. curl http://localhost/api/v1/users/image/8d6cca1c6bdc226cf2ba131e264ca2c7 -v -u #{login}:#{password}
  531. =end
  532. def image
  533. # cache image
  534. response.headers['Expires'] = 1.year.from_now.httpdate
  535. response.headers['Cache-Control'] = 'cache, store, max-age=31536000, must-revalidate'
  536. response.headers['Pragma'] = 'cache'
  537. file = Avatar.get_by_hash( params[:hash] )
  538. if file
  539. send_data(
  540. file.content,
  541. filename: file.filename,
  542. type: file.preferences['Content-Type'] || file.preferences['Mime-Type'],
  543. disposition: 'inline'
  544. )
  545. return
  546. end
  547. # serve default image
  548. image = 'R0lGODdhMAAwAOMAAMzMzJaWlr6+vqqqqqOjo8XFxbe3t7GxsZycnAAAAAAAAAAAAAAAAAAAAAAAAAAAACwAAAAAMAAwAAAEcxDISau9OOvNu/9gKI5kaZ5oqq5s675wLM90bd94ru98TwuAA+KQAQqJK8EAgBAgMEqmkzUgBIeSwWGZtR5XhSqAULACCoGCJGwlm1MGQrq9RqgB8fm4ZTUgDBIEcRR9fz6HiImKi4yNjo+QkZKTlJWWkBEAOw=='
  549. send_data(
  550. Base64.decode64(image),
  551. filename: 'image.gif',
  552. type: 'image/gif',
  553. disposition: 'inline'
  554. )
  555. end
  556. =begin
  557. Resource:
  558. POST /api/v1/users/avatar
  559. Payload:
  560. {
  561. "avatar_full": "base64 url",
  562. }
  563. Response:
  564. {
  565. :message => 'ok'
  566. }
  567. Test:
  568. curl http://localhost/api/v1/users/avatar -v -u #{login}:#{password} -H "Content-Type: application/json" -X POST -d '{"avatar": "base64 url"}'
  569. =end
  570. def avatar_new
  571. return if !valid_session_with_user
  572. # get & validate image
  573. file_full = StaticAssets.data_url_attributes( params[:avatar_full] )
  574. file_resize = StaticAssets.data_url_attributes( params[:avatar_resize] )
  575. avatar = Avatar.add(
  576. object: 'User',
  577. o_id: current_user.id,
  578. full: {
  579. content: file_full[:content],
  580. mime_type: file_full[:mime_type],
  581. },
  582. resize: {
  583. content: file_resize[:content],
  584. mime_type: file_resize[:mime_type],
  585. },
  586. source: 'upload ' + Time.zone.now.to_s,
  587. deletable: true,
  588. )
  589. # update user link
  590. current_user.update_attributes( image: avatar.store_hash )
  591. render json: { avatar: avatar }, status: :ok
  592. end
  593. def avatar_set_default
  594. return if !valid_session_with_user
  595. # get & validate image
  596. if !params[:id]
  597. render json: { message: 'No id of avatar!' }, status: :unprocessable_entity
  598. return
  599. end
  600. # set as default
  601. avatar = Avatar.set_default( 'User', current_user.id, params[:id] )
  602. # update user link
  603. current_user.update_attributes( image: avatar.store_hash )
  604. render json: {}, status: :ok
  605. end
  606. def avatar_destroy
  607. return if !valid_session_with_user
  608. # get & validate image
  609. if !params[:id]
  610. render json: { message: 'No id of avatar!' }, status: :unprocessable_entity
  611. return
  612. end
  613. # remove avatar
  614. Avatar.remove_one( 'User', current_user.id, params[:id] )
  615. # update user link
  616. avatar = Avatar.get_default( 'User', current_user.id )
  617. current_user.update_attributes( image: avatar.store_hash )
  618. render json: {}, status: :ok
  619. end
  620. def avatar_list
  621. return if !valid_session_with_user
  622. # list of avatars
  623. result = Avatar.list( 'User', current_user.id )
  624. render json: { avatars: result }, status: :ok
  625. end
  626. private
  627. def password_policy(password)
  628. if Setting.get('password_min_size').to_i > password.length
  629. return ["Can\'t update password, it must be at least %s characters long!", Setting.get('password_min_size')]
  630. end
  631. if Setting.get('password_need_digit').to_i == 1 && password !~ /\d/
  632. return ["Can't update password, it must contain at least 1 digit!"]
  633. end
  634. if Setting.get('password_min_2_lower_2_upper_characters').to_i == 1 && ( password !~ /[A-Z].*[A-Z]/ || password !~ /[a-z].*[a-z]/ )
  635. return ["Can't update password, it must contain at least 2 lowercase and 2 uppercase characters!"]
  636. end
  637. true
  638. end
  639. def permission_check_by_role
  640. return true if role?(Z_ROLENAME_ADMIN)
  641. return true if role?('Agent')
  642. response_access_deny
  643. false
  644. end
  645. def permission_check
  646. return true if role?(Z_ROLENAME_ADMIN)
  647. return true if role?('Agent')
  648. # allow to update customer by him self
  649. return true if role?(Z_ROLENAME_CUSTOMER) && params[:id].to_i == current_user.id
  650. response_access_deny
  651. false
  652. end
  653. end