summaryrefslogtreecommitdiff
path: root/app/controllers/api/rows_controller.rb
blob: 543aebe971b05bfe432dfe03d6494dd2782914cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
class Api::RowsController < ApplicationController
  before_filter :check_remote_ip_address_whitelist

  def index
    @rows = Api::Row.all

    respond_to do |format|
      format.xml { render xml: @rows }
    end
  end

  def show
    if params[:user_name]
      @row = Api::Row.find_by_user_name(params[:user_name])
    else
      @row = Api::Row.find(params[:id])
    end

    respond_to do |format|
      format.xml { render xml: @row }
    end
  end

  def new
    @row = Api::Row.new

    respond_to do |format|
      format.xml { render xml: @row }
    end
  end

  def edit
    if params[:user_name]
      @row = Api::Row.find_by_user_name(params[:user_name])
    else
      @row = Api::Row.find(params[:id])
    end
  end

  def create
    @row = Api::Row.new(params[:row])

    respond_to do |format|
      if @row.save
        @row.create_a_new_gemeinschaft_user

        format.xml { render xml: @row, status: :created, location: @row }
      else
        format.xml { render xml: @row.errors, status: :unprocessable_entity }
      end
    end
  end

  def update
    if params[:user_name]
      @row = Api::Row.find_by_user_name(params[:user_name])
    else
      @row = Api::Row.find(params[:id])
    end

    respond_to do |format|
      if @row.update_attributes(params[:row])
        @row.update_user_data
        format.xml { head :no_content }
      else
        format.xml { render xml: @row.errors, status: :unprocessable_entity }
      end
    end
  end

  def destroy
    if params[:user_name]
      @row = Api::Row.find_by_user_name(params[:user_name])
    else
      @row = Api::Row.find(params[:id])
    end
    @row.destroy

    respond_to do |format|
      format.xml { head :no_content }
    end
  end

  private

  def check_remote_ip_address_whitelist
    if !(GsParameter.get('REMOTE_IP_ADDRESS_WHITELIST').empty? or GsParameter.get('REMOTE_IP_ADDRESS_WHITELIST').include?(ENV['REMOTE_ADDR']))
      redirect_to root_url
    end
  end
end