-
-
Notifications
You must be signed in to change notification settings - Fork 393
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't use constants for authorization handlers configuration #2016
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2016 +/- ##
==========================================
+ Coverage 98.48% 98.48% +<.01%
==========================================
Files 1144 1145 +1
Lines 25754 25756 +2
==========================================
+ Hits 25363 25365 +2
Misses 391 391 |
CHANGELOG.md
Outdated
@@ -16,6 +16,7 @@ | |||
- **decidim**: URLs now use the participatory space slug instead of the ID, both in the public pages and in the admin. Old routes using the space IDs now redirect to the ones using the slug. [\#1842](https://github.com/decidim/decidim/pull/1842) | |||
- **decidim**: `bin/rails generate decidim:demo` is no longer available in generated applications. Use the `--demo` flag when generating your application or do the change manually if you want to use the "demo" authorization handler. [\#1978](https://github.com/decidim/decidim/pull/1978) | |||
- **decidim-core**: Changes some texts in the homepage ("How do I take part in a process?" section) [\#1947](https://github.com/decidim/decidim/pull/1947) | |||
- **decidim-core**: Authorization handlers now must be specified as strings. To migrate, change `config.authorization_handlers = [MyHandler]` to `config.authorization_handlers = ["MyHandler"]`. [\#19](https://github.com/decidim/decidim/pull/19) |
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.
s/19/2016/
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.
Ooops 馃槼, updated!
@@ -14,7 +14,7 @@ | |||
|
|||
<div class="field"> | |||
<%= f.label :available_authorizations %> | |||
<%= f.collection_check_boxes :available_authorizations, Decidim.authorization_handlers, :name, :name %> | |||
<%= f.collection_check_boxes :available_authorizations, Decidim.authorization_handlers, :itself, :itself %> |
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.
itself
?????????????? OMG I didn't know this existed 馃槶
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.
Pretty crazy, eh? Ruby style. I remember seeing it in docs or somewhere, but only now I found a use case.
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.
It's awesome 鉂わ笍
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.
Sad & nice at the same time!
And set it just once before the whole suite.
So we don't depend on the constant being already available when configuration is read.
The handler is never supposed to be instantiated from the model and it's only used for validations. This changes make that more explicit.
3d99d7e
to
95a32dc
Compare
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.
Super nice! Rails auto-loading & initialization time constants don't play along together.
馃帺 What? Why?
Tests on
decidim-barcelona
running against currentdecidim
master are failing because the authorization handler class is not yet available by the time tests are loaded.I think it's better to not use constants directly on code that is evaluated at initialization/load time, since we need to make sure the constants are actually available at the time. That's inconvenient because you never need to care about that in other situations, and I sometimes have seen it causing problems with code (auto)loading.
This is similar to Rails deprecating specifying
class_name
as a constant inActiveRecord
associations.This PR also includes some other refactorings in authorization handlers that I've extracted from another PR I'm working on (#1815 & #1871), to make reviewing that one easier.
馃搶 Related Issues
馃搵 Subtasks
None.
馃摲 Screenshots (optional)
None.
馃懟 GIF