Commit 8e46142d8f49dc91d71cb3b1f4c3cc58921a9499
1 parent
70760079
Exists in
staging
and in
42 other branches
ActionItem305: handling e-mail for environments with multiple e-mails
Showing
4 changed files
with
43 additions
and
3 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | +class AddIsDefaultToDomains < ActiveRecord::Migration | |
| 2 | + def self.up | |
| 3 | + add_column :domains, :is_default, :boolean, :default => false | |
| 4 | + execute('update domains set is_default = (1<0)') # set all to false | |
| 5 | + end | |
| 6 | + | |
| 7 | + def self.down | |
| 8 | + remove_column :domains, :is_default | |
| 9 | + end | |
| 10 | +end | ... | ... |
db/schema.rb
| ... | ... | @@ -9,7 +9,7 @@ |
| 9 | 9 | # |
| 10 | 10 | # It's strongly recommended to check this file into your version control system. |
| 11 | 11 | |
| 12 | -ActiveRecord::Schema.define(:version => 66) do | |
| 12 | +ActiveRecord::Schema.define(:version => 67) do | |
| 13 | 13 | |
| 14 | 14 | create_table "article_versions", :force => true do |t| |
| 15 | 15 | t.integer "article_id" |
| ... | ... | @@ -87,8 +87,8 @@ ActiveRecord::Schema.define(:version => 66) do |
| 87 | 87 | t.boolean "virtual", :default => false |
| 88 | 88 | end |
| 89 | 89 | |
| 90 | - add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" | |
| 91 | 90 | add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id" |
| 91 | + add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" | |
| 92 | 92 | |
| 93 | 93 | create_table "blocks", :force => true do |t| |
| 94 | 94 | t.string "title" |
| ... | ... | @@ -151,6 +151,7 @@ ActiveRecord::Schema.define(:version => 66) do |
| 151 | 151 | t.string "name" |
| 152 | 152 | t.string "owner_type" |
| 153 | 153 | t.integer "owner_id" |
| 154 | + t.boolean "is_default", :default => false | |
| 154 | 155 | end |
| 155 | 156 | |
| 156 | 157 | create_table "environments", :force => true do |t| |
| ... | ... | @@ -286,8 +287,8 @@ ActiveRecord::Schema.define(:version => 66) do |
| 286 | 287 | t.datetime "created_at" |
| 287 | 288 | end |
| 288 | 289 | |
| 289 | - add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type" | |
| 290 | 290 | add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id" |
| 291 | + add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type" | |
| 291 | 292 | |
| 292 | 293 | create_table "tags", :force => true do |t| |
| 293 | 294 | t.string "name" | ... | ... |
util/mail/postgresql/mail_users.sql
| ... | ... | @@ -24,5 +24,28 @@ JOIN domains on |
| 24 | 24 | domains.owner_type = 'Environment') |
| 25 | 25 | WHERE |
| 26 | 26 | users.password_type = 'md5' |
| 27 | + AND domains.is_default | |
| 27 | 28 | AND users.enable_email; |
| 28 | 29 | |
| 30 | +CREATE OR REPLACE VIEW mail_aliases | |
| 31 | +AS | |
| 32 | +SELECT | |
| 33 | + users.login || '@' || domains_from.name as source, | |
| 34 | + users.login || '@' || domains_to.name as destination | |
| 35 | +from users | |
| 36 | +JOIN profiles on | |
| 37 | + (profiles.user_id = users.id and | |
| 38 | + profiles.type = 'Person') | |
| 39 | +JOIN environments on | |
| 40 | + (environments.id = profiles.environment_id) | |
| 41 | +JOIN domains domains_from on | |
| 42 | + (domains_from.owner_id = environments.id and | |
| 43 | + domains_from.owner_type = 'Environment' and | |
| 44 | + not domains_from.is_default) | |
| 45 | +JOIN domains domains_to on | |
| 46 | + (domains_to.owner_id = environments.id and | |
| 47 | + domains_to.owner_type = 'Environment' and | |
| 48 | + domains_to.is_default) | |
| 49 | +WHERE | |
| 50 | + users.password_type = 'md5' | |
| 51 | + AND users.enable_email; | ... | ... |