diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb index f599154..f759100 100644 --- a/app/controllers/my_profile/profile_editor_controller.rb +++ b/app/controllers/my_profile/profile_editor_controller.rb @@ -18,5 +18,25 @@ class ProfileEditorController < MyProfileController end end + def enable + @to_enable = profile + if request.post? && params[:confirmation] + unless @to_enable.update_attribute('enabled', true) + flash[:notice] = _('%s was not enabled.') % @to_enable.name + end + redirect_to :action => 'index' + end + end + + def disable + @to_disable = profile + if request.post? && params[:confirmation] + unless @to_disable.update_attribute('enabled', false) + flash[:notice] = _('%s was not disabled.') % @to_disable.name + end + redirect_to :action => 'index' + end + end + end diff --git a/app/views/profile_editor/disable.rhtml b/app/views/profile_editor/disable.rhtml new file mode 100644 index 0000000..575c96c --- /dev/null +++ b/app/views/profile_editor/disable.rhtml @@ -0,0 +1,11 @@ +

<%= _("Disabling '%s' enterprise") % @to_disable.name %>

+ +

+<%= _('Are you sure you want to disable %s?') % @to_disable.name %> +

+ +<% form_tag do %> + <%= hidden_field_tag(:confirmation, 1) %> + <%= submit_button(:ok, _("Yes, I want to disable.")) %> + <%= button(:cancel, _("No, I don't want."), :action => 'index') %> +<% end %> diff --git a/app/views/profile_editor/enable.rhtml b/app/views/profile_editor/enable.rhtml new file mode 100644 index 0000000..1852691 --- /dev/null +++ b/app/views/profile_editor/enable.rhtml @@ -0,0 +1,11 @@ +

<%= _("Enabling '%s' enterprise") % @to_enable.name %>

+ +

+<%= _('Are you sure you want to enable %s?') % @to_enable.name %> +

+ +<% form_tag do %> + <%= hidden_field_tag(:confirmation, 1) %> + <%= submit_button(:ok, _("Yes, I want to enable.")) %> + <%= button(:cancel, _("No, I don't want."), :action => 'index') %> +<% end %> diff --git a/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml index 300397b..2d12034 100644 --- a/app/views/profile_editor/index.rhtml +++ b/app/views/profile_editor/index.rhtml @@ -28,6 +28,14 @@ <%= file_manager_button(_('Favorite Enterprises'), 'icons-app/favorites.png', :controller => 'favorite_enterprises') if profile.person? %> + <% if profile.enterprise? %> + <% if profile.enabled? %> + <%= file_manager_button(_('Disable Enterprise'), 'icons-app/disable.png', :action => 'disable') %> + <% else %> + <%= file_manager_button(_('Enable Enterprise'), 'icons-app/enable.png', :action => 'enable') %> + <% end %> + <% end %> + <% end %> <% if @profile.person? %> diff --git a/public/images/icons-app/README b/public/images/icons-app/README index 9a914f8..7000d85 100644 --- a/public/images/icons-app/README +++ b/public/images/icons-app/README @@ -42,6 +42,7 @@ friends.png (modified version of users.png) Nuovo gtk-folder.png Nuovo epiphany-bookmarks.png dlg-neu mozilla-mail.png dlg-neu +gtk-cancel.png dlg-neu ### END OF ICONS LISTING ### Icons rasterization diff --git a/public/images/icons-app/disable.png b/public/images/icons-app/disable.png new file mode 120000 index 0000000..e726007 --- /dev/null +++ b/public/images/icons-app/disable.png @@ -0,0 +1 @@ +gtk-cancel.png \ No newline at end of file diff --git a/public/images/icons-app/enable.png b/public/images/icons-app/enable.png new file mode 100644 index 0000000..2c0f42b Binary files /dev/null and b/public/images/icons-app/enable.png differ diff --git a/public/images/icons-app/gtk-cancel.png b/public/images/icons-app/gtk-cancel.png new file mode 100644 index 0000000..3d750c9 Binary files /dev/null and b/public/images/icons-app/gtk-cancel.png differ diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index 952427f..4b4ce27 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -360,4 +360,52 @@ class ProfileEditorControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/ze/mailconf' } end + should 'link to enable enterprise' do + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false) + get :index, :profile => 'testent' + assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testent/profile_editor/enable' } + end + + should 'link to disable enterprise' do + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true) + get :index, :profile => 'testent' + assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testent/profile_editor/disable' } + end + + should 'not link to enable/disable for non enterprises' do + ent = Organization.create!(:name => 'test org', :identifier => 'testorg', :enabled => true) + get :index, :profile => 'testorg' + assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/testorg/profile_editor/disable' } + end + + should 'request enable enterprise confirmation' do + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false) + get :enable, :profile => 'testent' + assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testent/profile_editor/enable', :method => 'post' } + end + + should 'enable enterprise after confirmation' do + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false) + post :enable, :profile => 'testent', :confirmation => 1 + assert assigns(:to_enable).enabled? + end + + should 'not enable enterprise without confirmation' do + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false) + post :enable, :profile => 'testent' + assert !assigns(:to_enable).enabled? + end + + should 'disable enterprise after confirmation' do + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true) + post :disable, :profile => 'testent', :confirmation => 1 + assert !assigns(:to_disable).enabled? + end + + should 'not disable enterprise without confirmation' do + ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true) + post :disable, :profile => 'testent' + assert assigns(:to_disable).enabled? + end + end diff --git a/test/test_helper.rb b/test/test_helper.rb index 070370b..f1b4e0d 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -42,7 +42,6 @@ class Test::Unit::TestCase fixtures File.basename(item).sub(/\.yml$/, '').to_s end end -# all_fixtures def self.should(name, &block) @shoulds ||= [] -- libgit2 0.21.2