Class: Kaui::AdminAllowedUsersController
Constant Summary
EngineControllerUtil::MAXIMUM_NUMBER_OF_RECORDS_DOWNLOAD, EngineControllerUtil::SIMPLE_PAGINATION_THRESHOLD
Instance Method Summary
collapse
#check_for_redirect_to_tenant_screen, #current_ability, #current_user, #options_for_klient, #populate_account_details, #retrieve_allowed_users_for_current_user, #retrieve_tenants_for_current_user
#perform_redirect_after_error
Instance Method Details
#add_tenant ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# File 'app/controllers/kaui/admin_allowed_users_controller.rb', line 108
def add_tenant
allowed_user = Kaui::AllowedUser.find(params.require(:allowed_user).require(:id))
unless current_user.root?
redirect_to admin_allowed_user_path(allowed_user.id), alert: 'Only the root user can set tenants for user'
return
end
tenants = []
params.each_key do |tenant|
tenant_info = tenant.split('_')
next if (tenant_info.size != 2) || (tenant_info[0] != 'tenant')
tenants << tenant_info[1]
end
tenants_for_current_user = retrieve_tenants_for_current_user
tenants = Kaui::Tenant.where(id: tenants).select { |tenant| tenants_for_current_user.include?(tenant.kb_tenant_id) }.map(&:id)
allowed_user.kaui_tenant_ids = tenants
redirect_to admin_allowed_user_path(allowed_user.id), notice: 'Successfully set tenants for user'
end
|
#create ⇒ Object
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
|
# File 'app/controllers/kaui/admin_allowed_users_controller.rb', line 54
def create
@is_killbill_managed = nil
@allowed_user = Kaui::AllowedUser.new(allowed_user_params)
existing_user = Kaui::AllowedUser.find_by(kb_username: @allowed_user.kb_username)
if existing_user.blank?
if params[:external] == '1'
@allowed_user.save!
else
@allowed_user.create_in_kb!(params.require(:password),
params[:roles].blank? ? [] : params[:roles].split(','),
current_user.kb_username,
params[:reason],
params[:comment],
options_for_klient)
end
redirect_to kaui_engine.admin_allowed_user_path(@allowed_user.id), notice: 'User was successfully configured'
else
flash[:error] = "User with name #{@allowed_user.kb_username} already exists!"
@roles = roles_for_user(existing_user)
render :new and return
end
end
|
#destroy ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'app/controllers/kaui/admin_allowed_users_controller.rb', line 95
def destroy
allowed_user = Kaui::AllowedUser.find(params.require(:id))
if allowed_user
allowed_user.destroy_in_kb!(current_user.kb_username, params[:reason], params[:comment], options_for_klient)
redirect_to kaui_engine.admin_allowed_users_path, notice: 'User was successfully deleted'
else
flash[:error] = "User #{params.require(:id)} not found"
redirect_to kaui_engine.admin_allowed_users_path
end
end
|
#edit ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/controllers/kaui/admin_allowed_users_controller.rb', line 40
def edit
@allowed_user = Kaui::AllowedUser.find(params.require(:id))
@is_killbill_managed = killbill_managed?(@allowed_user, options_for_klient)
if params[:user_context].present?
context = params[:user_context]
@roles = context[:roles].to_s.split(',').compact_blank
@allowed_user.description = context[:description] if context[:description].present?
else
@roles = roles_for_user(@allowed_user)
end
end
|
#index ⇒ Object
7
8
9
10
11
12
13
|
# File 'app/controllers/kaui/admin_allowed_users_controller.rb', line 7
def index
@allowed_users = retrieve_allowed_users_for_current_user
@roles_by_user = {}
@allowed_users.each do |user|
@roles_by_user[user.kb_username] = roles_for_user(user)
end
end
|
#new ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/controllers/kaui/admin_allowed_users_controller.rb', line 25
def new
@allowed_user = Kaui::AllowedUser.new
@is_killbill_managed = true
@roles = []
return if params[:user_context].blank?
context = params[:user_context]
@allowed_user.kb_username = context[:kb_username]
@allowed_user.description = context[:description]
@roles = context[:roles].to_s.split(',').compact_blank
@external_checked = context[:external] == '1'
end
|
#show ⇒ Object
15
16
17
18
19
20
21
22
23
|
# File 'app/controllers/kaui/admin_allowed_users_controller.rb', line 15
def show
@allowed_user = Kaui::AllowedUser.find(params.require(:id))
raise ActiveRecord::RecordNotFound, "Could not find user #{@allowed_user.id}" unless current_user.root? || @allowed_user.kb_username == current_user.kb_username
@roles = roles_for_user(@allowed_user)
tenants_for_current_user = retrieve_tenants_for_current_user
@tenants = Kaui::Tenant.all.select { |tenant| tenants_for_current_user.include?(tenant.kb_tenant_id) }
end
|
#update ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'app/controllers/kaui/admin_allowed_users_controller.rb', line 80
def update
@allowed_user = Kaui::AllowedUser.find(params.require(:id))
@allowed_user.description = params[:allowed_user][:description].presence
@allowed_user.update_in_kb!(params[:password].presence,
params[:roles].presence&.split(','),
current_user.kb_username,
params[:reason],
params[:comment],
options_for_klient)
redirect_to kaui_engine.admin_allowed_user_path(@allowed_user.id), notice: 'User was successfully updated'
end
|