Class: Kaui::AdminTenantsController
- Inherits:
-
EngineController
- Object
- EngineController
- Kaui::AdminTenantsController
- Defined in:
- app/controllers/kaui/admin_tenants_controller.rb
Instance Method Summary collapse
- #add_allowed_user ⇒ Object
- #allowed_users ⇒ Object
- #catalog_by_effective_date ⇒ Object
- #create ⇒ Object
- #create_simple_plan ⇒ Object
- #delete_catalog ⇒ Object
- #delete_overdue_config ⇒ Object
- #display_catalog_xml ⇒ Object
- #display_overdue_xml ⇒ Object
- #download_catalog_xml ⇒ Object
- #index ⇒ Object
- #invoice_template ⇒ Object
- #modify_overdue_config ⇒ Object
- #new ⇒ Object
- #new_catalog ⇒ Object
- #new_overdue_config ⇒ Object
- #new_plan_currency ⇒ Object
- #remove_allowed_user ⇒ Object
- #set_clock ⇒ Object
- #show ⇒ Object
- #switch_tenant ⇒ Object
- #upload_catalog ⇒ Object
- #upload_catalog_translation ⇒ Object
- #upload_invoice_template ⇒ Object
- #upload_invoice_translation ⇒ Object
- #upload_overdue_config ⇒ Object
- #upload_plugin_config ⇒ Object
Instance Method Details
#add_allowed_user ⇒ Object
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 508 def add_allowed_user current_tenant = safely_find_tenant_by_id(params[:tenant_id]) allowed_user = Kaui::AllowedUser.find_by(kb_username: params.require(:allowed_user).require(:kb_username)) unless current_user.root? flash[:error] = 'Only the root user can add users from tenants' redirect_to admin_tenant_path(current_tenant.id) return end if allowed_user.nil? flash[:error] = "User #{params.require(:allowed_user).require(:kb_username)} does not exist!" redirect_to admin_tenant_path(current_tenant.id) return end tenants_ids = allowed_user.kaui_tenants.map(&:id) || [] tenants_ids << current_tenant.id allowed_user.kaui_tenant_ids = tenants_ids redirect_to admin_tenant_path(current_tenant.id), notice: 'Allowed user was successfully added' end |
#allowed_users ⇒ Object
530 531 532 533 534 535 536 537 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 530 def allowed_users json_response do tenant = safely_find_tenant_by_id(params[:tenant_id]) actual_allowed_users = tenant.kaui_allowed_users.map(&:id) retrieve_allowed_users_for_current_user.reject { |au| actual_allowed_users.include? au.id } end end |
#catalog_by_effective_date ⇒ Object
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 554 def catalog_by_effective_date json_response do current_tenant = safely_find_tenant_by_id(params[:id]) effective_date = params.require(:effective_date) = [:api_key] = current_tenant.api_key [:api_secret] = current_tenant.api_secret catalog = [] result = begin Kaui::Catalog.get_catalog_json(false, effective_date, nil, ) rescue StandardError catalog = [] end # convert result to a full hash since dynamic attributes of a class are ignored when converting to json result.each do |data| plans = data[:plans].map do |plan| plan.instance_variables.to_h { |var| [var.to_s.delete('@'), plan.instance_variable_get(var)] } end catalog << { version_date: data[:version_date], currencies: data[:currencies], plans: } end { catalog: } end end |
#create ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 110 def create param_tenant = params[:tenant] old_tenant = Kaui::Tenant.find_by(name: param_tenant[:name]) || Kaui::Tenant.find_by(api_key: param_tenant[:api_key]) if old_tenant old_tenant.kaui_allowed_users << Kaui::AllowedUser.where(kb_username: current_user.kb_username).first_or_create redirect_to admin_tenant_path(old_tenant[:id]), notice: 'Tenant was successfully configured' and return end begin = new_tenant = nil begin [:api_key] = param_tenant[:api_key] [:api_secret] = param_tenant[:api_secret] new_tenant = Kaui::AdminTenant.find_by_api_key(param_tenant[:api_key], ) rescue KillBillClient::API::Unauthorized, KillBillClient::API::NotFound, KillBillClient::API::InternalServerError => e # Create the tenant in Kill Bill if e.instance_of?(KillBillClient::API::InternalServerError) && !e.&.include?('TenantCacheLoader cannot find value') flash[:error] = "Internal server error while retrieving tenant: #{as_string(e)}" redirect_to admin_tenants_path and return end new_tenant = Kaui::AdminTenant.new new_tenant.external_key = param_tenant[:name] new_tenant.api_key = param_tenant[:api_key] new_tenant.api_secret = param_tenant[:api_secret] new_tenant = new_tenant.create(false, [:username], nil, comment, ) end # Transform object to Kaui model tenant_model = Kaui::Tenant.new tenant_model.name = param_tenant[:name] tenant_model.api_key = param_tenant[:api_key] tenant_model.api_secret = param_tenant[:api_secret] tenant_model.kb_tenant_id = new_tenant.tenant_id # Save in KAUI tables tenant_model.save! # Make sure at least the current user can access the tenant tenant_model.kaui_allowed_users << Kaui::AllowedUser.where(kb_username: current_user.kb_username).first_or_create rescue KillBillClient::API::Conflict => _e # tenant api_key was found but has a wrong api_secret flash[:error] = "Submitted credentials for #{param_tenant[:api_key]} did not match the expected credentials." redirect_to admin_tenants_path and return rescue StandardError => e flash[:error] = "Failed to create the tenant: #{as_string(e)}" redirect_to admin_tenants_path and return end # Select the tenant, see TenantsController session[:kb_tenant_id] = tenant_model.kb_tenant_id session[:kb_tenant_name] = tenant_model.name session[:tenant_id] = tenant_model.id redirect_to admin_tenant_path(tenant_model[:id]), notice: 'Tenant was successfully configured' end |
#create_simple_plan ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 258 def create_simple_plan = fetch_state_for_new_catalog_screen() simple_plan = params.require(:simple_plan).permit!.to_h.compact_blank # Fix issue in Rails where first entry in the multi-select array is an empty string simple_plan['available_base_products']&.reject!(&:blank?) @simple_plan = Kaui::SimplePlan.new(simple_plan) valid = true # Validate new simple plan # https://github.com/killbill/killbill-admin-ui/issues/247 if @available_base_products.include?(@simple_plan.plan_id) flash.now[:error] = "Error while creating plan: invalid plan name (#{@simple_plan.plan_id} is a BASE product already)" valid = false elsif @available_ao_products.include?(@simple_plan.plan_id) flash.now[:error] = "Error while creating plan: invalid plan name (#{@simple_plan.plan_id} is an ADD_ON product already)" valid = false elsif @available_standalone_products.include?(@simple_plan.plan_id) flash.now[:error] = "Error while creating plan: invalid plan name (#{@simple_plan.plan_id} is a STANDALONE product already)" valid = false elsif @all_plans.include?(@simple_plan.product_name) flash.now[:error] = "Error while creating plan: invalid product name (#{@simple_plan.product_name} is a plan name already)" valid = false elsif @all_plans.include?(@simple_plan.plan_id) flash.now[:error] = "Error while creating plan: plan #{@simple_plan.plan_id} already exists" valid = false elsif @available_base_products.include?(@simple_plan.product_name) && @simple_plan.product_category != 'BASE' flash.now[:error] = "Error while creating plan: product #{@simple_plan.product_name} is a BASE product" valid = false elsif @available_ao_products.include?(@simple_plan.product_name) && @simple_plan.product_category != 'ADD_ON' flash.now[:error] = "Error while creating plan: product #{@simple_plan.product_name} is an ADD_ON product" valid = false elsif @available_standalone_products.include?(@simple_plan.product_name) && @simple_plan.product_category != 'STANDALONE' flash.now[:error] = "Error while creating plan: product #{@simple_plan.product_name} is a STANDALONE product" valid = false end if valid begin Kaui::Catalog.add_tenant_catalog_simple_plan(@simple_plan, [:username], nil, comment, ) redirect_to admin_tenant_path(@tenant.id), notice: 'Catalog plan was successfully added' rescue StandardError => e flash.now[:error] = "Error while creating plan: #{as_string(e)}" render action: :new_catalog end else render action: :new_catalog end end |
#delete_catalog ⇒ Object
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 209 def delete_catalog tenant = safely_find_tenant_by_id(params[:id]) = [:api_key] = tenant.api_key [:api_secret] = tenant.api_secret begin Kaui::Catalog.delete_catalog([:username], 'KAUI wrong catalog', comment, ) rescue NoMethodError => _e flash[:error] = 'Failed to delete catalog: only available in KB 0.19+ versions' redirect_to admin_tenants_path and return end redirect_to admin_tenant_path(tenant.id), notice: 'Catalog was successfully deleted' end |
#delete_overdue_config ⇒ Object
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 376 def delete_overdue_config current_tenant = safely_find_tenant_by_id(params[:id]) = [:api_key] = current_tenant.api_key [:api_secret] = current_tenant.api_secret begin Kaui::AdminTenant.delete_tenant_user_key_value('OVERDUE_CONFIG', [:username], nil, comment, ) rescue StandardError => e flash[:error] = "Failed to delete overdue config: #{as_string(e)}" redirect_to admin_tenant_new_overdue_config_path(id: current_tenant.id) and return end flash[:overdue_deleted] = true redirect_to admin_tenant_path(current_tenant.id, active_tab: 'OverdueShow'), notice: I18n.t('flashes.notices.overdue_deleted_successfully') end |
#display_catalog_xml ⇒ Object
539 540 541 542 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 539 def display_catalog_xml catalog_xml = fetch_catalog_xml(params[:id], params.require(:effective_date)) render xml: catalog_xml end |
#display_overdue_xml ⇒ Object
550 551 552 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 550 def display_overdue_xml render xml: params.require(:xml) end |
#download_catalog_xml ⇒ Object
544 545 546 547 548 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 544 def download_catalog_xml effective_date = params.require(:effective_date) catalog_xml = fetch_catalog_xml(params[:id], effective_date) send_data catalog_xml, filename: "catalog_#{effective_date}.xml", type: :xml end |
#index ⇒ Object
7 8 9 10 11 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 7 def index # Display the configured tenants in KAUI (which could be different than the existing tenants known by Kill Bill) 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 |
#invoice_template ⇒ Object
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 394 def invoice_template current_tenant = safely_find_tenant_by_id(params[:id]) = [:api_key] = current_tenant.api_key [:api_secret] = current_tenant.api_secret template = Kaui::AdminTenant.get_invoice_template(false, ) if template.present? render body: template, content_type: 'text/html' else render plain: 'No invoice template found', status: :not_found end end |
#modify_overdue_config ⇒ Object
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 333 def modify_overdue_config current_tenant = safely_find_tenant_by_id(params[:id]) = [:api_key] = current_tenant.api_key [:api_secret] = current_tenant.api_secret overdue_params = params[:kill_bill_client_model_overdue]&.permit! view_form_model = overdue_params&.to_h&.compact_blank || {} view_form_model['states'] = view_form_model['states'].values if view_form_model['states'].present? if view_form_model['states'].blank? Kaui::AdminTenant.delete_tenant_user_key_value('OVERDUE_CONFIG', [:username], nil, comment, ) flash[:overdue_deleted] = true redirect_to admin_tenant_path(current_tenant.id, active_tab: 'OverdueShow'), notice: I18n.t('flashes.notices.overdue_updated_successfully') else overdue = Kaui::Overdue.from_overdue_form_model(view_form_model) Kaui::Overdue.upload_tenant_overdue_config_json(overdue.to_json, [:username], nil, comment, ) redirect_to admin_tenant_path(current_tenant.id, active_tab: 'OverdueShow'), notice: I18n.t('flashes.notices.overdue_added_successfully') end end |
#new ⇒ Object
106 107 108 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 106 def new @tenant = Kaui::Tenant.new end |
#new_catalog ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 197 def new_catalog = fetch_state_for_new_catalog_screen() @simple_plan = Kaui::SimplePlan.new({ product_category: 'BASE', amount: 0, trial_length: 0, currency: 'USD', billing_period: 'MONTHLY' }) end |
#new_overdue_config ⇒ Object
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 310 def new_overdue_config @tenant = safely_find_tenant_by_id(params[:id]) = [:api_key] = @tenant.api_key [:api_secret] = @tenant.api_secret @overdue_config_exists = false begin @overdue = Kaui::Overdue.get_overdue_json() @overdue_corrupted = false @overdue_config_exists = @overdue.overdue_states.present? && !@overdue.has_states rescue KillBillClient::API::NotFound @overdue = KillBillClient::Model::Overdue.new.tap { |o| o.overdue_states = [] } @overdue_corrupted = false rescue StandardError => e Rails.logger.warn("Failed to load overdue configuration for tenant #{@tenant.id}: #{e.class}: #{e.}") @overdue = KillBillClient::Model::Overdue.new.tap { |o| o.overdue_states = [] } @overdue_corrupted = true @overdue_config_exists = true flash.now[:warning] = 'The existing overdue configuration is corrupted and cannot be loaded. Use the XML upload below to replace it with a valid configuration.' end end |
#new_plan_currency ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 226 def new_plan_currency @tenant = safely_find_tenant_by_id(params[:id]) is_plan_id_found = false plan_id = params[:plan_id] product = nil = [:api_key] = @tenant.api_key [:api_secret] = @tenant.api_secret catalog = Kaui::Catalog.get_catalog_json(true, nil, nil, ) # seek if plan id exists catalog.products.each do |p| p.plans.each { |plan| is_plan_id_found |= plan.name == plan_id } if is_plan_id_found product = p break end end unless is_plan_id_found flash[:error] = "Plan id #{plan_id} was not found." redirect_to admin_tenant_path(@tenant[:id]) end @simple_plan = Kaui::SimplePlan.new @simple_plan.plan_id = params[:plan_id] @simple_plan.product_name = product.name if product end |
#remove_allowed_user ⇒ Object
494 495 496 497 498 499 500 501 502 503 504 505 506 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 494 def remove_allowed_user current_tenant = safely_find_tenant_by_id(params[:id]) au = Kaui::AllowedUser.find(params.require(:allowed_user).require(:id)) unless current_user.root? render json: { alert: 'Only the root user can remove users from tenants' }.to_json, status: :unauthorized return end # remove the association au.kaui_tenants.delete current_tenant render json: '{}', status: :ok end |
#set_clock ⇒ Object
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 585 def set_clock @tenant = safely_find_tenant_by_id(params[:id]) if params[:commit] == 'Submit' date = Date.parse(params[:new_date]).strftime('%Y-%m-%d') msg = I18n.t('flashes.notices.clock_updated_successfully', new_date: date) else date = nil msg = I18n.t('flashes.notices.clock_reset_successfully') end begin Kaui::Admin.set_clock(date, nil, ) rescue KillBillClient::API::NotFound flash[:error] = 'Failed to set current KB clock: Kill Bill server must be started with system property org.killbill.server.test.mode=true' redirect_to admin_tenant_path(@tenant.id) and return end redirect_to admin_tenant_path(@tenant.id), notice: msg end |
#show ⇒ Object
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 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 13 def show @tenant = safely_find_tenant_by_id(params[:id]) @allowed_users = @tenant.kaui_allowed_users & retrieve_allowed_users_for_current_user # Get available users that can be added to this tenant actual_allowed_users_ids = (@tenant.kaui_allowed_users || []).map(&:id) @available_users = retrieve_allowed_users_for_current_user.reject { |au| actual_allowed_users_ids.include? au.id } configure_tenant_if_nil(@tenant) # Fetch clock data for the clock component begin @clock = Kaui::Admin.get_clock(nil, ) rescue KillBillClient::API::NotFound flash[:error] = 'Failed to get current KB clock: Kill Bill server must be started with system property org.killbill.server.test.mode=true' end = [:api_key] = @tenant.api_key [:api_secret] = @tenant.api_secret fetch_catalog_versions = promise do Kaui::Catalog.get_tenant_catalog_versions(nil, ) rescue StandardError @catalog_versions = [] end fetch_overdue = promise do Kaui::Overdue.get_overdue_json() rescue StandardError @overdue = nil end fetch_overdue_xml = promise do Kaui::Overdue.get_tenant_overdue_config() rescue StandardError @overdue_xml = nil end fetch_invoice_template = promise do Kaui::AdminTenant.get_invoice_template(false, ) rescue StandardError @invoice_template = nil end fetch_invoice_translations = promise do Kaui::AdminTenant.get_invoice_translations() rescue StandardError @invoice_translations = {} end fetch_tenant_plugin_config = promise { Kaui::AdminTenant.get_tenant_plugin_config() } @catalog_versions = [] wait(fetch_catalog_versions).each_with_index do |effective_date, idx| @catalog_versions << { version: idx, version_date: effective_date } end @latest_version = begin @catalog_versions[-1][:version_date] rescue StandardError nil end @overdue = flash[:overdue_deleted] ? nil : wait(fetch_overdue) @overdue_xml = flash[:overdue_deleted] ? nil : wait(fetch_overdue_xml) @overdue_config_exists = @overdue_xml.present? || (@overdue&.overdue_states.present? && !@overdue.has_states) @invoice_template = begin wait(fetch_invoice_template) rescue StandardError nil end @invoice_translations = begin wait(fetch_invoice_translations) rescue StandardError {} end @tenant_plugin_config = begin wait(fetch_tenant_plugin_config) rescue StandardError '' end # When reloading page from the view, it sends the last tab that was active @active_tab = params[:active_tab] || 'CatalogShow' respond_to do |format| format.html format.js end end |
#switch_tenant ⇒ Object
606 607 608 609 610 611 612 613 614 615 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 606 def switch_tenant tenant = Kaui::Tenant.find_by(kb_tenant_id: params.require(:kb_tenant_id)) # Select the tenant, see TenantsController session[:kb_tenant_id] = tenant.kb_tenant_id session[:kb_tenant_name] = tenant.name session[:tenant_id] = tenant.id redirect_to admin_tenant_path(tenant.id), notice: "Tenant was switched to #{tenant.name}" end |
#upload_catalog ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 168 def upload_catalog current_tenant = safely_find_tenant_by_id(params[:id]) = [:api_key] = current_tenant.api_key [:api_secret] = current_tenant.api_secret uploaded_catalog = params.require(:catalog) catalog_xml = uploaded_catalog.read validate_response = Kaui::Catalog.validate_catalog(catalog_xml, [:username], nil, comment, ) catalog_validation_errors = begin JSON.parse(validate_response.response.body)['catalogValidationErrors'] rescue StandardError nil end if catalog_validation_errors.blank? Kaui::AdminTenant.upload_catalog(catalog_xml, [:username], nil, comment, ) redirect_to admin_tenant_path(current_tenant.id), notice: I18n.t('flashes.notices.catalog_uploaded_successfully') else errors = '' catalog_validation_errors.each do |validation_error| errors += validation_error['errorDescription'] end flash[:error] = errors redirect_to admin_tenant_new_catalog_path(id: current_tenant.id) end end |
#upload_catalog_translation ⇒ Object
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 447 def upload_catalog_translation current_tenant = safely_find_tenant_by_id(params[:id]) = [:api_key] = current_tenant.api_key [:api_secret] = current_tenant.api_secret locale = params[:translation_locale] uploaded_catalog_translation = params.require(:catalog_translation) catalog_translation = uploaded_catalog_translation.read if locale.blank? flash[:error] = I18n.t('errors.messages.locale_required') redirect_to admin_tenant_path(current_tenant.id, active_tab: 'CatalogTranslation') and return end Kaui::AdminTenant.upload_catalog_translation(catalog_translation, locale, true, [:username], nil, comment, ) redirect_to admin_tenant_path(current_tenant.id, active_tab: 'CatalogTranslation'), notice: I18n.t('flashes.notices.catalog_translation_uploaded_successfully') end |
#upload_invoice_template ⇒ Object
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 410 def upload_invoice_template current_tenant = safely_find_tenant_by_id(params[:id]) = [:api_key] = current_tenant.api_key [:api_secret] = current_tenant.api_secret is_manual_pay = params[:manual_pay] uploaded_invoice_template = params.require(:invoice_template) invoice_template = uploaded_invoice_template.read Kaui::AdminTenant.upload_invoice_template(invoice_template, is_manual_pay, true, [:username], nil, comment, ) redirect_to admin_tenant_path(current_tenant.id, active_tab: 'InvoiceTemplate'), notice: I18n.t('flashes.notices.invoice_template_uploaded_successfully') end |
#upload_invoice_translation ⇒ Object
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 426 def upload_invoice_translation current_tenant = safely_find_tenant_by_id(params[:id]) = [:api_key] = current_tenant.api_key [:api_secret] = current_tenant.api_secret locale = params[:translation_locale] uploaded_invoice_translation = params.require(:invoice_translation) invoice_translation = uploaded_invoice_translation.read if locale.blank? flash[:error] = I18n.t('errors.messages.locale_required') redirect_to admin_tenant_path(current_tenant.id, active_tab: 'InvoiceTranslation') and return end Kaui::AdminTenant.upload_invoice_translation(invoice_translation, locale, true, [:username], nil, comment, ) redirect_to admin_tenant_path(current_tenant.id, active_tab: 'InvoiceTranslation'), notice: I18n.t('flashes.notices.invoice_translation_uploaded_successfully') end |
#upload_overdue_config ⇒ Object
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 354 def upload_overdue_config uploaded_overdue_config = params.require(:overdue) current_tenant = safely_find_tenant_by_id(params[:id]) = [:api_key] = current_tenant.api_key [:api_secret] = current_tenant.api_secret overdue_config_xml = uploaded_overdue_config.read begin Nokogiri::XML(overdue_config_xml, &:strict) rescue Nokogiri::XML::SyntaxError => e flash[:error] = I18n.t('errors.messages.invalid_xml', error: e) redirect_to admin_tenant_path(current_tenant.id) and return end Kaui::AdminTenant.upload_overdue_config(overdue_config_xml, [:username], nil, comment, ) redirect_to admin_tenant_path(current_tenant.id, active_tab: 'OverdueShow'), notice: I18n.t('flashes.notices.overdue_uploaded_successfully') end |
#upload_plugin_config ⇒ Object
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
# File 'app/controllers/kaui/admin_tenants_controller.rb', line 468 def upload_plugin_config current_tenant = safely_find_tenant_by_id(params[:id]) = [:api_key] = current_tenant.api_key [:api_secret] = current_tenant.api_secret plugin_name = params[:plugin_name] plugin_properties = params[:plugin_properties] plugin_type = params[:plugin_type] plugin_key = params[:plugin_key] if plugin_properties.blank? flash[:error] = 'Plugin properties cannot be blank' elsif plugin_name.blank? flash[:error] = 'Plugin name cannot be blank' else plugin_config = Kaui::AdminTenant.format_plugin_config(plugin_key, plugin_type, plugin_properties) Kaui::AdminTenant.upload_tenant_plugin_config(plugin_name, plugin_config, [:username], nil, comment, ) flash[:notice] = 'Config for plugin was successfully uploaded' end redirect_to admin_tenant_path(current_tenant.id, active_tab: 'PluginConfig') end |