1
0
Fork 0
discourse-custom-wizard-unl.../app/controllers/admin.rb

47 Zeilen
939 B
Ruby

2017-09-23 04:34:07 +02:00
class CustomWizard::AdminController < ::ApplicationController
before_filter :ensure_logged_in
before_filter :ensure_admin
def index
render nothing: true
end
def save
2017-09-24 05:01:18 +02:00
params.require(:wizard)
2017-09-23 04:34:07 +02:00
2017-09-24 05:01:18 +02:00
wizard = ::JSON.parse(params[:wizard])
2017-09-23 04:34:07 +02:00
2017-09-24 05:01:18 +02:00
wizard["id"] = SecureRandom.hex(8) if !wizard["id"]
2017-09-23 04:34:07 +02:00
2017-09-24 05:01:18 +02:00
PluginStore.set('custom_wizards', wizard["id"], wizard)
2017-09-23 04:34:07 +02:00
render json: success_json
end
def remove
2017-09-24 05:01:18 +02:00
params.require(:id)
2017-09-23 04:34:07 +02:00
2017-09-24 05:01:18 +02:00
PluginStore.remove('custom_wizards', params[:id])
2017-09-23 04:34:07 +02:00
render json: success_json
end
def find
2017-09-24 05:01:18 +02:00
params.require(:id)
2017-09-23 04:34:07 +02:00
2017-09-24 05:01:18 +02:00
wizard = PluginStore.get('custom_wizards', params[:id])
2017-09-23 04:34:07 +02:00
render json: success_json.merge(wizard: wizard)
end
def all
2017-09-24 05:01:18 +02:00
rows = PluginStoreRow.where(plugin_name: 'custom_wizards').order(:id)
2017-09-23 04:34:07 +02:00
wizards = rows ? [*rows].map do |r|
CustomWizard::Wizard.new(r.value)
end : []
render json: success_json.merge(wizards: wizards)
end
end