From 61cbb60be73c2ae8944ba36c66c208e5a605baeb Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Fri, 8 Feb 2008 23:37:55 +0000 Subject: [PATCH] ActionItem41: adding default roles for profile to be used when creating communities --- app/models/profile.rb | 9 +++++++++ db/migrate/013_access_control_migration.rb | 19 +++++++++++++++++++ test/unit/profile_test.rb | 12 +++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index 6b8b621..7bc5ca1 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -3,6 +3,15 @@ # which by default is the one returned by Environment:default. class Profile < ActiveRecord::Base + module Roles + def self.admin + ::Role.find_by_key('profile_admin') + end + def self.member + ::Role.find_by_key('profile_member') + end + end + PERMISSIONS[:profile] = { 'edit_profile' => N_('Edit profile'), 'destroy_profile' => N_('Destroy profile'), diff --git a/db/migrate/013_access_control_migration.rb b/db/migrate/013_access_control_migration.rb index 26058ec..097ceca 100644 --- a/db/migrate/013_access_control_migration.rb +++ b/db/migrate/013_access_control_migration.rb @@ -3,6 +3,8 @@ class AccessControlMigration < ActiveRecord::Migration create_table :roles do |t| t.column :name, :string t.column :permissions, :string + t.column :key, :string + t.column :system, :boolean, :default => false end create_table :role_assignments do |t| @@ -13,6 +15,23 @@ class AccessControlMigration < ActiveRecord::Migration t.column :role_id, :integer t.column :is_global, :boolean end + + # create system-defined roles + Role.with_scope(:create => { :system => true }) do + Role.create!(:key => 'profile_admin', :name => N_('Profile Administrator'), :permissions => [ + 'edit_profile', + 'destroy_profile', + 'manage_memberships', + 'post_content', + 'edit_profile_design', + 'manage_products', + ]) + + # members for environments, communities etc + Role.create!(:key => "profile_member", :name => N_('Member'), :permissions => [ + 'post_content' + ]) + end end def self.down diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 91eed4a..e8fbb36 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class ProfileTest < Test::Unit::TestCase - fixtures :profiles, :environments, :users + fixtures :profiles, :environments, :users, :roles def test_identifier_validation p = Profile.new @@ -294,6 +294,16 @@ class ProfileTest < Test::Unit::TestCase assert_equivalent [ third], profile.find_tagged_with('third-tag') end + should 'have administator role' do + Role.expects(:find_by_key).with('profile_admin').returns(Role.new) + assert_kind_of Role, Profile::Roles.admin + end + + should 'have member role' do + Role.expects(:find_by_key).with('profile_member').returns(Role.new) + assert_kind_of Role, Profile::Roles.member + end + private def assert_invalid_identifier(id) -- libgit2 0.21.2