docbrown/app/controllers/api_secrets_controller.rb
Michael Kohl 728a05c476 Move from env variables to SiteConfig (#5385) [deploy]
* Move from env variables to SiteConfig

Related to #5384

This PR only deals with the first remaining part outlined in the issue, starting to use existing SiteConfig keys instead of the env variables.

* Restore Envfile to original version for now
2020-01-07 16:36:24 -05:00

41 lines
952 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.full_messages.to_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: #{SiteConfig.default_site_email}"
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