docbrown/app/controllers/api_secrets_controller.rb
Ridhwana 5e93d3a25e
Add a contact email address to the /admin/customization/config (#16497)
* feat: remove the default email and cobine the periodic digest and the contact email under the Email section

* refactor: rename  the email_link to contact link and use the contact_email as a default and fallback to the ForemInstance.email

* chore: alignment

* feat: use the contact_email helper

* feat: move the contact_email to the ForemInstance model

* feat: use ForemInstance.contact_email instead of the application helper method

* removed the application Helper

* feat: set the dafault on the contact_email

* fix: cypress tests

* Update app/lib/constants/settings/general.rb

Co-authored-by: Michael Kohl <me@citizen428.net>

Co-authored-by: Michael Kohl <me@citizen428.net>
2022-02-15 17:37:08 +02:00

42 lines
954 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] = I18n.t("api_secrets_controller.generated", secret: @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] = I18n.t("api_secrets_controller.revoked")
else
flash[:error] =
I18n.t("errors.messages.try_again_email", email: ForemInstance.contact_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