Skip to content

Commit

Permalink
FEATURE: allow users to opt out from notifications
Browse files Browse the repository at this point in the history
Some users find code review approval notifications annoying, allow them
to opt out.

This can be disabled from the pref->notification panel for the user
  • Loading branch information
SamSaffron committed Sep 22, 2020
1 parent 78cdaee commit ed69e78
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 0 deletions.
@@ -0,0 +1,6 @@
export default {
//setupComponent(args, component) {},

This comment has been minimized.

Copy link
@eviltrout

eviltrout Sep 22, 2020

Contributor

This comment should be removed.

This comment has been minimized.

Copy link
@SamSaffron

SamSaffron via email Sep 22, 2020

Author Member
shouldRender(args, component) {
return component.currentUser && component.currentUser.admin;
},
};
Expand Up @@ -39,6 +39,13 @@ function initialize(api) {
}),
});

api.modifyClass("controller:preferences/notifications", {
init() {
this._super(...arguments);
this.saveAttrNames.push("custom_fields");
},
});

function allowSkip(currentUser, topic, siteSettings) {
return allowApprove(currentUser, topic, siteSettings);
}
Expand Down
@@ -0,0 +1,8 @@
<div class="control-group">
<label class="control-label">{{i18n "code_review.title"}}</label>
<div class="controls">
{{preference-checkbox
labelKey="code_review.notify_on_approval"
checked=model.custom_fields.notify_on_code_reviews}}
</div>
</div>
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Expand Up @@ -29,3 +29,4 @@ en:
github_webhooks: "Github Webhooks"
configure_webhooks: "Configure Webhooks"
configure_webhook: "Configure Webhook"
notify_on_approval: "Notify on code review approvals"
11 changes: 11 additions & 0 deletions lib/discourse_code_review/state/commit_approval.rb
Expand Up @@ -139,6 +139,17 @@ def transition_to_approved(topic)
end

def send_approved_notification(topic, post)
if !topic.user
return
end

notify = topic.user.custom_fields[DiscourseCodeReview::NOTIFY_REVIEW_CUSTOM_FIELD]

# can be nil as well
if notify == false
return
end

Notification.transaction do
destroyed_notifications =
topic.user.notifications
Expand Down
11 changes: 11 additions & 0 deletions plugin.rb
Expand Up @@ -50,6 +50,7 @@ class ::Auth::GithubAuthenticator

module ::DiscourseCodeReview
PluginName = 'discourse-code-review'
NOTIFY_REVIEW_CUSTOM_FIELD = 'notify_on_code_reviews'

class APIUserError < StandardError
end
Expand Down Expand Up @@ -162,6 +163,16 @@ def self.github_organizations
end
end

# TODO Drop after Discourse 2.6.0 release
register_editable_user_custom_field(DiscourseCodeReview::NOTIFY_REVIEW_CUSTOM_FIELD)
if respond_to?(:allow_staff_user_custom_field)
allow_staff_user_custom_field(DiscourseCodeReview::NOTIFY_REVIEW_CUSTOM_FIELD)
else
whitelist_staff_user_custom_field(DiscourseCodeReview::NOTIFY_REVIEW_CUSTOM_FIELD)
end

User.register_custom_field_type(DiscourseCodeReview::NOTIFY_REVIEW_CUSTOM_FIELD, :boolean)

require File.expand_path("../app/controllers/discourse_code_review/code_review_controller.rb", __FILE__)
require File.expand_path("../app/controllers/discourse_code_review/organizations_controller.rb", __FILE__)
require File.expand_path("../app/controllers/discourse_code_review/repos_controller.rb", __FILE__)
Expand Down

0 comments on commit ed69e78

Please sign in to comment.