diff --git a/app/controllers/my_profile/profile_members_controller.rb b/app/controllers/my_profile/profile_members_controller.rb index df30604..07c440b 100644 --- a/app/controllers/my_profile/profile_members_controller.rb +++ b/app/controllers/my_profile/profile_members_controller.rb @@ -13,6 +13,7 @@ class ProfileMembersController < MyProfileController def update_roles @roles = params[:roles] ? Role.find(params[:roles]) : [] + @roles = @roles.select{|r| r.has_kind?('Profile') } @person = Person.find(params[:person]) if @person.define_roles(@roles, profile) flash[:notice] = _('Roles successfuly updated') @@ -35,7 +36,7 @@ class ProfileMembersController < MyProfileController redirect_to :action => 'index' else @member = Person.find(params[:person]) - @roles = Role.find(:all).select{ |r| r.has_kind?(:profile) } + @roles = Role.find(:all).select{ |r| r.has_kind?('Profile') } render :action => 'affiliate' end end diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 2d4217b..72dbc47 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -20,4 +20,20 @@ class Enterprise < Organization e.products.each{ |p| p.enterprise_updated(e) } end + def closed? + true + end + + def code + ("%06d" % id) + Digest::MD5.hexdigest(id.to_s)[0..5] + end + + def self.return_by_code(code) + id = code[0..5].to_i + md5 = code[6..11] + return unless md5 == Digest::MD5.hexdigest(id.to_s)[0..5] + + Enterprise.find(id) + end + end diff --git a/app/views/blocks/profile_info_actions/enterprise.rhtml b/app/views/blocks/profile_info_actions/enterprise.rhtml index b3fb1c6..baff518 100644 --- a/app/views/blocks/profile_info_actions/enterprise.rhtml +++ b/app/views/blocks/profile_info_actions/enterprise.rhtml @@ -1,5 +1,12 @@ diff --git a/lib/tasks/populate.rake b/lib/tasks/populate.rake index d28a52c..d33b170 100644 --- a/lib/tasks/populate.rake +++ b/lib/tasks/populate.rake @@ -29,7 +29,7 @@ def create_roles 'edit_environment_design', 'manage_environment_categories', 'manage_environment_roles', - 'manage_environment_validators' + 'manage_environment_validators', ]) Role.create!(:key => 'profile_admin', :name => N_('Profile Administrator'), :permissions => [ 'edit_profile', diff --git a/script/anhetegua b/script/anhetegua index 948e130..5fdbd42 100755 --- a/script/anhetegua +++ b/script/anhetegua @@ -152,6 +152,7 @@ root = User.create!(:login => 'root', :email => 'root@noosfero.org', :password = admin_role = Environment::Roles.admin RoleAssignment.create!(:accessor => root, :role => admin_role, :resource => Environment.default) +RoleAssignment.create!(:accessor => root, :role => owner_role, :resource => Environment.default) # Sample user and sample enterprise owned by him ze = User.create!(:login => 'ze', :email => 'ze@localhost.localdomain', :password => 'test', :password_confirmation => 'test').person diff --git a/script/fbes_populate_helper.rb b/script/fbes_populate_helper.rb index 787d9b0..6c42e14 100644 --- a/script/fbes_populate_helper.rb +++ b/script/fbes_populate_helper.rb @@ -45,11 +45,13 @@ require File.dirname(__FILE__) + '/../config/environment' end def new_ent(data, products, consumptions) - count = 1 - while Enterprise.find_by_identifier(data[:identifier]) - data[:identifier] = data[:identifier] + "-#{count}" + count = 2 + ident = data[:identifier] + while Enterprise.find_by_identifier(ident) + ident = data[:identifier] + "-#{count}" count += 1 end + data[:identifier] = ident ent = Enterprise.create!({:environment => Environment.default}.merge(data)) products.each do |p| ent.products.create!(p) unless ent.products.find(:first, :conditions => p) diff --git a/test/functional/profile_members_controller_test.rb b/test/functional/profile_members_controller_test.rb index 0a9ff59..ed877be 100644 --- a/test/functional/profile_members_controller_test.rb +++ b/test/functional/profile_members_controller_test.rb @@ -53,6 +53,7 @@ class ProfileMembersControllerTest < Test::Unit::TestCase get 'change_role', :profile => 'test_enterprise' , :id => member assert_response :success + assert_includes assigns(:roles), role assert_equal member, assigns('member') assert_template 'change_role' assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'roles[]'} @@ -61,19 +62,20 @@ class ProfileMembersControllerTest < Test::Unit::TestCase should 'update roles' do ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'test enterprise') - role = Role.create!(:name => 'member_role', :permissions => ['edit_profile']) - orole = Role.create!(:name => 'owner_role', :permissions => ['edit_profile', 'destroy_profile']) + role1 = Role.create!(:name => 'member_role', :permissions => ['edit_profile']) + role2 = Role.create!(:name => 'owner_role', :permissions => ['edit_profile', 'destroy_profile']) member = create_user('test_member').person - member.add_role(role, ent) + member.add_role(role1, ent) user = create_user_with_permission('test_user', 'manage_memberships', ent) login_as :test_user - post 'update_roles', :profile => 'test_enterprise', :roles => [orole.id], :person => member + post 'update_roles', :profile => 'test_enterprise', :roles => [role2.id], :person => member assert_response :redirect member.reload - assert member.find_roles(ent).map(&:role).include?(orole) - assert !member.find_roles(ent).map(&:role).include?(role) + roles = member.find_roles(ent).map(&:role) + assert_includes roles, role2 + assert_not_includes roles, role1 end end diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index 9be6045..38b191f 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -103,17 +103,19 @@ class EnterpriseTest < Test::Unit::TestCase assert_not_includes result, ent2 end - should 'allow to add new members' do + should 'not allow to add new members' do o = Enterprise.create!(:name => 'my test profile', :identifier => 'mytestprofile') p = create_user('mytestuser').person o.add_member(p) + o.reload - assert o.members.include?(p), "Enterprise should add the new member" + assert_not_includes o.members, p end - + should 'allow to remove members' do c = Enterprise.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') + c.expects(:closed?).returns(false) p = create_user('myothertestuser').person c.add_member(p) @@ -123,4 +125,13 @@ class EnterpriseTest < Test::Unit::TestCase assert_not_includes c.members, p end + should 'return coherent code' do + ent = Enterprise.create!(:name => 'my test profile', :identifier => 'mytestprofile') + ent2 = Enterprise.create!(:name => 'my test profile 2', :identifier => 'mytestprofile2') + + assert_equal ent, Enterprise.return_by_code(ent.code) + assert_nil Enterprise.return_by_code(ent.code.next) + end + + end -- libgit2 0.21.2