Commit 8e46142d8f49dc91d71cb3b1f4c3cc58921a9499
1 parent
70760079
Exists in
master
and in
29 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 @@ | @@ -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,7 +9,7 @@ | ||
9 | # | 9 | # |
10 | # It's strongly recommended to check this file into your version control system. | 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 | create_table "article_versions", :force => true do |t| | 14 | create_table "article_versions", :force => true do |t| |
15 | t.integer "article_id" | 15 | t.integer "article_id" |
@@ -87,8 +87,8 @@ ActiveRecord::Schema.define(:version => 66) do | @@ -87,8 +87,8 @@ ActiveRecord::Schema.define(:version => 66) do | ||
87 | t.boolean "virtual", :default => false | 87 | t.boolean "virtual", :default => false |
88 | end | 88 | end |
89 | 89 | ||
90 | - add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" | ||
91 | add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id" | 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 | create_table "blocks", :force => true do |t| | 93 | create_table "blocks", :force => true do |t| |
94 | t.string "title" | 94 | t.string "title" |
@@ -151,6 +151,7 @@ ActiveRecord::Schema.define(:version => 66) do | @@ -151,6 +151,7 @@ ActiveRecord::Schema.define(:version => 66) do | ||
151 | t.string "name" | 151 | t.string "name" |
152 | t.string "owner_type" | 152 | t.string "owner_type" |
153 | t.integer "owner_id" | 153 | t.integer "owner_id" |
154 | + t.boolean "is_default", :default => false | ||
154 | end | 155 | end |
155 | 156 | ||
156 | create_table "environments", :force => true do |t| | 157 | create_table "environments", :force => true do |t| |
@@ -286,8 +287,8 @@ ActiveRecord::Schema.define(:version => 66) do | @@ -286,8 +287,8 @@ ActiveRecord::Schema.define(:version => 66) do | ||
286 | t.datetime "created_at" | 287 | t.datetime "created_at" |
287 | end | 288 | end |
288 | 289 | ||
289 | - add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type" | ||
290 | add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id" | 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 | create_table "tags", :force => true do |t| | 293 | create_table "tags", :force => true do |t| |
293 | t.string "name" | 294 | t.string "name" |
util/mail/postgresql/mail_users.sql
@@ -24,5 +24,28 @@ JOIN domains on | @@ -24,5 +24,28 @@ JOIN domains on | ||
24 | domains.owner_type = 'Environment') | 24 | domains.owner_type = 'Environment') |
25 | WHERE | 25 | WHERE |
26 | users.password_type = 'md5' | 26 | users.password_type = 'md5' |
27 | + AND domains.is_default | ||
27 | AND users.enable_email; | 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; |