docbrown/spec/policies
Jeremy Friesen a40efc6bbd
Refactoring questions asked of user (#15762)
* Refactoring questions asked of user

In this pull request, I'm extracting and normalizing role-based
questions asked of the user.

Prior to this commit, our codebase has asked two very similar questions
of our user model:

- `user.has_role?(:admin)`
- `user.admin?`

In asking `has_role?(:admin)` we are relying on implementation details
of the rolify gem.  In addition, the `has_role?` question asked
throughout controllers or views means that it's harder to create
hieararchies of permissions.

In favoring `user.admin?` as our question, we can use that indirection
as an opportunity to discuss and decide "Should someone with the
`:super_admin` role be `user.admin? == true`?"

The details of this commit is to do three primary things:

1. Ask the `has_role?` questions in "one place" in the code (e.g. the
   `Authorizer` module)
2. Extract the role based questions that are on the `User` model and
   provde backwards compatable delegation.
3. Structure the code so that it's harder to accidentally call
   `user.has_role?` (e.g., make `User#has_role?` and `User#has_any_role?`
   private).

This is related to #15624 and the updates are informed by discussion in
PR #15691.  This commit supplants #15691.

* Refactoring the liquid tag policy tests

* Fixing typo

* Bump for travis
2021-12-21 12:45:12 -05:00
..
admin_policy_spec.rb Use build_stubbed in Policy specs (#4017) [ci skip] 2019-09-13 11:38:58 -04:00
api_secret_policy_spec.rb Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
article_policy_spec.rb Fix organization's admin unable to view an article's stats (#14767) 2021-09-21 16:05:34 +01:00
authorizer_spec.rb Refactoring questions asked of user (#15762) 2021-12-21 12:45:12 -05:00
comment_policy_spec.rb Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
discussion_lock_policy_spec.rb Create DiscussionLocks (#13905) 2021-06-10 11:04:33 -04:00
follow_policy_spec.rb Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
github_repo_policy_spec.rb Split Settings::Authentication from SiteConfig (#13095) 2021-04-12 09:41:09 +02:00
html_variant_policy_spec.rb Use build_stubbed in Policy specs (#4017) [ci skip] 2019-09-13 11:38:58 -04:00
image_upload_policy_spec.rb Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
internal_policy_spec.rb Refactoring questions asked of user (#15762) 2021-12-21 12:45:12 -05:00
liquid_tag_policy_spec.rb Refactoring questions asked of user (#15762) 2021-12-21 12:45:12 -05:00
organization_policy_spec.rb Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
pinned_article_policy_spec.rb expect to forbid, rather than expect not to permit (#14390) 2021-07-30 11:42:47 -05:00
reaction_policy_spec.rb Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
response_template_policy_spec.rb Add response templates for internal usage (#6676) 2020-03-20 11:32:55 -04:00
stripe_active_card_policy_spec.rb Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
tag_policy_spec.rb Use build_stubbed in Policy specs (#4017) [ci skip] 2019-09-13 11:38:58 -04:00
user_policy_spec.rb Rename banned and comment_banned roles (#12270) 2021-04-06 10:12:14 -05:00
video_policy_spec.rb Remove harsh video restriction and add video duration (#1811) 2019-02-16 17:42:44 -04:00