Class: RivetCms::ApiTokensController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- RivetCms::ApiTokensController
- Includes:
- InertiaProps
- Defined in:
- app/controllers/rivet_cms/api_tokens_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/rivet_cms/api_tokens_controller.rb', line 19 def create scope = params[:scope].presence_in(%w[published preview]) || "published" token = ApiToken.generate!(name: params[:name].to_s, scope: scope) audit "api_token.created", token, scope: scope flash[:new_token] = token.plaintext redirect_to api_tokens_path, notice: "API token created — copy it now; it won't be shown again." rescue ActiveRecord::RecordInvalid => e redirect_to api_tokens_path, alert: e.record.errors..to_sentence end |
#destroy ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/controllers/rivet_cms/api_tokens_controller.rb', line 29 def destroy token = api_tokens.find(params[:id]) :delete, :api, record: token token.destroy audit "api_token.revoked", token redirect_to api_tokens_path, notice: "API token revoked" end |
#index ⇒ Object
12 13 14 15 16 17 |
# File 'app/controllers/rivet_cms/api_tokens_controller.rb', line 12 def index render inertia: "ApiTokens/Index", props: { tokens: permitted(api_tokens.recent, :read, :api).map { |token| api_token_json(token) }, new_token: flash[:new_token] } end |