From 0c8abae20ae213cdfbb2b4491956d577cab7d4e5 Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Sun, 2 Dec 2007 04:37:16 +0000 Subject: [PATCH] ActionItem93: reactivated permissions and made tests pass --- app/controllers/my_profile/cms_controller.rb | 3 +-- app/controllers/my_profile/consumed_products_controller.rb | 2 +- app/controllers/my_profile/enterprise_editor_controller.rb | 15 ++++++--------- app/controllers/my_profile/manage_products_controller.rb | 2 +- app/controllers/my_profile/profile_editor_controller.rb | 2 +- app/controllers/my_profile/profile_members_controller.rb | 2 +- app/models/profile.rb | 1 + test/functional/cms_controller_test.rb | 3 ++- test/functional/enterprise_editor_controller_test.rb | 4 ++-- test/test_helper.rb | 5 +++-- 10 files changed, 19 insertions(+), 20 deletions(-) diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 650b3df..4539e81 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -1,7 +1,6 @@ class CmsController < MyProfileController - # FIXME add the access control again - # protect 'post_content', :profile, :only => [:edit, :new, :reorder, :delete] + protect 'post_content', :profile, :only => [:edit, :new, :reorder, :delete] design :holder => :profile diff --git a/app/controllers/my_profile/consumed_products_controller.rb b/app/controllers/my_profile/consumed_products_controller.rb index 0504e40..0273b95 100644 --- a/app/controllers/my_profile/consumed_products_controller.rb +++ b/app/controllers/my_profile/consumed_products_controller.rb @@ -1,7 +1,7 @@ class ConsumedProductsController < ApplicationController needs_profile -# protect 'manage_products', :profile + protect 'manage_products', :profile def index @consumptions = @profile.consumptions diff --git a/app/controllers/my_profile/enterprise_editor_controller.rb b/app/controllers/my_profile/enterprise_editor_controller.rb index aa7febb..1bcbf23 100644 --- a/app/controllers/my_profile/enterprise_editor_controller.rb +++ b/app/controllers/my_profile/enterprise_editor_controller.rb @@ -2,8 +2,9 @@ class EnterpriseEditorController < MyProfileController protect 'edit_profile', :profile, :user, :except => :destroy protect 'destroy_profile', :profile, :only => :destroy - before_filter :check_enterprise - + requires_profile_class(Enterprise) + before_filter :enterprise + # Show details about an enterprise def index end @@ -35,13 +36,9 @@ class EnterpriseEditorController < MyProfileController end end - protected + protected - def check_enterprise - if profile.is_a?(Enterprise) - @enterprise = profile - else - redirect_to :controller => 'account' #:controller => 'profile_editor', :profile => current_user.login and return - end + def enterprise + @enterprise = @profile end end diff --git a/app/controllers/my_profile/manage_products_controller.rb b/app/controllers/my_profile/manage_products_controller.rb index d802362..8f4a137 100644 --- a/app/controllers/my_profile/manage_products_controller.rb +++ b/app/controllers/my_profile/manage_products_controller.rb @@ -1,7 +1,7 @@ class ManageProductsController < ApplicationController needs_profile -# protect 'manage_products', :profile + protect 'manage_products', :profile def index @products = @profile.products diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb index 45f7b35..54719be 100644 --- a/app/controllers/my_profile/profile_editor_controller.rb +++ b/app/controllers/my_profile/profile_editor_controller.rb @@ -1,6 +1,6 @@ class ProfileEditorController < MyProfileController - #protect 'edit_profile', :profile, only => [:index, :edit] + protect 'edit_profile', :profile, :only => [:index, :edit] helper :profile diff --git a/app/controllers/my_profile/profile_members_controller.rb b/app/controllers/my_profile/profile_members_controller.rb index d9ce095..b71e5ce 100644 --- a/app/controllers/my_profile/profile_members_controller.rb +++ b/app/controllers/my_profile/profile_members_controller.rb @@ -1,5 +1,5 @@ class ProfileMembersController < MyProfileController -# protect 'manage_memberships', :profile + protect 'manage_memberships', :profile def index @members = profile.members diff --git a/app/models/profile.rb b/app/models/profile.rb index 41f7607..2e77dbf 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -9,6 +9,7 @@ class Profile < ActiveRecord::Base 'manage_memberships' => N_('Manage memberships'), 'post_content' => N_('Post content'), 'edit_profile_design' => N_('Edit profile design'), + 'manage_products' => N_('Manage products'), } acts_as_accessible diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index f5154b4..a0db8ac 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -13,7 +13,8 @@ class CmsControllerTest < Test::Unit::TestCase @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new - @profile = create_user('testinguser').person + @profile = create_user_with_permission('testinguser', 'post_content') + login_as :testinguser end attr_reader :profile diff --git a/test/functional/enterprise_editor_controller_test.rb b/test/functional/enterprise_editor_controller_test.rb index 4bd917d..a0bfc72 100644 --- a/test/functional/enterprise_editor_controller_test.rb +++ b/test/functional/enterprise_editor_controller_test.rb @@ -67,12 +67,12 @@ class EnterpriseEditorControllerTest < Test::Unit::TestCase user = create_user_with_permission('test_user', 'edit_profile', ent) login_as :test_user - post 'update', :profile => 'test_enterprise', :enterprise => {:name => 'test_name'} + post 'update', :profile => 'test_enterprise', :organization_info => {:acronym => 'bla'} assert_response :redirect assert_redirected_to :action => 'index' ent.reload - assert_equal 'test_name', ent.name + assert_equal 'bla', ent.organization_info.acronym end should 'destroy' do diff --git a/test/test_helper.rb b/test/test_helper.rb index e0011b2..28bb38c 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -63,15 +63,16 @@ class Test::Unit::TestCase :password_confirmation => name.underscore) end - def create_user_with_permission(name, permission, target) + def create_user_with_permission(name, permission, target= nil) user = create_user(name).person + target ||= user i = 0 while Role.find_by_name('test_role' + i.to_s) i+=1 end role = Role.create!(:name => 'test_role' + i.to_s, :permissions => [permission]) - assert user.add_role(role, target) + assert user.add_role(role, target) assert user.has_permission?(permission, target) user end -- libgit2 0.21.2