Commit 2d904cef0765a28161e2c6c0b8a4e239ace24845
1 parent
dd777a43
Exists in
master
and in
29 other branches
ActionItem897: users must be approved before being able to use e-mail
Showing
26 changed files
with
323 additions
and
56 deletions
Show diff stats
app/controllers/my_profile/mailconf_controller.rb
@@ -15,11 +15,27 @@ class MailconfController < MyProfileController | @@ -15,11 +15,27 @@ class MailconfController < MyProfileController | ||
15 | @user = profile.user | 15 | @user = profile.user |
16 | end | 16 | end |
17 | 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' | 18 | + post_only :enable |
19 | + def enable | ||
20 | + @task = EmailActivation.new(:target => environment, :requestor => profile) | ||
21 | + begin | ||
22 | + @task.save! | ||
23 | + flash[:notice] = _('Please fill your personal information below in order to get your mailbox approved by one of the administrators') | ||
24 | + redirect_to :controller => 'profile_editor', :action => 'edit' | ||
25 | + rescue Exception => ex | ||
26 | + flash[:notice] = _('e-Mail was not enabled successfully.') | ||
27 | + render :action => 'index' | ||
28 | + end | ||
29 | + end | ||
30 | + post_only :disable | ||
31 | + def disable | ||
32 | + if profile.user.disable_email! | ||
33 | + flash[:notice] = _('e-Mail disabled successfully.') | ||
34 | + redirect_to :controller => 'profile_editor' | ||
35 | + else | ||
36 | + flash[:notice] = _('e-Mail was not disabled successfully.') | ||
37 | + redirect_to :action => 'index' | ||
38 | + end | ||
23 | end | 39 | end |
24 | 40 | ||
25 | end | 41 | end |
app/controllers/my_profile/profile_editor_controller.rb
@@ -3,7 +3,7 @@ class ProfileEditorController < MyProfileController | @@ -3,7 +3,7 @@ class ProfileEditorController < MyProfileController | ||
3 | protect 'edit_profile', :profile | 3 | protect 'edit_profile', :profile |
4 | 4 | ||
5 | def index | 5 | def index |
6 | - @pending_tasks = profile.tasks.pending.select{|i| user.has_permission?(i.permission, profile)} | 6 | + @pending_tasks = profile.all_pending_tasks.select{|i| user.has_permission?(i.permission, profile)} |
7 | end | 7 | end |
8 | 8 | ||
9 | helper :profile | 9 | helper :profile |
app/controllers/my_profile/tasks_controller.rb
@@ -3,11 +3,11 @@ class TasksController < MyProfileController | @@ -3,11 +3,11 @@ class TasksController < MyProfileController | ||
3 | protect 'perform_task', :profile | 3 | protect 'perform_task', :profile |
4 | 4 | ||
5 | def index | 5 | def index |
6 | - @tasks = profile.tasks.pending | 6 | + @tasks = profile.all_pending_tasks |
7 | end | 7 | end |
8 | 8 | ||
9 | def processed | 9 | def processed |
10 | - @tasks = profile.tasks.finished | 10 | + @tasks = profile.all_finished_tasks |
11 | end | 11 | end |
12 | 12 | ||
13 | VALID_DECISIONS = [ 'finish', 'cancel' ] | 13 | VALID_DECISIONS = [ 'finish', 'cancel' ] |
@@ -15,7 +15,7 @@ class TasksController < MyProfileController | @@ -15,7 +15,7 @@ class TasksController < MyProfileController | ||
15 | def close | 15 | def close |
16 | decision = params[:decision] | 16 | decision = params[:decision] |
17 | if request.post? && VALID_DECISIONS.include?(decision) && params[:id] | 17 | if request.post? && VALID_DECISIONS.include?(decision) && params[:id] |
18 | - task = profile.tasks.find(params[:id]) | 18 | + task = profile.find_in_all_tasks(params[:id]) |
19 | task.update_attributes!(params[:task]) | 19 | task.update_attributes!(params[:task]) |
20 | task.send(decision) | 20 | task.send(decision) |
21 | end | 21 | end |
app/controllers/public/enterprise_registration_controller.rb
@@ -10,6 +10,9 @@ class EnterpriseRegistrationController < ApplicationController | @@ -10,6 +10,9 @@ class EnterpriseRegistrationController < ApplicationController | ||
10 | # to the first step explicitly? | 10 | # to the first step explicitly? |
11 | def index | 11 | def index |
12 | @create_enterprise = CreateEnterprise.new(params[:create_enterprise]) | 12 | @create_enterprise = CreateEnterprise.new(params[:create_enterprise]) |
13 | + if params[:create_enterprise] && params[:create_enterprise][:target_id] | ||
14 | + @create_enterprise.target = Profile.find(params[:create_enterprise][:target_id]) | ||
15 | + end | ||
13 | @create_enterprise.requestor = current_user.person | 16 | @create_enterprise.requestor = current_user.person |
14 | the_action = | 17 | the_action = |
15 | if request.post? | 18 | if request.post? |
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +class EmailActivation < Task | ||
2 | + | ||
3 | + validates_presence_of :requestor_id, :target_id | ||
4 | + | ||
5 | + alias :environment :target | ||
6 | + alias :person :requestor | ||
7 | + | ||
8 | + def validate_on_create | ||
9 | + if !self.requestor.nil? && self.requestor.user.email_activation_pending? | ||
10 | + self.errors.add_to_base(_('You have already requested activation of your mailbox.')) | ||
11 | + end | ||
12 | + end | ||
13 | + | ||
14 | + def description | ||
15 | + _("'%{user} wants to activate email '%{email}'") % { :user => person.name, :email => person.email_addresses.join(', ') } | ||
16 | + end | ||
17 | + | ||
18 | + def perform | ||
19 | + person.user.enable_email! | ||
20 | + end | ||
21 | + | ||
22 | + def sends_email? | ||
23 | + false | ||
24 | + end | ||
25 | + | ||
26 | +end |
app/models/environment.rb
@@ -3,6 +3,8 @@ | @@ -3,6 +3,8 @@ | ||
3 | # domains. | 3 | # domains. |
4 | class Environment < ActiveRecord::Base | 4 | class Environment < ActiveRecord::Base |
5 | 5 | ||
6 | + has_many :tasks, :dependent => :destroy, :as => 'target' | ||
7 | + | ||
6 | PERMISSIONS['Environment'] = { | 8 | PERMISSIONS['Environment'] = { |
7 | 'view_environment_admin_panel' => N_('View environment admin panel'), | 9 | 'view_environment_admin_panel' => N_('View environment admin panel'), |
8 | 'edit_environment_features' => N_('Edit environment features'), | 10 | 'edit_environment_features' => N_('Edit environment features'), |
app/models/profile.rb
@@ -103,7 +103,32 @@ class Profile < ActiveRecord::Base | @@ -103,7 +103,32 @@ class Profile < ActiveRecord::Base | ||
103 | has_many :consumptions | 103 | has_many :consumptions |
104 | has_many :consumed_product_categories, :through => :consumptions, :source => :product_category | 104 | has_many :consumed_product_categories, :through => :consumptions, :source => :product_category |
105 | 105 | ||
106 | - has_many :tasks, :foreign_key => :target_id, :dependent => :destroy | 106 | + has_many :tasks, :dependent => :destroy, :as => 'target' |
107 | + | ||
108 | + %w[ pending finished ].each do |status| | ||
109 | + class_eval <<-CODE | ||
110 | + def all_#{status}_tasks | ||
111 | + env_tasks = [] | ||
112 | + if self.person? | ||
113 | + env_tasks = Environment.find(:all).select{ |env| self.is_admin?(env) }.map{ |env| env.tasks.#{status} }.flatten | ||
114 | + end | ||
115 | + tasks.#{status} + env_tasks | ||
116 | + end | ||
117 | + CODE | ||
118 | + end | ||
119 | + | ||
120 | + def find_in_all_tasks(task_id) | ||
121 | + if tasks.exists?(task_id) | ||
122 | + return tasks.find(task_id) | ||
123 | + else | ||
124 | + if self.person? | ||
125 | + environments_admin = Environment.find(:all).select{ |env| self.is_admin?(env) } | ||
126 | + task = environments_admin.select{ |env| env.tasks.exists?(task_id) }.map{ |i| i.tasks.find(task_id) } | ||
127 | + return task.first unless task.empty? | ||
128 | + end | ||
129 | + end | ||
130 | + return nil | ||
131 | + end | ||
107 | 132 | ||
108 | has_many :profile_categorizations, :conditions => [ 'categories_profiles.virtual = ?', false ] | 133 | has_many :profile_categorizations, :conditions => [ 'categories_profiles.virtual = ?', false ] |
109 | has_many :categories, :through => :profile_categorizations | 134 | has_many :categories, :through => :profile_categorizations |
app/models/task.rb
@@ -28,7 +28,7 @@ class Task < ActiveRecord::Base | @@ -28,7 +28,7 @@ class Task < ActiveRecord::Base | ||
28 | end | 28 | end |
29 | 29 | ||
30 | belongs_to :requestor, :class_name => 'Person', :foreign_key => :requestor_id | 30 | belongs_to :requestor, :class_name => 'Person', :foreign_key => :requestor_id |
31 | - belongs_to :target, :class_name => 'Profile', :foreign_key => :target_id | 31 | + belongs_to :target, :foreign_key => :target_id, :polymorphic => true |
32 | 32 | ||
33 | validates_uniqueness_of :code, :on => :create | 33 | validates_uniqueness_of :code, :on => :create |
34 | validates_presence_of :code | 34 | validates_presence_of :code |
app/models/user.rb
@@ -185,6 +185,22 @@ class User < ActiveRecord::Base | @@ -185,6 +185,22 @@ class User < ActiveRecord::Base | ||
185 | person.name | 185 | person.name |
186 | end | 186 | end |
187 | 187 | ||
188 | + def enable_email! | ||
189 | + self.update_attribute(:enable_email, true) | ||
190 | + end | ||
191 | + | ||
192 | + def disable_email! | ||
193 | + self.update_attribute(:enable_email, false) | ||
194 | + end | ||
195 | + | ||
196 | + def email_activation_pending? | ||
197 | + if self.environment.nil? | ||
198 | + return false | ||
199 | + else | ||
200 | + return EmailActivation.exists?(:requestor_id => self.person.id, :target_id => self.environment.id, :status => Task::Status::ACTIVE) | ||
201 | + end | ||
202 | + end | ||
203 | + | ||
188 | protected | 204 | protected |
189 | # before filter | 205 | # before filter |
190 | def encrypt_password | 206 | def encrypt_password |
app/views/mailconf/index.rhtml
1 | <h1><%= _('e-Mail configuration') %></h1> | 1 | <h1><%= _('e-Mail configuration') %></h1> |
2 | 2 | ||
3 | -<% form_tag(:action => 'save') do %> | 3 | +<%= error_messages_for :task %> |
4 | 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 option gives you an e-mail account with the address above. You'll be able to access a webmail from your user menu.") %> | ||
10 | - </blockquote> | ||
11 | - </div> | 5 | +<% if profile.user.email_activation_pending? %> |
6 | + | ||
7 | + <p><%= _('You already request activation of your mailbox. Please wait until an administrator approves your request.') %></p> | ||
12 | 8 | ||
13 | <% button_bar do %> | 9 | <% button_bar do %> |
14 | - <%= submit_button :save, _('Save') %> | ||
15 | <%= button :back, _('Back to control panel'), :controller => 'profile_editor' %> | 10 | <%= button :back, _('Back to control panel'), :controller => 'profile_editor' %> |
16 | <% end %> | 11 | <% end %> |
12 | + | ||
13 | +<% else %> | ||
14 | + | ||
15 | + | ||
16 | + <% if profile.user.enable_email %> | ||
17 | + | ||
18 | + <p><%= _("Disable e-Mail account below:") %></p> | ||
19 | + <ul><%= profile.email_addresses.map{|i| content_tag('li', i)}.join("\n") %></ul> | ||
20 | + <% button_bar do %> | ||
21 | + <%= button(:cancel, _('Disable e-Mail'), { :action => 'disable' }, :method => 'post') %> | ||
22 | + <%= button :back, _('Back to control panel'), :controller => 'profile_editor' %> | ||
23 | + <% end %> | ||
24 | + | ||
25 | + <% else %> | ||
26 | + | ||
27 | + <p><%= _("Enable e-Mail account below:") %></p> | ||
28 | + <ul><%= profile.email_addresses.map{|i| content_tag('li', i)}.join("\n") %></ul> | ||
29 | + <blockquote><%= _("You'll be able to access a webmail from your user menu.") %></blockquote> | ||
30 | + <% button_bar do %> | ||
31 | + <%= button(:ok, _('Enable e-Mail'), { :action => 'enable' }, :method => 'post') %> | ||
32 | + <%= button :back, _('Back to control panel'), :controller => 'profile_editor' %> | ||
33 | + <% end %> | ||
34 | + | ||
35 | + <% end %> | ||
36 | + | ||
17 | <% end %> | 37 | <% end %> |
app/views/tasks/new.rhtml
@@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
7 | <% else %> | 7 | <% else %> |
8 | <%= display_form_field( _('To: '), f.select(:target_id, profile.friends.map{|p|[p.name, p.id]})) %> | 8 | <%= display_form_field( _('To: '), f.select(:target_id, profile.friends.map{|p|[p.name, p.id]})) %> |
9 | <% end %> | 9 | <% end %> |
10 | + <%= hidden_field_tag 'ticket[target_type]', 'Profile' %> | ||
10 | <%= f.text_field :title, :style => 'width:80%;' %> | 11 | <%= f.text_field :title, :style => 'width:80%;' %> |
11 | <%= f.text_area :description, :style => 'height:200px; width:80%;' %> | 12 | <%= f.text_area :description, :style => 'height:200px; width:80%;' %> |
12 | 13 |
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 => 60) do | 12 | +ActiveRecord::Schema.define(:version => 61) 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" |
@@ -288,6 +288,7 @@ ActiveRecord::Schema.define(:version => 60) do | @@ -288,6 +288,7 @@ ActiveRecord::Schema.define(:version => 60) do | ||
288 | t.string "code", :limit => 40 | 288 | t.string "code", :limit => 40 |
289 | t.string "type" | 289 | t.string "type" |
290 | t.datetime "created_at" | 290 | t.datetime "created_at" |
291 | + t.string "target_type" | ||
291 | end | 292 | end |
292 | 293 | ||
293 | create_table "thumbnails", :force => true do |t| | 294 | create_table "thumbnails", :force => true do |t| |
po/pt_BR/noosfero.po
@@ -12,8 +12,13 @@ | @@ -12,8 +12,13 @@ | ||
12 | msgid "" | 12 | msgid "" |
13 | msgstr "" | 13 | msgstr "" |
14 | "Project-Id-Version: noosfero 0.13.0\n" | 14 | "Project-Id-Version: noosfero 0.13.0\n" |
15 | +<<<<<<< HEAD:po/pt_BR/noosfero.po | ||
15 | "POT-Creation-Date: 2009-01-30 15:19-0300\n" | 16 | "POT-Creation-Date: 2009-01-30 15:19-0300\n" |
16 | -"PO-Revision-Date: 2009-02-02 19:06-0300\n" | 17 | +"PO-Revision-Date: 2009-02-03 18:38-0300\n" |
18 | +======= | ||
19 | +"POT-Creation-Date: 2009-01-06 16:46-0300\n" | ||
20 | +"PO-Revision-Date: 2009-01-28 18:24-0300\n" | ||
21 | +>>>>>>> ActionItem897-novo:po/pt_BR/noosfero.po | ||
17 | "Last-Translator: Joenio Costa <joenio@colivre.coop.br>\n" | 22 | "Last-Translator: Joenio Costa <joenio@colivre.coop.br>\n" |
18 | "Language-Team: LANGUAGE <LL@li.org>\n" | 23 | "Language-Team: LANGUAGE <LL@li.org>\n" |
19 | "MIME-Version: 1.0\n" | 24 | "MIME-Version: 1.0\n" |
@@ -4542,6 +4547,10 @@ msgstr "%s quer publicar conteúdo: %s." | @@ -4542,6 +4547,10 @@ msgstr "%s quer publicar conteúdo: %s." | ||
4542 | msgid "Name for publishing" | 4547 | msgid "Name for publishing" |
4543 | msgstr "Nome para publicação" | 4548 | msgstr "Nome para publicação" |
4544 | 4549 | ||
4550 | +#: app/views/mailconf/index.rhtml:1 | ||
4551 | +msgid "e-Mail configuration" | ||
4552 | +msgstr "Configuração de e-Mail" | ||
4553 | + | ||
4545 | #: app/views/tasks/_approve_article.rhtml:24 | 4554 | #: app/views/tasks/_approve_article.rhtml:24 |
4546 | msgid "Comment for author" | 4555 | msgid "Comment for author" |
4547 | msgstr "Comentário para o autor" | 4556 | msgstr "Comentário para o autor" |
test/fixtures/roles.yml
@@ -55,3 +55,10 @@ profile_moderator: | @@ -55,3 +55,10 @@ profile_moderator: | ||
55 | system: true | 55 | system: true |
56 | permissions: | 56 | permissions: |
57 | - moderate_comments | 57 | - moderate_comments |
58 | +environment_administrator: | ||
59 | + id: 8 | ||
60 | + key: 'environment_administrator' | ||
61 | + name: 'Environment administrator' | ||
62 | + system: true | ||
63 | + permissions: | ||
64 | + - perform_task |
test/functional/mailconf_controller_test.rb
@@ -51,28 +51,18 @@ class MailconfControllerTest < Test::Unit::TestCase | @@ -51,28 +51,18 @@ class MailconfControllerTest < Test::Unit::TestCase | ||
51 | login_as('ze') | 51 | login_as('ze') |
52 | get :index, :profile => 'ze' | 52 | get :index, :profile => 'ze' |
53 | assert_tag( | 53 | assert_tag( |
54 | - :tag => 'form', | ||
55 | - :attributes => { :action => '/myprofile/ze/mailconf/save'}, | ||
56 | - :descendant => { | ||
57 | - :tag => 'input', | ||
58 | - :attributes => { :name => 'user[enable_email]', :type => 'checkbox' } | ||
59 | - } | 54 | + :tag => 'a', |
55 | + :content => 'Enable e-Mail', | ||
56 | + :attributes => {:href => '/myprofile/ze/mailconf/enable'} | ||
60 | ) | 57 | ) |
61 | end | 58 | end |
62 | 59 | ||
63 | - should 'display correctly the state true of e-mail enable/disable' do | ||
64 | - login_as('ze') | ||
65 | - users(:ze).update_attributes!(:enable_email => true) | ||
66 | - get :index, :profile => 'ze' | ||
67 | - assert_tag :tag => 'input', :attributes => { :name => 'user[enable_email]', :type => 'checkbox', :value => '1', :checked => 'checked' } | ||
68 | - end | ||
69 | - | ||
70 | should 'display correctly the state false of e-mail enable/disable' do | 60 | should 'display correctly the state false of e-mail enable/disable' do |
71 | login_as('ze') | 61 | login_as('ze') |
72 | users(:ze).update_attributes!(:enable_email => false) | 62 | users(:ze).update_attributes!(:enable_email => false) |
73 | get :index, :profile => 'ze' | 63 | get :index, :profile => 'ze' |
74 | - assert_no_tag :tag => 'input', :attributes => { :name => 'user[enable_email]', :type => 'checkbox', :value => '1', :checked => 'checked' } | ||
75 | - assert_tag :tag => 'input', :attributes => { :name => 'user[enable_email]', :type => 'hidden', :value => '0' } | 64 | + assert_tag :tag => 'a', :content => 'Enable e-Mail' |
65 | + assert_no_tag :tag => 'a', :content => 'Disable e-Mail', :attributes => { :href => '/myprofile/ze/mailconf/disable' } | ||
76 | end | 66 | end |
77 | 67 | ||
78 | should 'not display www in email address when force_www=true' do | 68 | should 'not display www in email address when force_www=true' do |
@@ -81,7 +71,7 @@ class MailconfControllerTest < Test::Unit::TestCase | @@ -81,7 +71,7 @@ class MailconfControllerTest < Test::Unit::TestCase | ||
81 | env.force_www = true | 71 | env.force_www = true |
82 | env.save! | 72 | env.save! |
83 | get :index, :profile => 'ze' | 73 | get :index, :profile => 'ze' |
84 | - assert_tag :tag => 'label', :attributes => { :for => 'user_enable_email' }, :content => /ze@colivre.net/ | 74 | + assert_tag :tag => 'li', :content => /ze@colivre.net/ |
85 | end | 75 | end |
86 | 76 | ||
87 | should 'not display www in email address when force_www=false' do | 77 | should 'not display www in email address when force_www=false' do |
@@ -90,30 +80,38 @@ class MailconfControllerTest < Test::Unit::TestCase | @@ -90,30 +80,38 @@ class MailconfControllerTest < Test::Unit::TestCase | ||
90 | env.force_www = false | 80 | env.force_www = false |
91 | env.save! | 81 | env.save! |
92 | get :index, :profile => 'ze' | 82 | get :index, :profile => 'ze' |
93 | - assert_tag :tag => 'label', :attributes => { :for => 'user_enable_email' }, :content => /ze@colivre.net/ | 83 | + assert_tag :tag => 'li', :content => /ze@colivre.net/ |
94 | end | 84 | end |
95 | 85 | ||
96 | - should 'save mail enable/disable as true' do | 86 | + should 'create task to environment admin when enable email' do |
97 | login_as('ze') | 87 | login_as('ze') |
98 | - post :save, :profile => 'ze', :user => { :enable_email => '1' } | ||
99 | - assert Profile['ze'].user.enable_email | 88 | + assert_difference EmailActivation, :count do |
89 | + post :enable, :profile => 'ze' | ||
90 | + end | ||
100 | end | 91 | end |
101 | 92 | ||
102 | should 'save mail enable/disable as false' do | 93 | should 'save mail enable/disable as false' do |
103 | login_as('ze') | 94 | login_as('ze') |
104 | - post :save, :profile => 'ze', :user => { :enable_email => '0' } | 95 | + assert users(:ze).enable_email! |
96 | + post :disable, :profile => 'ze' | ||
105 | assert !Profile['ze'].user.enable_email | 97 | assert !Profile['ze'].user.enable_email |
106 | end | 98 | end |
107 | 99 | ||
108 | should 'go back on save' do | 100 | should 'go back on save' do |
109 | login_as('ze') | 101 | login_as('ze') |
110 | - post :save, :profile => 'ze' | ||
111 | - assert_redirected_to :action => 'index' | 102 | + post :enable, :profile => 'ze' |
103 | + assert_redirected_to :controller => 'profile_editor' | ||
104 | + end | ||
105 | + | ||
106 | + should 'go to profile editor after enable email' do | ||
107 | + login_as('ze') | ||
108 | + post :enable, :profile => 'ze' | ||
109 | + assert_redirected_to :controller => 'profile_editor', :action => 'edit' | ||
112 | end | 110 | end |
113 | 111 | ||
114 | should 'display notice after saving' do | 112 | should 'display notice after saving' do |
115 | login_as('ze') | 113 | login_as('ze') |
116 | - post :save, :profile => 'ze' | 114 | + post :enable, :profile => 'ze' |
117 | assert_kind_of String, flash[:notice] | 115 | assert_kind_of String, flash[:notice] |
118 | end | 116 | end |
119 | 117 | ||
@@ -123,4 +121,12 @@ class MailconfControllerTest < Test::Unit::TestCase | @@ -123,4 +121,12 @@ class MailconfControllerTest < Test::Unit::TestCase | ||
123 | assert_tag :tag => 'div', :attributes => { :id => 'content'}, :descendant => { :tag => 'a', :attributes => { :href => '/myprofile/ze' } } | 121 | assert_tag :tag => 'div', :attributes => { :id => 'content'}, :descendant => { :tag => 'a', :attributes => { :href => '/myprofile/ze' } } |
124 | end | 122 | end |
125 | 123 | ||
124 | + should 'not display input for enable/disable e-mail when has pending_enable_email' do | ||
125 | + login_as('ze') | ||
126 | + users(:ze).update_attribute(:environment_id, Environment.default.id) | ||
127 | + EmailActivation.create!(:requestor => users(:ze).person, :target => Environment.default) | ||
128 | + get :index, :profile => 'ze' | ||
129 | + assert_no_tag :tag => 'input', :attributes => {:name => 'user[enable_email]', :type => 'checkbox'} | ||
130 | + end | ||
131 | + | ||
126 | end | 132 | end |
test/functional/profile_editor_controller_test.rb
@@ -46,8 +46,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -46,8 +46,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
46 | pending = [] | 46 | pending = [] |
47 | pending.expects(:select).returns(pending) | 47 | pending.expects(:select).returns(pending) |
48 | pending.expects(:empty?).returns(false) # force the display of the pending tasks list | 48 | pending.expects(:empty?).returns(false) # force the display of the pending tasks list |
49 | - tasks.expects(:pending).returns(pending) | ||
50 | - ze.expects(:tasks).returns(tasks) | 49 | + ze.expects(:all_pending_tasks).returns(pending) |
51 | get :index, :profile => ze.identifier | 50 | get :index, :profile => ze.identifier |
52 | assert_same pending, assigns(:pending_tasks) | 51 | assert_same pending, assigns(:pending_tasks) |
53 | assert_tag :tag => 'div', :attributes => { :class => 'pending-tasks' }, :descendant => { :tag => 'a', :attributes => { :href => '/myprofile/ze/tasks' } } | 52 | assert_tag :tag => 'div', :attributes => { :class => 'pending-tasks' }, :descendant => { :tag => 'a', :attributes => { :href => '/myprofile/ze/tasks' } } |
test/functional/tasks_controller_test.rb
@@ -147,7 +147,8 @@ class TasksControllerTest < Test::Unit::TestCase | @@ -147,7 +147,8 @@ class TasksControllerTest < Test::Unit::TestCase | ||
147 | f = create_user('friend').person | 147 | f = create_user('friend').person |
148 | profile.add_friend f | 148 | profile.add_friend f |
149 | 149 | ||
150 | - post :new, :profile => profile.identifier, :ticket => {:title => 'test ticket', :target_id => f.id} | 150 | + post :new, :profile => profile.identifier, :ticket => {:title => 'test ticket', :target_id => f.id, :target_type => 'Profile'} |
151 | + assert_response :redirect | ||
151 | 152 | ||
152 | assert_equal f, assigns(:ticket).target | 153 | assert_equal f, assigns(:ticket).target |
153 | end | 154 | end |
test/integration/enterprise_registration_test.rb
@@ -39,6 +39,7 @@ class EnterpriseRegistrationTest < ActionController::IntegrationTest | @@ -39,6 +39,7 @@ class EnterpriseRegistrationTest < ActionController::IntegrationTest | ||
39 | post '/enterprise_registration', :create_enterprise => data.merge(:target_id => org.id) | 39 | post '/enterprise_registration', :create_enterprise => data.merge(:target_id => org.id) |
40 | end | 40 | end |
41 | 41 | ||
42 | + assert_template 'confirmation' | ||
42 | assert_tag :tag => 'a', :attributes => { :href => '/' } | 43 | assert_tag :tag => 'a', :attributes => { :href => '/' } |
43 | 44 | ||
44 | code = CreateEnterprise.find(:first, :order => 'id desc').code | 45 | code = CreateEnterprise.find(:first, :order => 'id desc').code |
test/unit/create_enterprise_test.rb
@@ -109,8 +109,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase | @@ -109,8 +109,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase | ||
109 | :legal_form => 'cooperative', | 109 | :legal_form => 'cooperative', |
110 | :economic_activity => 'free software', | 110 | :economic_activity => 'free software', |
111 | :region_id => region.id, | 111 | :region_id => region.id, |
112 | - :requestor_id => person.id, | ||
113 | - :target_id => validator.id, | 112 | + :requestor => person, |
113 | + :target => validator, | ||
114 | }) | 114 | }) |
115 | 115 | ||
116 | enterprise = Enterprise.new | 116 | enterprise = Enterprise.new |
@@ -143,8 +143,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase | @@ -143,8 +143,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase | ||
143 | :legal_form => 'cooperative', | 143 | :legal_form => 'cooperative', |
144 | :economic_activity => 'free software', | 144 | :economic_activity => 'free software', |
145 | :region_id => region.id, | 145 | :region_id => region.id, |
146 | - :requestor_id => person.id, | ||
147 | - :target_id => validator.id, | 146 | + :requestor => person, |
147 | + :target => validator, | ||
148 | }) | 148 | }) |
149 | 149 | ||
150 | enterprise = Enterprise.new | 150 | enterprise = Enterprise.new |
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
2 | + | ||
3 | +class EmailActivationTest < Test::Unit::TestCase | ||
4 | + | ||
5 | + should 'require a requestor' do | ||
6 | + task = EmailActivation.new | ||
7 | + task.valid? | ||
8 | + | ||
9 | + assert task.errors.invalid?(:requestor_id) | ||
10 | + end | ||
11 | + | ||
12 | + should 'require a target (environment)' do | ||
13 | + task = EmailActivation.new | ||
14 | + task.valid? | ||
15 | + | ||
16 | + assert task.errors.invalid?(:target_id) | ||
17 | + end | ||
18 | + | ||
19 | + should 'enable user email when finish' do | ||
20 | + ze = create_user('zezinho', :environment_id => Environment.default.id) | ||
21 | + assert !ze.enable_email | ||
22 | + task = EmailActivation.create!(:requestor => ze.person, :target => Environment.default) | ||
23 | + task.finish | ||
24 | + ze.reload | ||
25 | + assert ze.enable_email | ||
26 | + end | ||
27 | + | ||
28 | + should 'create only once pending task by user' do | ||
29 | + ze = create_user('zezinho', :environment_id => Environment.default.id) | ||
30 | + task = EmailActivation.new(:requestor => ze.person, :target => Environment.default) | ||
31 | + assert task.save! | ||
32 | + | ||
33 | + anothertask = EmailActivation.new(:requestor => ze.person, :target => Environment.default) | ||
34 | + assert !anothertask.save | ||
35 | + end | ||
36 | + | ||
37 | + should 'display email address on description of task' do | ||
38 | + ze = create_user('zezinho', :environment_id => Environment.default.id) | ||
39 | + Environment.default.domains = [Domain.create!(:name => 'env_test.invalid')] | ||
40 | + task = EmailActivation.new(:requestor => ze.person, :target => Environment.default) | ||
41 | + assert_match /zezinho@env_test.invalid/, task.description | ||
42 | + end | ||
43 | + | ||
44 | +end |
test/unit/environment_test.rb
@@ -681,4 +681,11 @@ class EnvironmentTest < Test::Unit::TestCase | @@ -681,4 +681,11 @@ class EnvironmentTest < Test::Unit::TestCase | ||
681 | assert_equal ['Category'], Environment.new.category_types | 681 | assert_equal ['Category'], Environment.new.category_types |
682 | end | 682 | end |
683 | 683 | ||
684 | + should 'has tasks' do | ||
685 | + e = Environment.default | ||
686 | + assert_nothing_raised do | ||
687 | + e.tasks | ||
688 | + end | ||
689 | + end | ||
690 | + | ||
684 | end | 691 | end |
test/unit/profile_test.rb
@@ -1198,6 +1198,56 @@ class ProfileTest < Test::Unit::TestCase | @@ -1198,6 +1198,56 @@ class ProfileTest < Test::Unit::TestCase | ||
1198 | assert community.enable_contact? | 1198 | assert community.enable_contact? |
1199 | end | 1199 | end |
1200 | 1200 | ||
1201 | + should 'include pending tasks from environment if is admin' do | ||
1202 | + env = Environment.default | ||
1203 | + person = create_user('molly').person | ||
1204 | + task = Task.create!(:requestor => person, :target => env) | ||
1205 | + | ||
1206 | + Person.any_instance.stubs(:is_admin?).returns(true) | ||
1207 | + assert_equal [task], person.all_pending_tasks | ||
1208 | + end | ||
1209 | + | ||
1210 | + should 'find task from environment if is admin' do | ||
1211 | + env = Environment.default | ||
1212 | + person = create_user('molly').person | ||
1213 | + task = Task.create!(:requestor => person, :target => env) | ||
1214 | + | ||
1215 | + Person.any_instance.stubs(:is_admin?).returns(true) | ||
1216 | + assert_equal task, person.find_in_all_tasks(task.id) | ||
1217 | + end | ||
1218 | + | ||
1219 | + should 'find task from all environment if is admin' do | ||
1220 | + env = Environment.default | ||
1221 | + another = Environment.create!(:name => 'another_env') | ||
1222 | + person = Person['ze'] | ||
1223 | + task1 = Task.create!(:requestor => person, :target => env) | ||
1224 | + task2 = Task.create!(:requestor => person, :target => another) | ||
1225 | + | ||
1226 | + another.affiliate(person, Environment::Roles.admin) | ||
1227 | + env.affiliate(person, Environment::Roles.admin) | ||
1228 | + | ||
1229 | + Person.any_instance.stubs(:is_admin?).returns(true) | ||
1230 | + | ||
1231 | + assert_equal [task1, task2], person.all_pending_tasks | ||
1232 | + end | ||
1233 | + | ||
1234 | + should 'find task by id on all environments' do | ||
1235 | + env = Environment.create!(:name => 'other_env') | ||
1236 | + another = Environment.create!(:name => 'another_env') | ||
1237 | + person = Person['ze'] | ||
1238 | + | ||
1239 | + task1 = Task.create!(:requestor => person, :target => env) | ||
1240 | + task2 = Task.create!(:requestor => person, :target => another) | ||
1241 | + | ||
1242 | + person.stubs(:is_admin?).with(env).returns(true) | ||
1243 | + Environment.find(:all).select{|i| i.name != 'other_env'}.each do |env| | ||
1244 | + person.stubs(:is_admin?).with(env).returns(false) | ||
1245 | + end | ||
1246 | + | ||
1247 | + assert_not_nil person.find_in_all_tasks(task1.id) | ||
1248 | + assert_nil person.find_in_all_tasks(task2.id) | ||
1249 | + end | ||
1250 | + | ||
1201 | private | 1251 | private |
1202 | 1252 | ||
1203 | def assert_invalid_identifier(id) | 1253 | def assert_invalid_identifier(id) |
test/unit/task_test.rb
@@ -20,10 +20,10 @@ class TaskTest < Test::Unit::TestCase | @@ -20,10 +20,10 @@ class TaskTest < Test::Unit::TestCase | ||
20 | end | 20 | end |
21 | end | 21 | end |
22 | 22 | ||
23 | - def test_relationship_with_target | 23 | + should 'target be able to polymorphic relationship' do |
24 | t = Task.create | 24 | t = Task.create |
25 | - assert_raise ActiveRecord::AssociationTypeMismatch do | ||
26 | - t.target = 1 | 25 | + assert_nothing_raised do |
26 | + t.target = Environment.new | ||
27 | end | 27 | end |
28 | assert_nothing_raised do | 28 | assert_nothing_raised do |
29 | t.target = Profile.new | 29 | t.target = Profile.new |
test/unit/user_test.rb
@@ -262,6 +262,27 @@ class UserTest < Test::Unit::TestCase | @@ -262,6 +262,27 @@ class UserTest < Test::Unit::TestCase | ||
262 | assert_equal false, User.new.enable_email | 262 | assert_equal false, User.new.enable_email |
263 | end | 263 | end |
264 | 264 | ||
265 | + should 'enable email' do | ||
266 | + user = create_user('cooler') | ||
267 | + assert !user.enable_email | ||
268 | + assert user.enable_email! | ||
269 | + assert user.enable_email | ||
270 | + end | ||
271 | + | ||
272 | + should 'has email activation pending' do | ||
273 | + user = create_user('cooler') | ||
274 | + user.update_attribute(:environment_id, Environment.default.id) | ||
275 | + EmailActivation.create!(:requestor => user.person, :target => Environment.default) | ||
276 | + assert user.email_activation_pending? | ||
277 | + end | ||
278 | + | ||
279 | + should 'not has email activation pending if not have environment' do | ||
280 | + user = create_user('cooler') | ||
281 | + user.expects(:environment).returns(nil) | ||
282 | + EmailActivation.create!(:requestor => user.person, :target => Environment.default) | ||
283 | + assert !user.email_activation_pending? | ||
284 | + end | ||
285 | + | ||
265 | protected | 286 | protected |
266 | def new_user(options = {}) | 287 | def new_user(options = {}) |
267 | user = User.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) | 288 | user = User.new({ :login => 'quire', :email => 'quire@example.com', :password => 'quire', :password_confirmation => 'quire' }.merge(options)) |