FEATURE: exclude categories from autogenerated email in addresses
https://github.com/mozilla/discourse/issues/20
This commit is contained in:
Родитель
0178e5970a
Коммит
77dd2a3e8e
|
@ -13,6 +13,8 @@ Follow the Discourse [Install a Plugin](https://meta.discourse.org/t/install-a-p
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
Email-in address autogeneration can be disabled on particular categories by opening their category edit modal, going to "Settings", and ticking the "Disable auto-email-in plugin on this category and subcategories" option. Now the email-in address can be manually set, or removed altogether.
|
||||||
|
|
||||||
If `auto_email_in_append` is enabled then this plugin won't overwrite existing email-in addresses, but will append newly generated addresses to the chain of possible addresses.
|
If `auto_email_in_append` is enabled then this plugin won't overwrite existing email-in addresses, but will append newly generated addresses to the chain of possible addresses.
|
||||||
|
|
||||||
Then, if an admin manually edits the email in value, the generated address will be appended (if it doesn't already exist). This can be used to clear old addresses on categories.
|
Then, if an admin manually edits the email in value, the generated address will be appended (if it doesn't already exist). This can be used to clear old addresses on categories.
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<section class='field'>
|
||||||
|
<label>
|
||||||
|
{{input type="checkbox" checked=category.custom_fields.auto_email_in_disabled}}
|
||||||
|
{{i18n 'auto_email_in.disable'}}
|
||||||
|
</label>
|
||||||
|
</section>
|
|
@ -0,0 +1,4 @@
|
||||||
|
en:
|
||||||
|
js:
|
||||||
|
auto_email_in:
|
||||||
|
disable: Disable auto-email-in plugin on this category and subcategories
|
|
@ -1,6 +1,6 @@
|
||||||
# name: auto-email-in
|
# name: auto-email-in
|
||||||
# about: Discourse plugin which automatically sets category email-in addresses based on their slug
|
# about: Discourse plugin which automatically sets category email-in addresses based on their slug
|
||||||
# version: 1.1.0
|
# version: 1.2.0
|
||||||
# authors: Leo McArdle
|
# authors: Leo McArdle
|
||||||
|
|
||||||
enabled_site_setting :auto_email_in_enabled
|
enabled_site_setting :auto_email_in_enabled
|
||||||
|
@ -13,14 +13,18 @@ after_initialize do
|
||||||
update_subcategory_email_in
|
update_subcategory_email_in
|
||||||
end
|
end
|
||||||
|
|
||||||
|
register_custom_field_type("auto_email_in_disabled", :boolean)
|
||||||
|
|
||||||
def update_email_in
|
def update_email_in
|
||||||
return unless SiteSetting.auto_email_in_enabled
|
return unless SiteSetting.auto_email_in_enabled
|
||||||
|
return if self.custom_fields["auto_email_in_disabled"]
|
||||||
|
|
||||||
old_email_in = self.email_in
|
old_email_in = self.email_in
|
||||||
divider = SiteSetting.auto_email_in_divider
|
divider = SiteSetting.auto_email_in_divider
|
||||||
domain = SiteSetting.auto_email_in_domain
|
domain = SiteSetting.auto_email_in_domain
|
||||||
|
|
||||||
if self.parent_category
|
if self.parent_category
|
||||||
|
return if self.parent_category.custom_fields["auto_email_in_disabled"]
|
||||||
new_email_in = "#{self.parent_category.slug}#{divider}#{self.slug}@#{domain}"
|
new_email_in = "#{self.parent_category.slug}#{divider}#{self.slug}@#{domain}"
|
||||||
else
|
else
|
||||||
new_email_in = "#{self.slug}@#{domain}"
|
new_email_in = "#{self.slug}@#{domain}"
|
||||||
|
|
|
@ -109,5 +109,34 @@ describe Category do
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when category has auto_email_in_disabled" do
|
||||||
|
context "and is child category" do
|
||||||
|
before { child.custom_fields["auto_email_in_disabled"] = true }
|
||||||
|
|
||||||
|
it "allows manually setting email-in" do
|
||||||
|
child.email_in = "manual@example.com"
|
||||||
|
child.save
|
||||||
|
expect(child.email_in).to eq "manual@example.com"
|
||||||
|
SiteSetting.auto_email_in_divider = "."
|
||||||
|
child.reload
|
||||||
|
expect(child.email_in).to eq "manual@example.com"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "and is parent category" do
|
||||||
|
before do
|
||||||
|
child.save
|
||||||
|
parent.custom_fields["auto_email_in_disabled"] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
it "doesn't update child categories" do
|
||||||
|
parent.slug = "new-parent"
|
||||||
|
parent.save
|
||||||
|
expect(parent.email_in).to eq "test-parent@example.com"
|
||||||
|
expect(child.email_in).to eq "test-parent+test-child@example.com"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче