add 'incoming_email' to groups
This commit is contained in:
parent
fa6687841f
commit
578f606a1a
|
@ -92,6 +92,11 @@
|
|||
<label for="grant_trust_level">{{i18n 'groups.trust_levels.title'}}</label>
|
||||
{{combo-box name="grant_trust_level" valueAttribute="value" value=model.grant_trust_level content=trustLevelOptions}}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="incoming_email">{{i18n 'admin.groups.incoming_email'}}</label>
|
||||
{{text-field name="incoming_email" value=model.incoming_email placeholderKey="admin.groups.incoming_email_placeholder"}}
|
||||
</div>
|
||||
{{/unless}}
|
||||
|
||||
<div class='buttons'>
|
||||
|
|
|
@ -98,7 +98,8 @@ const Group = Discourse.Model.extend({
|
|||
automatic_membership_retroactive: !!this.get('automatic_membership_retroactive'),
|
||||
title: this.get('title'),
|
||||
primary_group: !!this.get('primary_group'),
|
||||
grant_trust_level: this.get('grant_trust_level')
|
||||
grant_trust_level: this.get('grant_trust_level'),
|
||||
incoming_email: this.get("incoming_email"),
|
||||
};
|
||||
},
|
||||
|
||||
|
|
|
@ -81,6 +81,8 @@ class Admin::GroupsController < Admin::AdminController
|
|||
|
||||
group.primary_group = group.automatic ? false : params["primary_group"] == "true"
|
||||
|
||||
group.incoming_email = group.automatic ? nil : params[:incoming_email]
|
||||
|
||||
title = params[:title] if params[:title].present?
|
||||
group.title = group.automatic ? nil : title
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@ class Group < ActiveRecord::Base
|
|||
has_many :categories, through: :category_groups
|
||||
has_many :users, through: :group_users
|
||||
|
||||
before_save :downcase_incoming_email
|
||||
|
||||
after_save :destroy_deletions
|
||||
after_save :automatic_group_membership
|
||||
after_save :update_primary_group
|
||||
|
@ -23,6 +25,7 @@ class Group < ActiveRecord::Base
|
|||
validate :name_format_validator
|
||||
validates_uniqueness_of :name, case_sensitive: false
|
||||
validate :automatic_membership_email_domains_format_validator
|
||||
validate :incoming_email_validator
|
||||
|
||||
AUTO_GROUPS = {
|
||||
:everyone => 0,
|
||||
|
@ -70,6 +73,17 @@ class Group < ActiveRecord::Base
|
|||
)", levels: levels, user_id: user && user.id )
|
||||
}
|
||||
|
||||
def downcase_incoming_email
|
||||
self.incoming_email = (incoming_email || "").strip.downcase.presence
|
||||
end
|
||||
|
||||
def incoming_email_validator
|
||||
return if self.automatic || self.incoming_email.blank?
|
||||
unless Email.is_valid?(incoming_email)
|
||||
self.errors.add(:base, I18n.t('groups.errors.invalid_incoming_email', incoming_email: incoming_email))
|
||||
end
|
||||
end
|
||||
|
||||
def posts_for(guardian, before_post_id=nil)
|
||||
user_ids = group_users.map {|gu| gu.user_id}
|
||||
result = Post.where(user_id: user_ids).includes(:user, :topic, :topic => :category).references(:posts, :topics, :category)
|
||||
|
|
|
@ -9,5 +9,10 @@ class BasicGroupSerializer < ApplicationSerializer
|
|||
:automatic_membership_retroactive,
|
||||
:primary_group,
|
||||
:title,
|
||||
:grant_trust_level
|
||||
:grant_trust_level,
|
||||
:incoming_email
|
||||
|
||||
def include_incoming_email?
|
||||
scope.is_staff?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1958,6 +1958,8 @@ en:
|
|||
primary_group: "Automatically set as primary group"
|
||||
group_owners: Owners
|
||||
add_owners: Add owners
|
||||
incoming_email: "Custom incoming email address"
|
||||
incoming_email_placeholder: "enter email address"
|
||||
|
||||
|
||||
api:
|
||||
|
|
|
@ -194,6 +194,7 @@ en:
|
|||
can_not_modify_automatic: "You can not modify an automatic group"
|
||||
member_already_exist: "'%{username}' is already a member of this group."
|
||||
invalid_domain: "'%{domain}' is not a valid domain."
|
||||
invalid_incoming_email: "'%{incoming_email}' is not a valid email address."
|
||||
default_names:
|
||||
everyone: "everyone"
|
||||
admins: "admins"
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class AddIncomingEmailToGroups < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :groups, :incoming_email, :string, null: true
|
||||
add_index :groups, :incoming_email, unique: true
|
||||
end
|
||||
end
|
|
@ -30,7 +30,8 @@ describe Admin::GroupsController do
|
|||
"automatic_membership_retroactive"=>false,
|
||||
"title"=>nil,
|
||||
"primary_group"=>false,
|
||||
"grant_trust_level"=>nil
|
||||
"grant_trust_level"=>nil,
|
||||
"incoming_email"=>nil
|
||||
}])
|
||||
end
|
||||
|
||||
|
|
|
@ -43,6 +43,16 @@ describe Group do
|
|||
group.automatic_membership_email_domains = "discourse.org|wikipedia.org"
|
||||
expect(group.valid?).to eq true
|
||||
end
|
||||
|
||||
it "is invalid for bad incoming email" do
|
||||
group.incoming_email = "foo.bar.org"
|
||||
expect(group.valid?).to eq(false)
|
||||
end
|
||||
|
||||
it "is valid for proper incoming email" do
|
||||
group.incoming_email = "foo@bar.org"
|
||||
expect(group.valid?).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
def real_admins
|
||||
|
|
Loading…
Reference in New Issue