Commit a39b1635b2fa508858e6a99f3f4901240a152eb8
1 parent
c250cb47
Exists in
master
and in
29 other branches
ActionItem44: adding basic mail configuration
For now, user can only enable/disable e-mail account. git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1995 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
13 changed files
with
253 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,25 @@ |
1 | +class MailconfController < MyProfileController | |
2 | + | |
3 | + requires_profile_class Person | |
4 | + | |
5 | + protect 'edit_profile', :profile | |
6 | + | |
7 | + before_filter :check_mail_enabled | |
8 | + def check_mail_enabled | |
9 | + unless MailConf.enabled? | |
10 | + render :text => "Mail is not enabled in noosfero.", :status => 500 | |
11 | + end | |
12 | + end | |
13 | + | |
14 | + def index | |
15 | + @user = profile.user | |
16 | + end | |
17 | + | |
18 | + post_only :save | |
19 | + def save | |
20 | + profile.user.update_attributes(params[:user]) | |
21 | + flash[:notice] = _('e-Mail settings saved successfully.') | |
22 | + redirect_to :action => 'index' | |
23 | + end | |
24 | + | |
25 | +end | ... | ... |
... | ... | @@ -0,0 +1,25 @@ |
1 | +class MailConf | |
2 | + class << self | |
3 | + | |
4 | + def config_file | |
5 | + File.join(RAILS_ROOT, 'config', 'mail.yml') | |
6 | + end | |
7 | + | |
8 | + def config | |
9 | + if File.exists?(config_file) | |
10 | + YAML.load_file(config_file) | |
11 | + else | |
12 | + {} | |
13 | + end | |
14 | + end | |
15 | + | |
16 | + def enabled? | |
17 | + config['enabled'] || false | |
18 | + end | |
19 | + | |
20 | + def webmail_url | |
21 | + config['webmail_url'] | |
22 | + end | |
23 | + | |
24 | + end | |
25 | +end | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +<h1><%= _('e-Mail configuration') %></h1> | |
2 | + | |
3 | +<% form_tag(:action => 'save') do %> | |
4 | + | |
5 | + <div> | |
6 | + <%= check_box :user, :enable_email %> | |
7 | + <label for='user_enable_email'><%= _('Enable e-mail %s') % profile.email_addresses.join(', ') %></label> | |
8 | + <blockquote> | |
9 | + <%= _('Marking this options gives you an e-mail account with the address above.') %> | |
10 | + </blockquote> | |
11 | + </div> | |
12 | + | |
13 | + <% button_bar do %> | |
14 | + <%= submit_button :save, _('Save') %> | |
15 | + <%= button :back, _('Back to control panel'), :controller => 'profile_editor' %> | |
16 | + <% end %> | |
17 | +<% end %> | ... | ... |
app/views/profile_editor/index.rhtml
... | ... | @@ -8,6 +8,8 @@ |
8 | 8 | |
9 | 9 | <%= file_manager_button(_('Edit Profile'), 'icons-app/edit-profile.png', :controller => 'profile_editor', :action => 'edit') %> |
10 | 10 | |
11 | + <%= file_manager_button(_('Mail settings'), 'icons-app/mail.png', :controller => 'mailconf') if profile.person? && MailConf.enabled? %> | |
12 | + | |
11 | 13 | <%= file_manager_button(_('Pending tasks'), 'icons-app/todo.png', :controller => 'tasks', :action => 'index') %> |
12 | 14 | |
13 | 15 | <%= file_manager_button(_('Edit Visual Design'), 'icons-app/design-editor.png', :controller => 'profile_design', :action => 'index') %> | ... | ... |
db/schema.rb
... | ... | @@ -260,6 +260,7 @@ ActiveRecord::Schema.define(:version => 41) do |
260 | 260 | t.string "terms_accepted", :limit => 1 |
261 | 261 | t.integer "environment_id" |
262 | 262 | t.string "password_type" |
263 | + t.boolean "enable_email", :default => false | |
263 | 264 | end |
264 | 265 | |
265 | 266 | create_table "validation_infos", :force => true do |t| | ... | ... |
public/images/icons-app/README
4.84 KB
... | ... | @@ -0,0 +1,105 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class MailconfControllerTest < Test::Unit::TestCase | |
4 | + | |
5 | + all_fixtures | |
6 | + | |
7 | + def setup | |
8 | + @controller = MailconfController.new | |
9 | + @request = ActionController::TestRequest.new | |
10 | + @response = ActionController::TestResponse.new | |
11 | + | |
12 | + MailConf.stubs(:enabled?).returns(true) | |
13 | + end | |
14 | + | |
15 | + should 'check if mail is enabled' do | |
16 | + MailConf.expects(:enabled?).returns(false) | |
17 | + | |
18 | + login_as('ze') | |
19 | + get :index, :profile => 'ze' | |
20 | + assert_response 500 | |
21 | + end | |
22 | + | |
23 | + should 'not be used by organizations' do | |
24 | + org = Organization.create!(:name => 'testorg', :identifier => 'testorg') | |
25 | + get :index, :profile => 'testorg' | |
26 | + assert_response 403 | |
27 | + end | |
28 | + | |
29 | + should 'not be edited by others' do | |
30 | + login_as('johndoe') | |
31 | + get :index, :profile => 'ze' | |
32 | + assert_response 403 | |
33 | + end | |
34 | + | |
35 | + should 'be edited by owner' do | |
36 | + login_as('ze') | |
37 | + get :index, :profile => 'ze' | |
38 | + assert_response :success | |
39 | + end | |
40 | + | |
41 | + should 'expose user to templates' do | |
42 | + login_as('ze') | |
43 | + get :index, :profile => 'ze' | |
44 | + assert_equal users(:ze), assigns(:user) | |
45 | + end | |
46 | + | |
47 | + should 'present enable/disable for e-mail use' do | |
48 | + login_as('ze') | |
49 | + get :index, :profile => 'ze' | |
50 | + assert_tag( | |
51 | + :tag => 'form', | |
52 | + :attributes => { :action => '/myprofile/ze/mailconf/save'}, | |
53 | + :descendant => { | |
54 | + :tag => 'input', | |
55 | + :attributes => { :name => 'user[enable_email]', :type => 'checkbox' } | |
56 | + } | |
57 | + ) | |
58 | + end | |
59 | + | |
60 | + should 'display correctly the state true of e-mail enable/disable' do | |
61 | + login_as('ze') | |
62 | + users(:ze).update_attributes!(:enable_email => true) | |
63 | + get :index, :profile => 'ze' | |
64 | + assert_tag :tag => 'input', :attributes => { :name => 'user[enable_email]', :type => 'checkbox', :value => '1', :checked => 'checked' } | |
65 | + end | |
66 | + | |
67 | + should 'display correctly the state false of e-mail enable/disable' do | |
68 | + login_as('ze') | |
69 | + users(:ze).update_attributes!(:enable_email => false) | |
70 | + get :index, :profile => 'ze' | |
71 | + assert_no_tag :tag => 'input', :attributes => { :name => 'user[enable_email]', :type => 'checkbox', :value => '1', :checked => 'checked' } | |
72 | + assert_tag :tag => 'input', :attributes => { :name => 'user[enable_email]', :type => 'hidden', :value => '0' } | |
73 | + end | |
74 | + | |
75 | + should 'save mail enable/disable as true' do | |
76 | + login_as('ze') | |
77 | + post :save, :profile => 'ze', :user => { :enable_email => '1' } | |
78 | + assert Profile['ze'].user.enable_email | |
79 | + end | |
80 | + | |
81 | + should 'save mail enable/disable as false' do | |
82 | + login_as('ze') | |
83 | + post :save, :profile => 'ze', :user => { :enable_email => '0' } | |
84 | + assert !Profile['ze'].user.enable_email | |
85 | + end | |
86 | + | |
87 | + should 'go back on save' do | |
88 | + login_as('ze') | |
89 | + post :save, :profile => 'ze' | |
90 | + assert_redirected_to :action => 'index' | |
91 | + end | |
92 | + | |
93 | + should 'display notice after saving' do | |
94 | + login_as('ze') | |
95 | + post :save, :profile => 'ze' | |
96 | + assert_kind_of String, flash[:notice] | |
97 | + end | |
98 | + | |
99 | + should 'link back to control panel' do | |
100 | + login_as('ze') | |
101 | + get :index, :profile => 'ze' | |
102 | + assert_tag :tag => 'div', :attributes => { :id => 'content'}, :descendant => { :tag => 'a', :attributes => { :href => '/myprofile/ze' } } | |
103 | + end | |
104 | + | |
105 | +end | ... | ... |
test/functional/profile_editor_controller_test.rb
... | ... | @@ -341,4 +341,23 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
341 | 341 | assert_no_tag :tag => 'a', :content => 'Favorite Enterprises' |
342 | 342 | end |
343 | 343 | |
344 | + should 'link to mailconf' do | |
345 | + MailConf.expects(:enabled?).returns(true) | |
346 | + get :index, :profile => 'ze' | |
347 | + assert_tag :tag => 'a', :attributes => { :href => '/myprofile/ze/mailconf' } | |
348 | + end | |
349 | + | |
350 | + should 'not link to mailconf for organizations' do | |
351 | + MailConf.stubs(:enabled?).returns(true) | |
352 | + org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact') | |
353 | + get :index, :profile => 'testorg' | |
354 | + assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/testorg/mailconf' } | |
355 | + end | |
356 | + | |
357 | + should 'not link to mailconf if mail not enabled' do | |
358 | + MailConf.expects(:enabled?).returns(false) | |
359 | + get :index, :profile => 'ze' | |
360 | + assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/ze/mailconf' } | |
361 | + end | |
362 | + | |
344 | 363 | end | ... | ... |
... | ... | @@ -0,0 +1,38 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | + | |
3 | +class MailConfTest < ActiveSupport::TestCase | |
4 | + | |
5 | + CONFIG_FILE = '/not/existing.yml' | |
6 | + | |
7 | + should 'use config/mail.yml as config' do | |
8 | + assert_equal RAILS_ROOT + '/config/mail.yml', MailConf.config_file | |
9 | + end | |
10 | + | |
11 | + should 'enable if told to' do | |
12 | + MailConf.stubs(:config_file).returns(CONFIG_FILE) | |
13 | + File.expects(:exists?).with(CONFIG_FILE).returns(true) | |
14 | + YAML.expects(:load_file).with(CONFIG_FILE).returns({ 'enabled' => true}) | |
15 | + assert_equal true, MailConf.enabled? | |
16 | + end | |
17 | + | |
18 | + should 'disable if told to' do | |
19 | + MailConf.stubs(:config_file).returns(CONFIG_FILE) | |
20 | + File.expects(:exists?).with(CONFIG_FILE).returns(true) | |
21 | + YAML.expects(:load_file).with(CONFIG_FILE).returns({ 'enabled' => false }) | |
22 | + assert_equal false, MailConf.enabled? | |
23 | + end | |
24 | + | |
25 | + should 'disable if config file not present' do | |
26 | + MailConf.stubs(:config_file).returns(CONFIG_FILE) | |
27 | + File.expects(:exists?).with(CONFIG_FILE).returns(false) | |
28 | + assert_equal false, MailConf.enabled? | |
29 | + end | |
30 | + | |
31 | + should 'provide webmail url preference' do | |
32 | + MailConf.stubs(:config_file).returns(CONFIG_FILE) | |
33 | + File.expects(:exists?).with(CONFIG_FILE).returns(true) | |
34 | + YAML.expects(:load_file).with(CONFIG_FILE).returns({ 'enabled' => false, 'webmail_url' => 'http://some.url/webmail' }) | |
35 | + assert_equal 'http://some.url/webmail', MailConf.webmail_url | |
36 | + end | |
37 | + | |
38 | +end | ... | ... |
test/unit/user_test.rb
... | ... | @@ -251,6 +251,16 @@ class UserTest < Test::Unit::TestCase |
251 | 251 | assert_equal crypted_password, user.crypted_password |
252 | 252 | end |
253 | 253 | |
254 | + def test_should_have_enable_email_setting | |
255 | + u = User.new | |
256 | + u.enable_email = true | |
257 | + assert_equal true, u.enable_email | |
258 | + end | |
259 | + | |
260 | + def test_should_have_enable_email_as_false_by_default | |
261 | + assert_equal false, User.new.enable_email | |
262 | + end | |
263 | + | |
254 | 264 | protected |
255 | 265 | def create_user(options = {}) |
256 | 266 | User.create({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) | ... | ... |