Class: RolloutAdmin::AdminController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rollout_admin/admin_controller.rb

Instance Method Summary collapse

Instance Method Details

#activateObject



28
29
30
31
32
33
# File 'app/controllers/rollout_admin/admin_controller.rb', line 28

def activate
  if params[:object_type] == "feature"
    $rollout.activate(params[:object].to_s)
  end
  redirect_to index_path    
end

#addObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/rollout_admin/admin_controller.rb', line 44

def add
  if params[:object_type] == "user"
    @users=[]
    params[:user].split(",").each {|id|
      puts User.find(id).inspect

      $rollout.activate_user(params[:feature], User.find(id))
      @feature = $rollout.get(params[:feature])
      @users << User.find(id)
    }

    render :json => @users
  elsif params[:object_type] == "group"
    $rollout.activate_group(params[:feature], params[:group].to_sym)
    @feature = $rollout.get(params[:feature])
    render :json => @feature.groups
  elsif params[:object_type] == "ip"
    $rollout.activate_ip(params[:feature], params[:ip].to_s)
    @feature = $rollout.get(params[:feature])
    render :json => @feature.ips
  end
end

#createObject



16
17
18
19
# File 'app/controllers/rollout_admin/admin_controller.rb', line 16

def create 
	$rollout.activate_percentage(params[:feature_name], 0)
	redirect_to index_path
end

#deactivateObject



21
22
23
24
25
26
# File 'app/controllers/rollout_admin/admin_controller.rb', line 21

def deactivate
  if params[:object_type] == "feature"
    $rollout.deactivate(params[:object].to_s)
  end
  redirect_to index_path    
end

#get_usersObject



35
36
37
38
39
40
41
42
# File 'app/controllers/rollout_admin/admin_controller.rb', line 35

def get_users
  if Object.const_defined?('User')
    @users=User.all
    render :json => @users
  else
    render :json => {'error' => 'no users defined'}
  end
end

#indexObject



8
9
10
11
12
13
14
# File 'app/controllers/rollout_admin/admin_controller.rb', line 8

def index
	@feature_list = $rollout.features
	@features = []
	@feature_list.uniq.each { |feature| 
		@features << $rollout.get(feature)
	}
end

#removeObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/controllers/rollout_admin/admin_controller.rb', line 67

def remove 
  if params[:object_type] == "user"
    @user=User.find(params[:user])
    if @user
      $rollout.deactivate_user(params[:feature], @user)
    end
    @feature = $rollout.get(params[:feature])
    render :json => @feature.users
  elsif params[:object_type] == "group"
    $rollout.deactivate_group(params[:feature], params[:group].to_sym)
    @feature = $rollout.get(params[:feature])
    render :json => @feature.groups
  elsif params[:object_type] == "ip"
    puts params[:ip]
    $rollout.deactivate_ip(params[:feature], params[:ip].to_s)
    @feature = $rollout.get(params[:feature])
    render :json => @feature.ips
  end
end

#update_percentageObject



87
88
89
90
# File 'app/controllers/rollout_admin/admin_controller.rb', line 87

def update_percentage
  $rollout.activate_percentage(params[:feature].to_sym,params[:percentage].to_i)
  render :json => {:status => "success"}
end