diff --git a/app/controllers/my_profile/mailconf_controller.rb b/app/controllers/my_profile/mailconf_controller.rb
new file mode 100644
index 0000000..1cefbe4
--- /dev/null
+++ b/app/controllers/my_profile/mailconf_controller.rb
@@ -0,0 +1,25 @@
+class MailconfController < MyProfileController
+
+ requires_profile_class Person
+
+ protect 'edit_profile', :profile
+
+ before_filter :check_mail_enabled
+ def check_mail_enabled
+ unless MailConf.enabled?
+ render :text => "Mail is not enabled in noosfero.", :status => 500
+ end
+ end
+
+ def index
+ @user = profile.user
+ end
+
+ post_only :save
+ def save
+ profile.user.update_attributes(params[:user])
+ flash[:notice] = _('e-Mail settings saved successfully.')
+ redirect_to :action => 'index'
+ end
+
+end
diff --git a/app/models/mail_conf.rb b/app/models/mail_conf.rb
new file mode 100644
index 0000000..540fb52
--- /dev/null
+++ b/app/models/mail_conf.rb
@@ -0,0 +1,25 @@
+class MailConf
+ class << self
+
+ def config_file
+ File.join(RAILS_ROOT, 'config', 'mail.yml')
+ end
+
+ def config
+ if File.exists?(config_file)
+ YAML.load_file(config_file)
+ else
+ {}
+ end
+ end
+
+ def enabled?
+ config['enabled'] || false
+ end
+
+ def webmail_url
+ config['webmail_url']
+ end
+
+ end
+end
diff --git a/app/views/mailconf/index.rhtml b/app/views/mailconf/index.rhtml
new file mode 100644
index 0000000..4694894
--- /dev/null
+++ b/app/views/mailconf/index.rhtml
@@ -0,0 +1,17 @@
+
<%= _('e-Mail configuration') %>
+
+<% form_tag(:action => 'save') do %>
+
+
+ <%= check_box :user, :enable_email %>
+
+
+ <%= _('Marking this options gives you an e-mail account with the address above.') %>
+
+
+
+ <% button_bar do %>
+ <%= submit_button :save, _('Save') %>
+ <%= button :back, _('Back to control panel'), :controller => 'profile_editor' %>
+ <% end %>
+<% end %>
diff --git a/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml
index 2270fd7..300397b 100644
--- a/app/views/profile_editor/index.rhtml
+++ b/app/views/profile_editor/index.rhtml
@@ -8,6 +8,8 @@
<%= file_manager_button(_('Edit Profile'), 'icons-app/edit-profile.png', :controller => 'profile_editor', :action => 'edit') %>
+ <%= file_manager_button(_('Mail settings'), 'icons-app/mail.png', :controller => 'mailconf') if profile.person? && MailConf.enabled? %>
+
<%= file_manager_button(_('Pending tasks'), 'icons-app/todo.png', :controller => 'tasks', :action => 'index') %>
<%= file_manager_button(_('Edit Visual Design'), 'icons-app/design-editor.png', :controller => 'profile_design', :action => 'index') %>
diff --git a/db/migrate/040_add_enable_email_to_user.rb b/db/migrate/040_add_enable_email_to_user.rb
new file mode 100644
index 0000000..45c7387
--- /dev/null
+++ b/db/migrate/040_add_enable_email_to_user.rb
@@ -0,0 +1,9 @@
+class AddEnableEmailToUser < ActiveRecord::Migration
+ def self.up
+ add_column :users, :enable_email, :boolean, :default => false
+ end
+
+ def self.down
+ remove_column :users, :enable_email
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 398deaf..a1bd028 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -260,6 +260,7 @@ ActiveRecord::Schema.define(:version => 41) do
t.string "terms_accepted", :limit => 1
t.integer "environment_id"
t.string "password_type"
+ t.boolean "enable_email", :default => false
end
create_table "validation_infos", :force => true do |t|
diff --git a/public/images/icons-app/README b/public/images/icons-app/README
index 1f89bb4..9a914f8 100644
--- a/public/images/icons-app/README
+++ b/public/images/icons-app/README
@@ -41,6 +41,7 @@ stock_todo.png Nuovo
friends.png (modified version of users.png) Nuovo
gtk-folder.png Nuovo
epiphany-bookmarks.png dlg-neu
+mozilla-mail.png dlg-neu
### END OF ICONS LISTING ###
Icons rasterization
diff --git a/public/images/icons-app/mail.png b/public/images/icons-app/mail.png
new file mode 120000
index 0000000..1cfb7ba
--- /dev/null
+++ b/public/images/icons-app/mail.png
@@ -0,0 +1 @@
+mozilla-mail.png
\ No newline at end of file
diff --git a/public/images/icons-app/mozilla-mail.png b/public/images/icons-app/mozilla-mail.png
new file mode 100644
index 0000000..e255957
Binary files /dev/null and b/public/images/icons-app/mozilla-mail.png differ
diff --git a/test/functional/mailconf_controller_test.rb b/test/functional/mailconf_controller_test.rb
new file mode 100644
index 0000000..351bbd6
--- /dev/null
+++ b/test/functional/mailconf_controller_test.rb
@@ -0,0 +1,105 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class MailconfControllerTest < Test::Unit::TestCase
+
+ all_fixtures
+
+ def setup
+ @controller = MailconfController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+
+ MailConf.stubs(:enabled?).returns(true)
+ end
+
+ should 'check if mail is enabled' do
+ MailConf.expects(:enabled?).returns(false)
+
+ login_as('ze')
+ get :index, :profile => 'ze'
+ assert_response 500
+ end
+
+ should 'not be used by organizations' do
+ org = Organization.create!(:name => 'testorg', :identifier => 'testorg')
+ get :index, :profile => 'testorg'
+ assert_response 403
+ end
+
+ should 'not be edited by others' do
+ login_as('johndoe')
+ get :index, :profile => 'ze'
+ assert_response 403
+ end
+
+ should 'be edited by owner' do
+ login_as('ze')
+ get :index, :profile => 'ze'
+ assert_response :success
+ end
+
+ should 'expose user to templates' do
+ login_as('ze')
+ get :index, :profile => 'ze'
+ assert_equal users(:ze), assigns(:user)
+ end
+
+ should 'present enable/disable for e-mail use' do
+ login_as('ze')
+ get :index, :profile => 'ze'
+ assert_tag(
+ :tag => 'form',
+ :attributes => { :action => '/myprofile/ze/mailconf/save'},
+ :descendant => {
+ :tag => 'input',
+ :attributes => { :name => 'user[enable_email]', :type => 'checkbox' }
+ }
+ )
+ end
+
+ should 'display correctly the state true of e-mail enable/disable' do
+ login_as('ze')
+ users(:ze).update_attributes!(:enable_email => true)
+ get :index, :profile => 'ze'
+ assert_tag :tag => 'input', :attributes => { :name => 'user[enable_email]', :type => 'checkbox', :value => '1', :checked => 'checked' }
+ end
+
+ should 'display correctly the state false of e-mail enable/disable' do
+ login_as('ze')
+ users(:ze).update_attributes!(:enable_email => false)
+ get :index, :profile => 'ze'
+ assert_no_tag :tag => 'input', :attributes => { :name => 'user[enable_email]', :type => 'checkbox', :value => '1', :checked => 'checked' }
+ assert_tag :tag => 'input', :attributes => { :name => 'user[enable_email]', :type => 'hidden', :value => '0' }
+ end
+
+ should 'save mail enable/disable as true' do
+ login_as('ze')
+ post :save, :profile => 'ze', :user => { :enable_email => '1' }
+ assert Profile['ze'].user.enable_email
+ end
+
+ should 'save mail enable/disable as false' do
+ login_as('ze')
+ post :save, :profile => 'ze', :user => { :enable_email => '0' }
+ assert !Profile['ze'].user.enable_email
+ end
+
+ should 'go back on save' do
+ login_as('ze')
+ post :save, :profile => 'ze'
+ assert_redirected_to :action => 'index'
+ end
+
+ should 'display notice after saving' do
+ login_as('ze')
+ post :save, :profile => 'ze'
+ assert_kind_of String, flash[:notice]
+ end
+
+ should 'link back to control panel' do
+ login_as('ze')
+ get :index, :profile => 'ze'
+ assert_tag :tag => 'div', :attributes => { :id => 'content'}, :descendant => { :tag => 'a', :attributes => { :href => '/myprofile/ze' } }
+ end
+
+end
diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb
index ef0c2ea..13e813c 100644
--- a/test/functional/profile_editor_controller_test.rb
+++ b/test/functional/profile_editor_controller_test.rb
@@ -341,4 +341,23 @@ class ProfileEditorControllerTest < Test::Unit::TestCase
assert_no_tag :tag => 'a', :content => 'Favorite Enterprises'
end
+ should 'link to mailconf' do
+ MailConf.expects(:enabled?).returns(true)
+ get :index, :profile => 'ze'
+ assert_tag :tag => 'a', :attributes => { :href => '/myprofile/ze/mailconf' }
+ end
+
+ should 'not link to mailconf for organizations' do
+ MailConf.stubs(:enabled?).returns(true)
+ org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact')
+ get :index, :profile => 'testorg'
+ assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/testorg/mailconf' }
+ end
+
+ should 'not link to mailconf if mail not enabled' do
+ MailConf.expects(:enabled?).returns(false)
+ get :index, :profile => 'ze'
+ assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/ze/mailconf' }
+ end
+
end
diff --git a/test/unit/mail_conf_test.rb b/test/unit/mail_conf_test.rb
new file mode 100644
index 0000000..91c58ad
--- /dev/null
+++ b/test/unit/mail_conf_test.rb
@@ -0,0 +1,38 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class MailConfTest < ActiveSupport::TestCase
+
+ CONFIG_FILE = '/not/existing.yml'
+
+ should 'use config/mail.yml as config' do
+ assert_equal RAILS_ROOT + '/config/mail.yml', MailConf.config_file
+ end
+
+ should 'enable if told to' do
+ MailConf.stubs(:config_file).returns(CONFIG_FILE)
+ File.expects(:exists?).with(CONFIG_FILE).returns(true)
+ YAML.expects(:load_file).with(CONFIG_FILE).returns({ 'enabled' => true})
+ assert_equal true, MailConf.enabled?
+ end
+
+ should 'disable if told to' do
+ MailConf.stubs(:config_file).returns(CONFIG_FILE)
+ File.expects(:exists?).with(CONFIG_FILE).returns(true)
+ YAML.expects(:load_file).with(CONFIG_FILE).returns({ 'enabled' => false })
+ assert_equal false, MailConf.enabled?
+ end
+
+ should 'disable if config file not present' do
+ MailConf.stubs(:config_file).returns(CONFIG_FILE)
+ File.expects(:exists?).with(CONFIG_FILE).returns(false)
+ assert_equal false, MailConf.enabled?
+ end
+
+ should 'provide webmail url preference' do
+ MailConf.stubs(:config_file).returns(CONFIG_FILE)
+ File.expects(:exists?).with(CONFIG_FILE).returns(true)
+ YAML.expects(:load_file).with(CONFIG_FILE).returns({ 'enabled' => false, 'webmail_url' => 'http://some.url/webmail' })
+ assert_equal 'http://some.url/webmail', MailConf.webmail_url
+ end
+
+end
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index 126224c..a73faec 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -251,6 +251,16 @@ class UserTest < Test::Unit::TestCase
assert_equal crypted_password, user.crypted_password
end
+ def test_should_have_enable_email_setting
+ u = User.new
+ u.enable_email = true
+ assert_equal true, u.enable_email
+ end
+
+ def test_should_have_enable_email_as_false_by_default
+ assert_equal false, User.new.enable_email
+ end
+
protected
def create_user(options = {})
User.create({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options))
--
libgit2 0.21.2