Commit 61cbb60be73c2ae8944ba36c66c208e5a605baeb
1 parent
386ac925
Exists in
master
and in
29 other branches
ActionItem41: adding default roles for profile to be used when creating communities
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1324 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
39 additions
and
1 deletions
Show diff stats
app/models/profile.rb
@@ -3,6 +3,15 @@ | @@ -3,6 +3,15 @@ | ||
3 | # which by default is the one returned by Environment:default. | 3 | # which by default is the one returned by Environment:default. |
4 | class Profile < ActiveRecord::Base | 4 | class Profile < ActiveRecord::Base |
5 | 5 | ||
6 | + module Roles | ||
7 | + def self.admin | ||
8 | + ::Role.find_by_key('profile_admin') | ||
9 | + end | ||
10 | + def self.member | ||
11 | + ::Role.find_by_key('profile_member') | ||
12 | + end | ||
13 | + end | ||
14 | + | ||
6 | PERMISSIONS[:profile] = { | 15 | PERMISSIONS[:profile] = { |
7 | 'edit_profile' => N_('Edit profile'), | 16 | 'edit_profile' => N_('Edit profile'), |
8 | 'destroy_profile' => N_('Destroy profile'), | 17 | 'destroy_profile' => N_('Destroy profile'), |
db/migrate/013_access_control_migration.rb
@@ -3,6 +3,8 @@ class AccessControlMigration < ActiveRecord::Migration | @@ -3,6 +3,8 @@ class AccessControlMigration < ActiveRecord::Migration | ||
3 | create_table :roles do |t| | 3 | create_table :roles do |t| |
4 | t.column :name, :string | 4 | t.column :name, :string |
5 | t.column :permissions, :string | 5 | t.column :permissions, :string |
6 | + t.column :key, :string | ||
7 | + t.column :system, :boolean, :default => false | ||
6 | end | 8 | end |
7 | 9 | ||
8 | create_table :role_assignments do |t| | 10 | create_table :role_assignments do |t| |
@@ -13,6 +15,23 @@ class AccessControlMigration < ActiveRecord::Migration | @@ -13,6 +15,23 @@ class AccessControlMigration < ActiveRecord::Migration | ||
13 | t.column :role_id, :integer | 15 | t.column :role_id, :integer |
14 | t.column :is_global, :boolean | 16 | t.column :is_global, :boolean |
15 | end | 17 | end |
18 | + | ||
19 | + # create system-defined roles | ||
20 | + Role.with_scope(:create => { :system => true }) do | ||
21 | + Role.create!(:key => 'profile_admin', :name => N_('Profile Administrator'), :permissions => [ | ||
22 | + 'edit_profile', | ||
23 | + 'destroy_profile', | ||
24 | + 'manage_memberships', | ||
25 | + 'post_content', | ||
26 | + 'edit_profile_design', | ||
27 | + 'manage_products', | ||
28 | + ]) | ||
29 | + | ||
30 | + # members for environments, communities etc | ||
31 | + Role.create!(:key => "profile_member", :name => N_('Member'), :permissions => [ | ||
32 | + 'post_content' | ||
33 | + ]) | ||
34 | + end | ||
16 | end | 35 | end |
17 | 36 | ||
18 | def self.down | 37 | def self.down |
test/unit/profile_test.rb
1 | require File.dirname(__FILE__) + '/../test_helper' | 1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | ||
3 | class ProfileTest < Test::Unit::TestCase | 3 | class ProfileTest < Test::Unit::TestCase |
4 | - fixtures :profiles, :environments, :users | 4 | + fixtures :profiles, :environments, :users, :roles |
5 | 5 | ||
6 | def test_identifier_validation | 6 | def test_identifier_validation |
7 | p = Profile.new | 7 | p = Profile.new |
@@ -294,6 +294,16 @@ class ProfileTest < Test::Unit::TestCase | @@ -294,6 +294,16 @@ class ProfileTest < Test::Unit::TestCase | ||
294 | assert_equivalent [ third], profile.find_tagged_with('third-tag') | 294 | assert_equivalent [ third], profile.find_tagged_with('third-tag') |
295 | end | 295 | end |
296 | 296 | ||
297 | + should 'have administator role' do | ||
298 | + Role.expects(:find_by_key).with('profile_admin').returns(Role.new) | ||
299 | + assert_kind_of Role, Profile::Roles.admin | ||
300 | + end | ||
301 | + | ||
302 | + should 'have member role' do | ||
303 | + Role.expects(:find_by_key).with('profile_member').returns(Role.new) | ||
304 | + assert_kind_of Role, Profile::Roles.member | ||
305 | + end | ||
306 | + | ||
297 | private | 307 | private |
298 | 308 | ||
299 | def assert_invalid_identifier(id) | 309 | def assert_invalid_identifier(id) |