-
Notifications
You must be signed in to change notification settings - Fork 78
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
Configure default subscriptions for emails and optional targets #160
Configure default subscriptions for emails and optional targets #160
Conversation
…s_default to have a more granual default setup
…optinal_targets_as_default
140465f
to
ab36d0d
Compare
Hi there, I'm ready with this PR. I added new rspec tests to exercise the new configs, added them to Functions.md and made the views aware of the new optional defaults. I hope I did everything I had to and we could merge it in soon, just ping me if I need to change anything :) |
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've added several comments for your PR. Thank you for your contribution!
@@ -24,12 +24,12 @@ | |||
<% end %> | |||
<% else %> | |||
<% if ActivityNotification.config.subscribe_as_default %> | |||
<%= link_to subscribe_path_for(subscription, option_params), onclick: '$(this).find("input").prop("checked", true);$(this).parent().parent().parent().next().slideDown();$(this).parent().parent().parent().next().find("input").prop("checked", true);$(this).parent().parent().parent().next().next().slideDown();$(this).parent().parent().parent().next().next().find("input").prop("checked", true);', method: :put, remote: true do %> | |||
<%= link_to subscribe_path_for(subscription, option_params.merge(with_email_subscription: ActivityNotification.config.subscribe_to_email_as_default, with_optional_targets: ActivityNotification.config.subscribe_to_optional_targets_as_default)), onclick: "$(this).find(\"input\").prop(\"checked\", true);$(this).parent().parent().parent().next().slideDown();$(this).parent().parent().parent().next().find(\"input\").prop(\"checked\", #{ActivityNotification.config.subscribe_to_email_as_default.to_s});$(this).parent().parent().parent().next().next().slideDown();$(this).parent().parent().parent().next().next().find(\"input\").prop(\"checked\", #{ActivityNotification.config.subscribe_to_optional_targets_as_default});", method: :put, remote: true do %> |
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.
Why do you set default parameters in a view? It seems to be too complex and it might become breaking changes for the existing users using customized views. I think subscription records should be initialized with default subscription in server side business logic, not front end views. What do you think about 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.
Nice catch. I think I just haven't found the right place at first. There are two separate changes in this line.
option_params.merge(with_email_subscription: ActivityNotification.config.subscribe_to_email_as_default, with_optional_targets: ActivityNotification.config.subscribe_to_optional_targets_as_default)
This should be reverted, there's a better place for it in subscriptions_controller.rb#L93-L97, I just need to change the to_boolean(true)
conversions to use the right default from config.
.find("input").prop("checked", #{ActivityNotification.config.subscribe_to_email_as_default.to_s});
This code should remain here to remove a flick in the transitions. Without this, for a few seconds the frontend could show a wrong state, then it got rewritten with the response from the backend.
I'm going to make a new commit about these.
<%= check_box :subscribing, "", { checked: false }, 'true', 'false' %> | ||
<div class="slider"></div> | ||
<% end %> | ||
<% else %> | ||
<%= link_to subscribe_path_for(subscription, option_params.merge(with_email_subscription: false)), onclick: '$(this).find("input").prop("checked", true);$(this).parent().parent().parent().next().slideDown();$(this).parent().parent().parent().next().next().slideDown();', method: :put, remote: true do %> | ||
<%= link_to subscribe_path_for(subscription, option_params.merge(with_email_subscription: false, with_optional_targets: false)), onclick: '$(this).find("input").prop("checked", true);$(this).parent().parent().parent().next().slideDown();$(this).parent().parent().parent().next().next().slideDown();', method: :put, remote: true do %> |
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.
Same as above
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.
Here the original code already contained with_email_subscription: false
, so I thought we either need to remove that or add optional_targets too. On current master, it looks like this with config.subscribe_as_default = false
in the initializer:
- I open the page
- Immediately after I turn on the notifications
- A few moments later, when the server responded with a partial
With the changes I added to solve your other comment, these with_*
overrides will become unneccessary, I'm going to remove them in a commit.
Hi @simukappu . Thanks for the review, I found them very helpful. I replied to your comments and made changes where I felt necessary. |
a0ca838
to
b06ef28
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.
LGTM. Also worked fine with my env.
Issue #, if available: #159
Summary
I added two new entry to
ActivityNotification::Config
,subscribe_to_email_as_default
to change default subscriptions for emails (if you want to differ fromsubscribe_as_default
) andsubscribe_to_optional_targets_as_default
to change default subscriptions for optional targets. Then I went through the gem, looked for usages ofsubscribe_as_default
and changed them to use the new configs. After introducing the new defaults to every reasonable place, the tests remained green (that was the expected result as the new configs have a fallback to the common default)Other Information
I still need to do a few steps to finish the PR, but an initial review would be nice