docbrown/app/controllers/api_secrets_controller.rb
Michael Kohl 6dfabd578f
Rename SiteConfig to Settings::General (#13573)
* Rename SiteConfig

* More renaming

* Update spec

* Update mandatory settings mapping

* More renaming

* e2e test fixes

* You have a rename, and you have a rename

* Spec fix

* More changes

* Temporarily disable specs

* After-merge update

* Undo rename for migration

* undo rename of DUS

* Fix DUS

* Fix merge problem

* Remove redundant DUS

* Fix specs

* Remove unused code

* Change wrong class name

* More cleanup

* Re-add missing values to constant

* Fix constant

* Fix spec

* Remove obsolete fields

* Add accidentally removed field

* Update spec

* Move methods from Settings::General to ForemInstance

* Remove unneeded model

* Change mentions of 'site config'
2021-05-21 14:45:37 +02:00

42 lines
960 B
Ruby

class ApiSecretsController < ApplicationController
before_action :load_api_secret, only: :destroy
after_action :verify_authorized
def create
authorize ApiSecret
@secret = ApiSecret.new(permitted_attributes(ApiSecret))
@secret.user_id = current_user.id
if @secret.save
flash[:notice] = "Your API Key has been generated: #{@secret.secret}"
else
flash[:error] = @secret.errors_as_sentence
end
redirect_back(fallback_location: root_path)
end
def destroy
authorize @secret
if @secret.destroy
flash[:notice] = "Your API Key has been revoked."
else
flash[:error] =
"An error occurred. Please try again or send an email to: #{Settings::General.email_addresses[:contact]}"
end
redirect_back(fallback_location: root_path)
end
private
def load_api_secret
@secret = ApiSecret.find(destroy_params[:id])
end
def destroy_params
params.permit(:id)
end
end