PageRenderTime 895ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/api/app/controllers/spree/api/return_authorizations_controller.rb

https://github.com/tomz/spree
Ruby | 78 lines | 67 code | 11 blank | 0 comment | 4 complexity | adfceef4ae9f7215df2b662c58cdd666 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. module Spree
  2. module Api
  3. class ReturnAuthorizationsController < Spree::Api::BaseController
  4. def create
  5. authorize! :create, ReturnAuthorization
  6. @return_authorization = order.return_authorizations.build(return_authorization_params)
  7. if @return_authorization.save
  8. respond_with(@return_authorization, status: 201, default_template: :show)
  9. else
  10. invalid_resource!(@return_authorization)
  11. end
  12. end
  13. def destroy
  14. @return_authorization = order.return_authorizations.accessible_by(current_ability, :destroy).find(params[:id])
  15. @return_authorization.destroy
  16. respond_with(@return_authorization, status: 204)
  17. end
  18. def index
  19. authorize! :admin, ReturnAuthorization
  20. @return_authorizations = order.return_authorizations.accessible_by(current_ability, :read).
  21. ransack(params[:q]).result.
  22. page(params[:page]).per(params[:per_page])
  23. respond_with(@return_authorizations)
  24. end
  25. def new
  26. authorize! :admin, ReturnAuthorization
  27. end
  28. def show
  29. authorize! :admin, ReturnAuthorization
  30. @return_authorization = order.return_authorizations.accessible_by(current_ability, :read).find(params[:id])
  31. respond_with(@return_authorization)
  32. end
  33. def update
  34. @return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
  35. if @return_authorization.update_attributes(return_authorization_params)
  36. respond_with(@return_authorization, default_template: :show)
  37. else
  38. invalid_resource!(@return_authorization)
  39. end
  40. end
  41. def receive
  42. @return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
  43. if @return_authorization.receive
  44. respond_with @return_authorization, default_template: :show
  45. else
  46. invalid_resource!(@return_authorization)
  47. end
  48. end
  49. def cancel
  50. @return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])
  51. if @return_authorization.cancel
  52. respond_with @return_authorization, default_template: :show
  53. else
  54. invalid_resource!(@return_authorization)
  55. end
  56. end
  57. private
  58. def order
  59. @order ||= Spree::Order.find_by!(number: order_id)
  60. authorize! :read, @order
  61. end
  62. def return_authorization_params
  63. params.require(:return_authorization).permit(permitted_return_authorization_attributes)
  64. end
  65. end
  66. end
  67. end