docbrown/app
Daniel Uber 68867e7c68
Ensure we have current user information before deciding how to handle the "flag user" button (#13279)
* Make test fail again

Minimal reproduction via `rspec
spec/system/user/trusted_user_flags_user_spec.rb --order=random
--seed=9374` which runs in this order:

- when signed in as a trusted user
- when not logged in
- when signed in as the non-trusted user
- when signed in as the user

Because "not logged in" immediately precedes "non-trusted user" in this
order, the browser store cache is cleared and there is no user. Since
there's no user, the flag is not removed.

* Wait for current user promise before processing current user

* Extract button callback registration to function

This addresses a code climate concern (function exceeded 50 lines) by
extracting the button behavior to a function of (button, id, name),
and calls that within the exported initFlag function.

* Prefer request to fetch

Addresses feedback to use @utilities/http's request method in  place
of fetch (which automatically adds the needed csrf headers)

* Reorder imports

Satisfies code climate report that imports are out of order

* Add honeybadger notify to error handling

Do more than just notify that something went wrong. Notify honeybadger
on failure to flag/unflag a user.

* Remove temp variable

This makes the notify code look more like the suggestion

* Reduce function arglist

Since the user id and name are properties of the flagButton's dataset,
we can efficiently extract them from the flagButton.

Only pull user id from dataset to check if current user = profile
user, and extract id and name from dataset after passing the
flagButton.

* reorder imports

Not sure how I managed to reverse this in 18aeb675b but here we go again

* Test button behavior

The original tests only asserted that the link to reactions was
present and labeled correctly. Add additional check that we can use
the button and that the label toggling occurs (this adds a request to
the test case, but adds a test for user facing behavior).

* Tame eslint check

I was getting conflicting feedback on import ordering from code
climate and eslint. Since telling eslint to ignore its rules was
immediately clear to me (there's an example on the line before this)
that's the direction I headed, but I can revisit if it matters

https://github.com/forem/forem/pull/13279#issuecomment-814411401
captures the conflict (code climate wants @utilities/http first,
eslint wants ../chat/util first, one or the other fails regardless of
the ordering.

* Use multiple rules in one ignore comment

https://eslint.org/docs/user-guide/configuring/rules#disabling-rules
supports multiple warnings separated by commas

* Remove stray comment

* Move documentation comment to the code it describes

* Replace invalid name

I had copied from the suggested code snippet the
userData.profileUserID name, but userData in this context is a global
function, and `profileUserId` (capitalization) is the bound variable
in this context.

Fix it before we throw an error trying to report an error (ironically,
before the window alert telling the user an error occurred, I think
this would have been visible only in console).

* Actually call the remove button function
2021-04-07 16:28:21 -05:00
..
assets Update Analytics Dashboard time navigation to tabs (#13270) 2021-04-07 14:11:15 +01:00
black_box Small adjustment to blackbox.rb (#10961) 2020-10-20 21:14:56 -04:00
controllers Fix Ruby 2.7 kwargs' warnings & misc spec warnings (#13256) 2021-04-06 16:57:59 -04:00
decorators Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
errors Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
helpers Fix Ruby 2.7 kwargs' warnings & misc spec warnings (#13256) 2021-04-06 16:57:59 -04:00
javascript Ensure we have current user information before deciding how to handle the "flag user" button (#13279) 2021-04-07 16:28:21 -05:00
lib Upgrade to Ahoy 2.0.x (#13085) 2021-04-06 10:12:32 -05:00
liquid_tags improve keyboard accessibility of modals 12427 10610 (#12511) 2021-02-24 16:01:10 +00:00
mailers Add email type as utm_campaign column (#13297) 2021-04-07 12:54:51 -04:00
middlewares Move TimeZoneSetter middleware in proper place (#11336) 2020-11-09 17:11:10 +01:00
models [15 Min Fix]: Extract a post's followers out of service and onto Article model (#13229) 2021-04-07 06:46:32 -07:00
policies Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
queries Fix Ruby 2.7 kwargs' warnings & misc spec warnings (#13256) 2021-04-06 16:57:59 -04:00
refinements Drop profile columns from user (#10707) 2020-12-03 08:14:38 +07:00
sanitizers [15-minute fix] Don't allow markdown to use CSS classes (#13282) 2021-04-07 11:40:39 -04:00
serializers ✂️ Remove search from Connect (#13235) 2021-04-06 13:03:31 -04:00
services Fix rescue in EdgeCache::Bust (#13303) 2021-04-07 15:31:30 -04:00
uploaders Change frame limit to match imgproxy (#13265) 2021-04-06 12:28:50 +02:00
validators Add validations to SiteConfig model (#12341) 2021-01-26 09:12:24 +07:00
view_objects Move GeneratedImage to Images::GenerateSocialmage (#11691) 2020-12-02 11:03:14 +07:00
views Remove superfluous app_url from nav links index (#13302) 2021-04-07 11:50:10 -06:00
workers [15 Min Fix]: Extract a post's followers out of service and onto Article model (#13229) 2021-04-07 06:46:32 -07:00