Advertisement
Guest User

Untitled

a guest
Mar 8th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. class EquipmentController < ApplicationController
  2. before_action :set_equipment, only: [:show, :edit, :update, :destroy]
  3. skip_before_action :verify_authenticity_token
  4. before_filter :authenticate_admin_user!, only: [:index, :edit, :update, :destroy] unless Rails.env.test? # Permissions for authenticated users to add, edit, view, update and destroy
  5.  
  6. # GET /equipment
  7. # GET /equipment.json
  8. def index
  9. @equipment = Equipment.order("created_at DESC").search(params[:search]).paginate(:page => params[:page], :per_page => 10)
  10. end
  11.  
  12. # GET /equipment/1
  13. # GET /equipment/1.json
  14. def show
  15. end
  16.  
  17. # GET /equipment/new
  18. def new
  19. @equipment = Equipment.new
  20. end
  21.  
  22. # GET /equipment/1/edit
  23. def edit
  24. end
  25.  
  26. # POST /equipment
  27. # POST /equipment.json
  28. def create
  29. @equipment_params = getParams(equipment_params)
  30. @equipment = Equipment.new(@equipment_params)
  31.  
  32. respond_to do |format|
  33. if @equipment.save
  34. unless Rails.env.test? # Don't send mails if in test
  35. ItEquipmentMailer.send_IT_equipment_email(@equipment).deliver #if !@equipment.equipment_requested.empty? && @equipment.computer_type == 'Other'
  36. ItEquipmentMailer.send_phone_email(@equipment).deliver if @equipment.brli_cell_phone
  37. ItEquipmentMailer.send_desk_equipment_email(@equipment).deliver if @equipment.desk_equipment
  38. end
  39. format.html { redirect_to @equipment, notice: 'Equipment was successfully created.' }
  40. format.json { render :show, status: :created, location: @equipment }
  41. else
  42. @user_id = params[:equipment][:user_id]
  43. format.html { render :new }
  44. format.json { render json: @equipment.errors, status: :unprocessable_entity }
  45. end
  46. end
  47. end
  48.  
  49. # PATCH/PUT /equipment/1
  50. # PATCH/PUT /equipment/1.json
  51. def update
  52. @equipment_params = getParams(equipment_params)
  53.  
  54. respond_to do |format|
  55. unless Rails.env.test? || Rails.env.development? # Don't send mails if in test
  56. ItEquipmentMailer.send_IT_equipment_email(@equipment).deliver
  57. ItEquipmentMailer.send_phone_email(@equipment).deliver if @equipment.brli_cell_phone
  58. ItEquipmentMailer.send_desk_equipment_email(@equipment).deliver if @equipment.desk_equipment
  59. end
  60. if @equipment.update(@equipment_params)
  61. format.html { redirect_to @equipment, notice: 'Equipment was successfully updated.' }
  62. format.json { render :show, status: :ok, location: @equipment }
  63. else
  64. format.html { render :edit }
  65. format.json { render json: @equipment.errors, status: :unprocessable_entity }
  66. end
  67. end
  68. end
  69.  
  70. # DELETE /equipment/1
  71. # DELETE /equipment/1.json
  72. def destroy
  73. @equipment.destroy
  74. respond_to do |format|
  75. format.html { redirect_to equipment_index_url, notice: 'Equipment was successfully destroyed.' }
  76. format.json { head :no_content }
  77. end
  78. end
  79.  
  80. private
  81. # Use callbacks to share common setup or constraints between actions.
  82. def set_equipment
  83. @equipment = Equipment.find(params[:id])
  84. end
  85.  
  86. # Never trust parameters from the scary internet, only allow the white list through.
  87. def equipment_params
  88. params.require(:equipment).permit({:desk_phone_authorization => [], :desk_equipment => [], :groups_privs => []},:computer_type, :phone, :brli_cell_phone, :laptop_notes, :desktop_notes, :supervisor_email, :manager_email, :user_id, :dept_code, :location, :shared_folder, :email_group_access, :other, :floor, :office_num, :remote, :hiring_manager, :address).merge(desk_phone_authorization: params[:desk_phone_authorization], desk_equipment: params[:desk_equipment], groups_privs: params[:groups_privs])
  89. end
  90.  
  91. def getParams(equipment_params)
  92. if equipment_params[:desk_phone_authorization]
  93. dpa = equipment_params[:desk_phone_authorization]
  94. dpa_s = dpa.join(',')
  95. equipment_params[:desk_phone_authorization] = dpa_s
  96. end
  97.  
  98. if equipment_params[:desk_equipment]
  99. de = equipment_params[:desk_equipment]
  100. de_s = de.join(',')
  101. equipment_params[:desk_equipment] = de_s
  102. end
  103.  
  104. # Parse desktop_authorization groups and privileges elements
  105. equipment_params[:groups_privs] = equipment_params[:groups_privs].join(",") if equipment_params[:groups_privs]
  106.  
  107. return equipment_params
  108. end
  109. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement