docbrown/app/controllers/api_secrets_controller.rb
Ridhwana 17fdc556ee
Generalization: Replace static dev emails with configurable ones. (#7438)
* feat: update the email addresses in the site config

* chore: update the default email address everywhere

* feat: update the template for the config

* chore: remove default_site_mail as an allowed parameter

* feat: change biz@dev.to to teh business email address and with a subject

* feat: update partners@dev.to to use SiteConfig.email_addresses[:business]

* feta: update to business email address

* feat: update members@dev.to to use the site config

* feat: update privacy email

* chore: Anna's suggestion to loop through object instead of keys
2020-04-23 11:26:58 +02:00

41 lines
959 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.email_addresses[:default]}"
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