Class: DiscourseSubscriptionClient::SuppliersController
- Inherits:
-
AdminController
- Object
- ApplicationController
- AdminController
- DiscourseSubscriptionClient::SuppliersController
show all
- Defined in:
- app/controllers/discourse_subscription_client/suppliers_controller.rb
Instance Method Summary
collapse
#ensure_can_manage_subscriptions, #failed_json, #render_json_dump, #render_serialized, #serialize_data, #success_json
Instance Method Details
#authorize_callback ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/controllers/discourse_subscription_client/suppliers_controller.rb', line 28
def authorize_callback
payload = params[:payload]
request_id = cookies[:user_api_request_id]
supplier_id = request_id.split("-").first
data = DiscourseSubscriptionClient::Authorization.process_response(request_id, payload)
raise Discourse::InvalidParameters, :payload unless data
supplier = SubscriptionClientSupplier.find(supplier_id)
raise Discourse::InvalidParameters, :supplier_id unless supplier
supplier.update(
api_key: data[:key],
user_id: data[:user_id],
authorized_at: DateTime.now.iso8601(3)
)
DiscourseSubscriptionClient::Subscriptions.update
if !session[:final_landing_path].blank?
redirect_to session[:final_landing_path]
else
redirect_to "/admin/plugins"
end
end
|
#destroy ⇒ Object
54
55
56
57
58
59
60
|
# File 'app/controllers/discourse_subscription_client/suppliers_controller.rb', line 54
def destroy
if @supplier.destroy_authorization
render json: success_json.merge(supplier_id: @supplier.id)
else
render json: failed_json
end
end
|
#index ⇒ Object
9
10
11
12
13
14
15
16
17
|
# File 'app/controllers/discourse_subscription_client/suppliers_controller.rb', line 9
def index
suppliers = SubscriptionClientSupplier.all
if params[:resource]
suppliers = suppliers
.joins(:resources)
.where(resources: { name: params[:resource] })
end
render_serialized(suppliers, SupplierSerializer, root: "suppliers")
end
|