New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UX: Surface stripe AuthenticationError on the Admin Dashboard #187
base: main
Are you sure you want to change the base?
Conversation
"discourse_subscriptions.auth.invalid", | ||
settingsUrl: "admin/site_settings/category/discourse_subscriptions", | ||
) | ||
AdminDashboardData.add_found_scheduled_check_problem( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why add_found_scheduled_check_problem
was used, like I was saying yesterday the correct way of doing this is by using add_scheduled_problem_check
. The example is here:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at how this plugin is set up more, I see you want a JIT kind of message for this. Usually the better solution for this is to use AdminDashboardData.add_problem_message
. Sadly though this has no plugin extensibility (nor does anything in AdminDashboardData
atm 😢 ), since all the messages have to be defined upfront:
So I would recommend a couple of things. First of all make a commit to core to:
- Add a filtered register in
DiscoursePluginRegistry
usingdefine_filtered_register
, which could be called something likeadmin_problem_messages
- Alter
AdminDashboardData
to also iterate throughDiscoursePluginRegistry.admin_problem_messages
here https://github.com/discourse/discourse/blob/1ed09234f98b68d13ed7b49c2588155c7d8c9947/app/models/admin_dashboard_data.rb#L66-L69
Then change this PR to:
- In plugin.rb, call `DiscoursePluginRegistry.register_admin_problem_message("discourse_subscriptions.some_i18n_key", self)
- Call
AdminDashboardData.add_problem_message("discourse_subscriptions.some_i18n_key")
- Change the clear to use
AdminDashboardData.clear_problem_message("discourse_subscriptions.some_i18n_key")
In addition, I would also add a site setting validator to validate that the Stripe key is valid when setting discourse_subscriptions_secret_key
.
If you need some help with this, I think @Drenmi would be the person to do it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is more more work, but it is more correct. This is why I started up a topic too to discuss the new messaging interface for admins, because like we talked about it would be good to let plugins do this kind of thing easier :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few points..
- the error is only known when the API call is made. so using core's
add_scheduled_problem_check
's check schedule of10.minutes
would mean core is invoking the API every so often, even if the value is correct. I want to avoid that. - There is no way to "validate" the API key without an API call. In the gem, Stripe's recommended way is to use the web interface at https://stripe.com/api.
In defining this new interface on core, I will leave it to the staff exp team. With social auth validation coming up there will prob be more to-and-fro on this and it will probably be a better use of time. There are some complications like plugin availability and problem message removal issues that need to be better addressed if we're defining a plugin 'API' for admin problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no way to "validate" the API key without an API call. In the gem, Stripe's recommended way is to use the web interface at https://stripe.com/api.
Yeah there will be a similar problem with the social auth checks. Any API call will do; doing a GET /v1/balance
for stripe seems easiest, but people are also suggesting creating a token (but that is not very nice to have to create something).
In defining this new interface on core, I will leave it to the staff exp team. With social auth validation coming up there will prob be more to-and-fro on this and it will probably be a better use of time.
Yep sure makes sense to leave it to us 👍 There will definitely be plenty to do in this area to make things consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Martin!
There's a bit of log noise now when a user has an invalid API key.
This surfaces the issue to the admin dashboard instead of just /logs. AdminProblemChecks are done every 10.minutes, so we won't have to worry about the
Problem
still being there if the plugin is removed.