diff --git a/assets/javascripts/discourse/templates/admin-wizards-api.hbs b/assets/javascripts/discourse/templates/admin-wizards-api.hbs
index 6a0a8067..160225ea 100644
--- a/assets/javascripts/discourse/templates/admin-wizards-api.hbs
+++ b/assets/javascripts/discourse/templates/admin-wizards-api.hbs
@@ -260,14 +260,20 @@
Datetime |
+ User |
Status |
- Endpoint |
+ URL |
Error |
{{#each api.log as |logentry|}}
{{logentry.time}} |
+
+
+ |
{{logentry.status}} |
- {{logentry.endpoint_url}} |
+ {{logentry.url}} |
{{logentry.error}} |
{{/each}}
diff --git a/lib/api/authorization.rb b/lib/api/authorization.rb
index 9dd51d50..f6a11794 100644
--- a/lib/api/authorization.rb
+++ b/lib/api/authorization.rb
@@ -116,8 +116,14 @@ class CustomWizard::Api::Authorization
:method => 'GET',
:query => URI.encode_www_form(body)
)
-
- result = connection.request()
+ begin
+ result = connection.request()
+ log_params = {time: Time.now, user_id: 0, status: 'SUCCESS', url: token_url, error: ""}
+ CustomWizard::Api::LogEntry.set(name, log_params)
+ rescue
+ log_params = {time: Time.now, user_id: 0, status: 'FAILURE', url: token_url, error: "Token refresh request failed"}
+ CustomWizard::Api::LogEntry.set(name, log_params)
+ end
self.handle_token_result(name, result)
end
diff --git a/lib/api/endpoint.rb b/lib/api/endpoint.rb
index 356687e7..3036a49f 100644
--- a/lib/api/endpoint.rb
+++ b/lib/api/endpoint.rb
@@ -62,7 +62,7 @@ class CustomWizard::Api::Endpoint
end
end
- def self.request(api_name, endpoint_id, body)
+ def self.request(user, api_name, endpoint_id, body)
endpoint = self.get(api_name, endpoint_id)
auth = CustomWizard::Api::Authorization.get_header_authorization_string(api_name)
@@ -87,12 +87,13 @@ class CustomWizard::Api::Endpoint
begin
response = connection.request(params)
- log_params = {time: Time.now, status: 'SUCCESS', endpoint_url: endpoint.url, error: ""}
+ log_params = {time: Time.now, user_id: user.id, status: 'SUCCESS', url: endpoint.url, error: ""}
+
CustomWizard::Api::LogEntry.set(api_name, log_params)
return JSON.parse(response.body)
rescue
# TODO: improve error detail
- log_params = {time: Time.now, status: 'FAILURE', endpoint_url: endpoint.url, error: "API request failed"}
+ log_params = {time: Time.now, user_id: user.id, status: 'FAILURE', url: endpoint.url, error: "API request failed"}
CustomWizard::Api::LogEntry.set(api_name, log_params)
return JSON.parse "[{\"error\":\"API request failed\"}]"
end
diff --git a/lib/api/logentry.rb b/lib/api/logentry.rb
index 083262aa..6b7831bd 100644
--- a/lib/api/logentry.rb
+++ b/lib/api/logentry.rb
@@ -3,9 +3,14 @@ class CustomWizard::Api::LogEntry
attr_accessor :log_id,
:time,
+ :user_id,
:status,
- :endpoint_url,
- :error
+ :url,
+ :error,
+ :username,
+ :userpath,
+ :name,
+ :avatar_template
def initialize(api_name, data={})
@api_name = api_name
@@ -58,6 +63,12 @@ class CustomWizard::Api::LogEntry
api_name = record['plugin_name'].sub("custom_wizard_api_", "")
data = ::JSON.parse(record['value'])
data[:log_id] = record['key'].split('_').last
+ this_user = User.find_by(id: data['user_id'])
+ data[:user_id] = this_user.id || nil
+ data[:username] = this_user.username || ""
+ data[:userpath] = "/u/#{this_user.username_lower}/activity"
+ data[:name] = this_user.name || ""
+ data[:avatar_template] = "/user_avatar/default/#{this_user.username_lower}/97/#{this_user.uploaded_avatar_id}.png"
self.new(api_name, data)
end
end
diff --git a/lib/builder.rb b/lib/builder.rb
index 7fd4fa6d..c2be9282 100644
--- a/lib/builder.rb
+++ b/lib/builder.rb
@@ -406,7 +406,7 @@ class CustomWizard::Builder
api_body = CustomWizard::Builder.fill_placeholders(JSON.generate(api_body_parsed), user, data)
end
- result = CustomWizard::Api::Endpoint.request(action['api'], action['api_endpoint'], api_body)
+ result = CustomWizard::Api::Endpoint.request(user, action['api'], action['api_endpoint'], api_body)
if error = result['error'] || (result[0] && result[0]['error'])
error = error['message'] || error
diff --git a/serializers/api/log_serializer.rb b/serializers/api/log_serializer.rb
index 754c15f3..13ee1555 100644
--- a/serializers/api/log_serializer.rb
+++ b/serializers/api/log_serializer.rb
@@ -2,6 +2,11 @@ class CustomWizard::Api::LogSerializer < ApplicationSerializer
attributes :log_id,
:time,
:status,
- :endpoint_url,
- :error
+ :url,
+ :error,
+ :user_id,
+ :username,
+ :userpath,
+ :name,
+ :avatar_template
end