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 | 3 | # which by default is the one returned by Environment:default. |
4 | 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 | 15 | PERMISSIONS[:profile] = { |
7 | 16 | 'edit_profile' => N_('Edit profile'), |
8 | 17 | 'destroy_profile' => N_('Destroy profile'), | ... | ... |
db/migrate/013_access_control_migration.rb
... | ... | @@ -3,6 +3,8 @@ class AccessControlMigration < ActiveRecord::Migration |
3 | 3 | create_table :roles do |t| |
4 | 4 | t.column :name, :string |
5 | 5 | t.column :permissions, :string |
6 | + t.column :key, :string | |
7 | + t.column :system, :boolean, :default => false | |
6 | 8 | end |
7 | 9 | |
8 | 10 | create_table :role_assignments do |t| |
... | ... | @@ -13,6 +15,23 @@ class AccessControlMigration < ActiveRecord::Migration |
13 | 15 | t.column :role_id, :integer |
14 | 16 | t.column :is_global, :boolean |
15 | 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 | 35 | end |
17 | 36 | |
18 | 37 | def self.down | ... | ... |
test/unit/profile_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | |
3 | 3 | class ProfileTest < Test::Unit::TestCase |
4 | - fixtures :profiles, :environments, :users | |
4 | + fixtures :profiles, :environments, :users, :roles | |
5 | 5 | |
6 | 6 | def test_identifier_validation |
7 | 7 | p = Profile.new |
... | ... | @@ -294,6 +294,16 @@ class ProfileTest < Test::Unit::TestCase |
294 | 294 | assert_equivalent [ third], profile.find_tagged_with('third-tag') |
295 | 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 | 307 | private |
298 | 308 | |
299 | 309 | def assert_invalid_identifier(id) | ... | ... |