diff --git a/db/migrate/067_add_is_default_to_domains.rb b/db/migrate/067_add_is_default_to_domains.rb new file mode 100644 index 0000000..f29e986 --- /dev/null +++ b/db/migrate/067_add_is_default_to_domains.rb @@ -0,0 +1,10 @@ +class AddIsDefaultToDomains < ActiveRecord::Migration + def self.up + add_column :domains, :is_default, :boolean, :default => false + execute('update domains set is_default = (1<0)') # set all to false + end + + def self.down + remove_column :domains, :is_default + end +end diff --git a/db/schema.rb b/db/schema.rb index ba371e3..159bdfc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 66) do +ActiveRecord::Schema.define(:version => 67) do create_table "article_versions", :force => true do |t| t.integer "article_id" @@ -87,8 +87,8 @@ ActiveRecord::Schema.define(:version => 66) do t.boolean "virtual", :default => false end - add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id" + add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" create_table "blocks", :force => true do |t| t.string "title" @@ -151,6 +151,7 @@ ActiveRecord::Schema.define(:version => 66) do t.string "name" t.string "owner_type" t.integer "owner_id" + t.boolean "is_default", :default => false end create_table "environments", :force => true do |t| @@ -286,8 +287,8 @@ ActiveRecord::Schema.define(:version => 66) do t.datetime "created_at" end - add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type" add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id" + add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type" create_table "tags", :force => true do |t| t.string "name" diff --git a/util/mail/postgresql/mail_users.sql b/util/mail/postgresql/mail_users.sql index 8e004f1..c18a49a 100644 --- a/util/mail/postgresql/mail_users.sql +++ b/util/mail/postgresql/mail_users.sql @@ -24,5 +24,28 @@ JOIN domains on domains.owner_type = 'Environment') WHERE users.password_type = 'md5' + AND domains.is_default AND users.enable_email; +CREATE OR REPLACE VIEW mail_aliases +AS +SELECT + users.login || '@' || domains_from.name as source, + users.login || '@' || domains_to.name as destination +from users +JOIN profiles on + (profiles.user_id = users.id and + profiles.type = 'Person') +JOIN environments on + (environments.id = profiles.environment_id) +JOIN domains domains_from on + (domains_from.owner_id = environments.id and + domains_from.owner_type = 'Environment' and + not domains_from.is_default) +JOIN domains domains_to on + (domains_to.owner_id = environments.id and + domains_to.owner_type = 'Environment' and + domains_to.is_default) +WHERE + users.password_type = 'md5' + AND users.enable_email; diff --git a/util/mail/postgresql/virtual_aliases.cf b/util/mail/postgresql/virtual_aliases.cf new file mode 100644 index 0000000..11f1e70 --- /dev/null +++ b/util/mail/postgresql/virtual_aliases.cf @@ -0,0 +1,6 @@ +user = pam +password = pam +dbname = noosfero_development +query = select destination from mail_aliases where source = '%s' +hosts = 127.0.0.1 +ssl = false -- libgit2 0.21.2