docbrown/app/controllers/admin/consumer_apps_controller.rb
Fernando Valverde e602d50d32
Push Notification multi app support (#13304)
* PushNotificationTarget model + /admin/push_notifications (index)

* Admin panel CRUD + request tests

* Migrate Redis backed Rpush model responsibilities into PushNotificationTarget

* Fix failing specs

* Fix conflicts + clean up test by using constant reference

* Removed unused policy

* policy + services + misc feedback

* PushNotificationTarget refactored to AppIntegration

* Review feedback

* Some small cleanup

* Refactor AppIntegration -> ConsumerApp

* Fixing specs

* Trigger Travis

* More naming refactor changes

* Refactor services into queries

* Revert to where(...).first, fix typo and tests

* Apply suggestions from code review

Co-authored-by: rhymes <rhymes@hey.com>

* PR review feedback - create_or_find_by, validations, renaming + more tests

* Fix aria-label text

* Remove unnecessary individual index - composite index will do

Co-authored-by: rhymes <rhymes@hey.com>
2021-04-21 17:13:01 -06:00

63 lines
1.4 KiB
Ruby

module Admin
class ConsumerAppsController < Admin::ApplicationController
layout "admin"
def index
@apps = ConsumerApps::FindOrCreateAllQuery.call
end
def new
@app = ConsumerApp.new
end
def edit
@app = ConsumerApp.find(params[:id])
authorize @app
end
def create
@app = ConsumerApp.new(consumer_app_params)
authorize @app
if @app.save
flash[:success] = "#{@app.app_bundle} has been created!"
redirect_to admin_consumer_apps_path
else
flash[:danger] = @app.errors_as_sentence
render :new
end
end
def update
@app = ConsumerApp.find(params[:id])
authorize @app
if @app.update(consumer_app_params)
flash[:success] = "#{@app.app_bundle} has been updated!"
redirect_to admin_consumer_apps_path
else
flash[:danger] = @app.errors_as_sentence
render :edit
end
end
def destroy
@app = ConsumerApp.find(params[:id])
authorize @app
if @app.destroy
flash[:success] = "#{@app.app_bundle} has been deleted!"
redirect_to admin_consumer_apps_path
else
flash[:danger] = "Something went wrong with deleting #{@app.app_bundle}."
render :edit
end
end
private
def consumer_app_params
params.permit(:app_bundle, :platform, :auth_key)
end
end
end