Commit 57d2dac6e6d0344fe9848c947a86e30adae67ccf
Committed by
Daniela Feitosa
1 parent
704ab1a4
Exists in
master
and in
29 other branches
ActionItem1080: made roles specific for environment
* changed system roles to depend on environment * made roles environment specific
Showing
26 changed files
with
180 additions
and
92 deletions
Show diff stats
app/controllers/admin/role_controller.rb
@@ -2,11 +2,11 @@ class RoleController < AdminController | @@ -2,11 +2,11 @@ class RoleController < AdminController | ||
2 | protect 'manage_environment_roles', :environment | 2 | protect 'manage_environment_roles', :environment |
3 | 3 | ||
4 | def index | 4 | def index |
5 | - @roles = Role.find(:all) | 5 | + @roles = environment.roles.find(:all) |
6 | end | 6 | end |
7 | 7 | ||
8 | def show | 8 | def show |
9 | - @role = Role.find(params[:id]) | 9 | + @role = environment.roles.find(params[:id]) |
10 | end | 10 | end |
11 | 11 | ||
12 | def new | 12 | def new |
@@ -15,6 +15,7 @@ class RoleController < AdminController | @@ -15,6 +15,7 @@ class RoleController < AdminController | ||
15 | 15 | ||
16 | def create | 16 | def create |
17 | @role = Role.new(params[:role]) | 17 | @role = Role.new(params[:role]) |
18 | + @role.environment = environment | ||
18 | if @role.save | 19 | if @role.save |
19 | redirect_to :action => 'show', :id => @role | 20 | redirect_to :action => 'show', :id => @role |
20 | else | 21 | else |
@@ -24,11 +25,11 @@ class RoleController < AdminController | @@ -24,11 +25,11 @@ class RoleController < AdminController | ||
24 | end | 25 | end |
25 | 26 | ||
26 | def edit | 27 | def edit |
27 | - @role = Role.find(params[:id]) | 28 | + @role = environment.roles.find(params[:id]) |
28 | end | 29 | end |
29 | 30 | ||
30 | def update | 31 | def update |
31 | - @role = Role.find(params[:id]) | 32 | + @role = environment.roles.find(params[:id]) |
32 | if @role.update_attributes(params[:role]) | 33 | if @role.update_attributes(params[:role]) |
33 | redirect_to :action => 'show', :id => @role | 34 | redirect_to :action => 'show', :id => @role |
34 | else | 35 | else |
@@ -38,7 +39,7 @@ class RoleController < AdminController | @@ -38,7 +39,7 @@ class RoleController < AdminController | ||
38 | end | 39 | end |
39 | 40 | ||
40 | def destroy | 41 | def destroy |
41 | - @role = Role.find(params[:id]) | 42 | + @role = environment.roles.find(params[:id]) |
42 | if @role.destroy | 43 | if @role.destroy |
43 | redirect_to :action => 'index' | 44 | redirect_to :action => 'index' |
44 | else | 45 | else |
app/controllers/my_profile/profile_members_controller.rb
@@ -3,11 +3,11 @@ class ProfileMembersController < MyProfileController | @@ -3,11 +3,11 @@ class ProfileMembersController < MyProfileController | ||
3 | 3 | ||
4 | def index | 4 | def index |
5 | @members = profile.members | 5 | @members = profile.members |
6 | - @member_role = Role.find_by_name('member') | 6 | + @member_role = environment.roles.find_by_name('member') |
7 | end | 7 | end |
8 | 8 | ||
9 | def update_roles | 9 | def update_roles |
10 | - @roles = params[:roles] ? Role.find(params[:roles]) : [] | 10 | + @roles = params[:roles] ? environment.roles.find(params[:roles]) : [] |
11 | @roles = @roles.select{|r| r.has_kind?('Profile') } | 11 | @roles = @roles.select{|r| r.has_kind?('Profile') } |
12 | @person = Person.find(params[:person]) | 12 | @person = Person.find(params[:person]) |
13 | if @person.define_roles(@roles, profile) | 13 | if @person.define_roles(@roles, profile) |
@@ -26,18 +26,18 @@ class ProfileMembersController < MyProfileController | @@ -26,18 +26,18 @@ class ProfileMembersController < MyProfileController | ||
26 | 26 | ||
27 | def add_role | 27 | def add_role |
28 | @person = Person.find(params[:person]) | 28 | @person = Person.find(params[:person]) |
29 | - @role = Role.find(params[:role]) | 29 | + @role = environment.roles.find(params[:role]) |
30 | if @profile.affiliate(@person, @role) | 30 | if @profile.affiliate(@person, @role) |
31 | redirect_to :action => 'index' | 31 | redirect_to :action => 'index' |
32 | else | 32 | else |
33 | @member = Person.find(params[:person]) | 33 | @member = Person.find(params[:person]) |
34 | - @roles = Role.find(:all).select{ |r| r.has_kind?('Profile') } | 34 | + @roles = environment.roles.find(:all).select{ |r| r.has_kind?('Profile') } |
35 | render :action => 'affiliate' | 35 | render :action => 'affiliate' |
36 | end | 36 | end |
37 | end | 37 | end |
38 | 38 | ||
39 | def remove_role | 39 | def remove_role |
40 | - @association = RoleAssignment.find(params[:id]) | 40 | + @association = RoleAssignment.find(:all, :conditions => {:id => params[:id], :target_id => profile.id}) |
41 | if @association.destroy | 41 | if @association.destroy |
42 | flash[:notice] = 'Member succefully unassociated' | 42 | flash[:notice] = 'Member succefully unassociated' |
43 | else | 43 | else |
app/helpers/application_helper.rb
@@ -610,16 +610,16 @@ module ApplicationHelper | @@ -610,16 +610,16 @@ module ApplicationHelper | ||
610 | 610 | ||
611 | def rolename_for(profile, resource) | 611 | def rolename_for(profile, resource) |
612 | role = profile.role_assignments.find_by_resource_id(resource.id).role | 612 | role = profile.role_assignments.find_by_resource_id(resource.id).role |
613 | - content_tag('span', role.name, :style => "color: #{role_color(role)}") | 613 | + content_tag('span', role.name, :style => "color: #{role_color(role, resource.environment.id)}") |
614 | end | 614 | end |
615 | 615 | ||
616 | - def role_color(role) | 616 | + def role_color(role, env_id) |
617 | case role | 617 | case role |
618 | - when Profile::Roles.admin | 618 | + when Profile::Roles.admin(env_id) |
619 | 'blue' | 619 | 'blue' |
620 | - when Profile::Roles.member | 620 | + when Profile::Roles.member(env_id) |
621 | 'green' | 621 | 'green' |
622 | - when Profile::Roles.moderator | 622 | + when Profile::Roles.moderator(env_id) |
623 | 'gray' | 623 | 'gray' |
624 | else | 624 | else |
625 | 'black' | 625 | 'black' |
app/models/add_member.rb
@@ -11,7 +11,7 @@ class AddMember < Task | @@ -11,7 +11,7 @@ class AddMember < Task | ||
11 | acts_as_having_settings :roles, :field => :data | 11 | acts_as_having_settings :roles, :field => :data |
12 | 12 | ||
13 | def perform | 13 | def perform |
14 | - self.roles ||= [Profile::Roles.member.id] | 14 | + self.roles ||= [Profile::Roles.member(organization.environment.id).id] |
15 | target.affiliate(requestor, self.roles.map{|i| Role.find(i)}) | 15 | target.affiliate(requestor, self.roles.map{|i| Role.find(i)}) |
16 | end | 16 | end |
17 | 17 |
app/models/enterprise.rb
@@ -82,7 +82,7 @@ class Enterprise < Organization | @@ -82,7 +82,7 @@ class Enterprise < Organization | ||
82 | 82 | ||
83 | def enable(owner) | 83 | def enable(owner) |
84 | return if enabled | 84 | return if enabled |
85 | - affiliate(owner, Profile::Roles.all_roles) | 85 | + affiliate(owner, Profile::Roles.all_roles(environment.id)) |
86 | update_attribute(:enabled,true) | 86 | update_attribute(:enabled,true) |
87 | if environment.replace_enterprise_template_when_enable | 87 | if environment.replace_enterprise_template_when_enable |
88 | apply_template(template) | 88 | apply_template(template) |
app/models/environment.rb
@@ -15,8 +15,8 @@ class Environment < ActiveRecord::Base | @@ -15,8 +15,8 @@ class Environment < ActiveRecord::Base | ||
15 | } | 15 | } |
16 | 16 | ||
17 | module Roles | 17 | module Roles |
18 | - def self.admin | ||
19 | - Role.find_by_key('environment_administrator') | 18 | + def self.admin(env_id) |
19 | + Role.find_by_key_and_environment_id('environment_administrator', env_id) | ||
20 | end | 20 | end |
21 | end | 21 | end |
22 | 22 | ||
@@ -91,6 +91,8 @@ class Environment < ActiveRecord::Base | @@ -91,6 +91,8 @@ class Environment < ActiveRecord::Base | ||
91 | 91 | ||
92 | has_many :regions | 92 | has_many :regions |
93 | 93 | ||
94 | + has_many :roles | ||
95 | + | ||
94 | acts_as_accessible | 96 | acts_as_accessible |
95 | 97 | ||
96 | def superior_intances | 98 | def superior_intances |
app/models/profile.rb
@@ -4,23 +4,28 @@ | @@ -4,23 +4,28 @@ | ||
4 | class Profile < ActiveRecord::Base | 4 | class Profile < ActiveRecord::Base |
5 | 5 | ||
6 | module Roles | 6 | module Roles |
7 | - def self.admin | ||
8 | - ::Role.find_by_key('profile_admin') | 7 | + def self.admin(env_id) |
8 | + find_role('admin', env_id) | ||
9 | end | 9 | end |
10 | - def self.member | ||
11 | - ::Role.find_by_key('profile_member') | 10 | + def self.member(env_id) |
11 | + find_role('member', env_id) | ||
12 | end | 12 | end |
13 | - def self.moderator | ||
14 | - ::Role.find_by_key('profile_moderator') | 13 | + def self.moderator(env_id) |
14 | + find_role('moderator', env_id) | ||
15 | end | 15 | end |
16 | - def self.owner | ||
17 | - ::Role.find_by_key('profile_owner') | 16 | + def self.owner(env_id) |
17 | + find_role('owner', env_id) | ||
18 | end | 18 | end |
19 | - def self.editor | ||
20 | - ::Role.find_by_key('profile_editor') | 19 | + def self.editor(env_id) |
20 | + find_role('editor', env_id) | ||
21 | end | 21 | end |
22 | - def self.all_roles | ||
23 | - [admin, member, moderator, owner, editor] | 22 | + def self.all_roles(env_id) |
23 | + [admin(env_id), member(env_id), moderator(env_id), owner(env_id), editor(env_id)] | ||
24 | + end | ||
25 | + | ||
26 | + private | ||
27 | + def self.find_role(name, env_id) | ||
28 | + ::Role.find_by_key_and_environment_id("profile_#{name}", env_id) | ||
24 | end | 29 | end |
25 | end | 30 | end |
26 | 31 | ||
@@ -463,7 +468,7 @@ class Profile < ActiveRecord::Base | @@ -463,7 +468,7 @@ class Profile < ActiveRecord::Base | ||
463 | if self.closed? | 468 | if self.closed? |
464 | AddMember.create!(:person => person, :organization => self) | 469 | AddMember.create!(:person => person, :organization => self) |
465 | else | 470 | else |
466 | - self.affiliate(person, Profile::Roles.member) | 471 | + self.affiliate(person, Profile::Roles.member(environment.id)) |
467 | end | 472 | end |
468 | else | 473 | else |
469 | raise _("%s can't has members") % self.class.name | 474 | raise _("%s can't has members") % self.class.name |
@@ -471,17 +476,17 @@ class Profile < ActiveRecord::Base | @@ -471,17 +476,17 @@ class Profile < ActiveRecord::Base | ||
471 | end | 476 | end |
472 | 477 | ||
473 | def remove_member(person) | 478 | def remove_member(person) |
474 | - self.disaffiliate(person, Profile::Roles.all_roles) | 479 | + self.disaffiliate(person, Profile::Roles.all_roles(environment.id)) |
475 | end | 480 | end |
476 | 481 | ||
477 | # adds a person as administrator os this profile | 482 | # adds a person as administrator os this profile |
478 | def add_admin(person) | 483 | def add_admin(person) |
479 | - self.affiliate(person, Profile::Roles.admin) | 484 | + self.affiliate(person, Profile::Roles.admin(environment.id)) |
480 | end | 485 | end |
481 | 486 | ||
482 | def add_moderator(person) | 487 | def add_moderator(person) |
483 | if self.has_members? | 488 | if self.has_members? |
484 | - self.affiliate(person, Profile::Roles.moderator) | 489 | + self.affiliate(person, Profile::Roles.moderator(environment.id)) |
485 | else | 490 | else |
486 | raise _("%s can't has moderators") % self.class.name | 491 | raise _("%s can't has moderators") % self.class.name |
487 | end | 492 | end |
@@ -600,7 +605,7 @@ class Profile < ActiveRecord::Base | @@ -600,7 +605,7 @@ class Profile < ActiveRecord::Base | ||
600 | end | 605 | end |
601 | 606 | ||
602 | def admins | 607 | def admins |
603 | - self.members_by_role(Profile::Roles.admin) | 608 | + self.members_by_role(Profile::Roles.admin(environment.id)) |
604 | end | 609 | end |
605 | 610 | ||
606 | def enable_contact? | 611 | def enable_contact? |
app/views/tasks/_add_member.rhtml
@@ -24,10 +24,10 @@ | @@ -24,10 +24,10 @@ | ||
24 | <p class="member-classify-suggestions"> | 24 | <p class="member-classify-suggestions"> |
25 | <%= _('Roles:') %> <br> | 25 | <%= _('Roles:') %> <br> |
26 | <% | 26 | <% |
27 | - @roles = Role.find(:all).select{ |r| r.has_kind?('Profile') } | 27 | + @roles = task.target.environment.roles.find(:all).select{ |r| r.has_kind?('Profile') } |
28 | %> | 28 | %> |
29 | <% @roles.each do |r| %> | 29 | <% @roles.each do |r| %> |
30 | - <%= labelled_check_box(r.name, 'task[roles][]', r.id, ( task.target.members.empty? ? true : ( r.id == Profile::Roles.member.id ) ) ) %><br/> | 30 | + <%= labelled_check_box(r.name, 'task[roles][]', r.id, ( task.target.members.empty? ? true : ( r.id == Profile::Roles.member(r.environment.id).id ) ) ) %><br/> |
31 | <% end %> | 31 | <% end %> |
32 | </p> | 32 | </p> |
33 | </div> | 33 | </div> |
@@ -0,0 +1,50 @@ | @@ -0,0 +1,50 @@ | ||
1 | +class Environment < ActiveRecord::Base; end | ||
2 | +class Role < ActiveRecord::Base; end | ||
3 | +class RoleWithEnvironment < ActiveRecord::Base | ||
4 | + set_table_name 'roles' | ||
5 | + belongs_to :environment | ||
6 | +end | ||
7 | +class RoleAssignment < ActiveRecord::Base | ||
8 | + belongs_to :accessor, :polymorphic => true | ||
9 | + belongs_to :target, :polymorphic => true | ||
10 | +end | ||
11 | + | ||
12 | +class AddEnviromentIdToRole < ActiveRecord::Migration | ||
13 | + def self.up | ||
14 | + add_column :roles, :environment_id, :integer | ||
15 | + | ||
16 | + roles = Role.find(:all) | ||
17 | + Environment.find(:all).each do |env| | ||
18 | + roles.each do |role| | ||
19 | + re = RoleWithEnvironment.new(role.attributes) | ||
20 | + re.environment = env | ||
21 | + re.save | ||
22 | + RoleAssignment.find_all_by_role_id(role.id).select{|ra| (ra.target.kind_of?(Profile) ? ra.target.environment_id : ra.target.id) == env.id }.each do |ra| | ||
23 | + ra.role_id = re.id | ||
24 | + ra.save | ||
25 | + end | ||
26 | + end | ||
27 | + end | ||
28 | + roles.each(&:destroy) | ||
29 | + end | ||
30 | + | ||
31 | + def self.down | ||
32 | + roles_by_name = {} | ||
33 | + roles_by_key = {} | ||
34 | + roles_with_environment = RoleWithEnvironment.find(:all) | ||
35 | + roles_with_environment.each do |re| | ||
36 | + if re.key | ||
37 | + role = roles_by_name[re.key] || roles_by_key[re.name] || Role.create(re.attributes) | ||
38 | + roles_by_name[role.name] ||= roles_by_key[role.key] ||= role | ||
39 | + end | ||
40 | + role = roles_by_name[re.name] ||= Role.create(re.attributes) unless role | ||
41 | + RoleAssignment.find_all_by_role_id(re.id).each do |ra| | ||
42 | + ra.role_id = role.id | ||
43 | + ra.save | ||
44 | + end | ||
45 | + end | ||
46 | + roles_with_environment.each(&:destroy) | ||
47 | + | ||
48 | + remove_column :roles, :environment_id, :integer | ||
49 | + end | ||
50 | +end |
db/schema.rb
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | # | 9 | # |
10 | # It's strongly recommended to check this file into your version control system. | 10 | # It's strongly recommended to check this file into your version control system. |
11 | 11 | ||
12 | -ActiveRecord::Schema.define(:version => 68) do | 12 | +ActiveRecord::Schema.define(:version => 69) do |
13 | 13 | ||
14 | create_table "article_versions", :force => true do |t| | 14 | create_table "article_versions", :force => true do |t| |
15 | t.integer "article_id" | 15 | t.integer "article_id" |
@@ -279,7 +279,8 @@ ActiveRecord::Schema.define(:version => 68) do | @@ -279,7 +279,8 @@ ActiveRecord::Schema.define(:version => 68) do | ||
279 | t.string "name" | 279 | t.string "name" |
280 | t.text "permissions" | 280 | t.text "permissions" |
281 | t.string "key" | 281 | t.string "key" |
282 | - t.boolean "system", :default => false | 282 | + t.boolean "system", :default => false |
283 | + t.integer "environment_id" | ||
283 | end | 284 | end |
284 | 285 | ||
285 | create_table "taggings", :force => true do |t| | 286 | create_table "taggings", :force => true do |t| |
lib/tasks/populate.rake
@@ -13,18 +13,20 @@ namespace :db do | @@ -13,18 +13,20 @@ namespace :db do | ||
13 | end | 13 | end |
14 | 14 | ||
15 | def new_permissions | 15 | def new_permissions |
16 | - admin = Profile::Roles.admin | 16 | + e = Environment.default |
17 | + admin = Profile::Roles.admin(e.id) | ||
17 | admin.permissions += ['manage_friends', 'validate_enterprise', 'perform_task'] | 18 | admin.permissions += ['manage_friends', 'validate_enterprise', 'perform_task'] |
18 | admin.save | 19 | admin.save |
19 | 20 | ||
20 | - moderator = Profile::Roles.moderator | 21 | + moderator = Profile::Roles.moderator(e.id) |
21 | moderator.permissions += ['manage_friends', 'perform_task'] | 22 | moderator.permissions += ['manage_friends', 'perform_task'] |
22 | moderator.save | 23 | moderator.save |
23 | end | 24 | end |
24 | 25 | ||
25 | def create_roles | 26 | def create_roles |
27 | + e = Environment.default | ||
26 | # Environment administrator! | 28 | # Environment administrator! |
27 | - Role.create!(:key => 'environment_administrator', :name => N_('Environment Administrator'), :permissions => [ | 29 | + Role.create!(:key => 'environment_administrator', :name => N_('Environment Administrator'), :environment => e, :permissions => [ |
28 | 'view_environment_admin_panel', | 30 | 'view_environment_admin_panel', |
29 | 'edit_environment_features', | 31 | 'edit_environment_features', |
30 | 'edit_environment_design', | 32 | 'edit_environment_design', |
@@ -39,7 +41,7 @@ def create_roles | @@ -39,7 +41,7 @@ def create_roles | ||
39 | 'manage_products', | 41 | 'manage_products', |
40 | 'edit_appearance', | 42 | 'edit_appearance', |
41 | ]) | 43 | ]) |
42 | - Role.create!(:key => 'profile_admin', :name => N_('Profile Administrator'), :permissions => [ | 44 | + Role.create!(:key => 'profile_admin', :name => N_('Profile Administrator'), :environment => e, :permissions => [ |
43 | 'edit_profile', | 45 | 'edit_profile', |
44 | 'destroy_profile', | 46 | 'destroy_profile', |
45 | 'manage_memberships', | 47 | 'manage_memberships', |
@@ -49,13 +51,13 @@ def create_roles | @@ -49,13 +51,13 @@ def create_roles | ||
49 | 'edit_appearance', | 51 | 'edit_appearance', |
50 | ]) | 52 | ]) |
51 | # members for enterprises, communities etc | 53 | # members for enterprises, communities etc |
52 | - Role.create!(:key => "profile_member", :name => N_('Member'), :permissions => [ | 54 | + Role.create!(:key => "profile_member", :name => N_('Member'), :environment => e, :permissions => [ |
53 | 'edit_profile', | 55 | 'edit_profile', |
54 | 'post_content', | 56 | 'post_content', |
55 | 'manage_products' | 57 | 'manage_products' |
56 | ]) | 58 | ]) |
57 | # moderators for enterprises, communities etc | 59 | # moderators for enterprises, communities etc |
58 | - Role.create!(:key => 'profile_moderator', :name => N_('Moderator'), :permissions => [ | 60 | + Role.create!(:key => 'profile_moderator', :name => N_('Moderator'), :environment => e, :permissions => [ |
59 | 'manage_memberships', | 61 | 'manage_memberships', |
60 | 'edit_profile_design', | 62 | 'edit_profile_design', |
61 | 'manage_products' | 63 | 'manage_products' |
script/anhetegua
@@ -150,19 +150,19 @@ colivre = new_validator(ba, "Colivre", 'colivre', Enterprise) | @@ -150,19 +150,19 @@ colivre = new_validator(ba, "Colivre", 'colivre', Enterprise) | ||
150 | #forum_rs = new_validator(rs, 'Forum Gaucho de Economia Solidaria', 'ecosolrs') | 150 | #forum_rs = new_validator(rs, 'Forum Gaucho de Economia Solidaria', 'ecosolrs') |
151 | 151 | ||
152 | # Role for own things | 152 | # Role for own things |
153 | -owner_role = Profile::Roles.admin | 153 | +owner_role = Profile::Roles.admin(Environment.default.id) |
154 | 154 | ||
155 | # Sample user and sample enterprise owned by him | 155 | # Sample user and sample enterprise owned by him |
156 | ze = User.create!(:login => 'ze', :email => 'ze@localhost.localdomain', :password => 'test', :password_confirmation => 'test').person | 156 | ze = User.create!(:login => 'ze', :email => 'ze@localhost.localdomain', :password => 'test', :password_confirmation => 'test').person |
157 | 157 | ||
158 | -Environment.default.affiliate(ze, Environment::Roles.admin) | 158 | +Environment.default.affiliate(ze, Environment::Roles.admin(Environment.default.id)) |
159 | empa = Enterprise.create!(:name => 'Cooperativa A', :identifier => 'coop_a') | 159 | empa = Enterprise.create!(:name => 'Cooperativa A', :identifier => 'coop_a') |
160 | 160 | ||
161 | empa.affiliate(ze, owner_role) | 161 | empa.affiliate(ze, owner_role) |
162 | colivre.affiliate(ze, owner_role) | 162 | colivre.affiliate(ze, owner_role) |
163 | 163 | ||
164 | -member_role = Profile::Roles.member | ||
165 | -moderator_role = Profile::Roles.moderator | 164 | +member_role = Profile::Roles.member(Environment.default.id) |
165 | +moderator_role = Profile::Roles.moderator(Environment.default.id) | ||
166 | 166 | ||
167 | # product categories | 167 | # product categories |
168 | produtos = ProductCategory.create!(:name => 'Produtos', :environment => Environment.default) | 168 | produtos = ProductCategory.create!(:name => 'Produtos', :environment => Environment.default) |
test/fixtures/roles.yml
1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | 1 | # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html |
2 | one: | 2 | one: |
3 | id: 1 | 3 | id: 1 |
4 | + environment_id: 1 | ||
4 | name: 'member' | 5 | name: 'member' |
5 | permissions: | 6 | permissions: |
6 | - post_content | 7 | - post_content |
7 | two: | 8 | two: |
8 | id: 2 | 9 | id: 2 |
10 | + environment_id: 1 | ||
9 | name: 'owner' | 11 | name: 'owner' |
10 | permissions: | 12 | permissions: |
11 | - menage_memberships | 13 | - menage_memberships |
@@ -14,11 +16,13 @@ two: | @@ -14,11 +16,13 @@ two: | ||
14 | - edit_profile | 16 | - edit_profile |
15 | three: | 17 | three: |
16 | id: 3 | 18 | id: 3 |
19 | + environment_id: 1 | ||
17 | name: 'moderator' | 20 | name: 'moderator' |
18 | permissions: | 21 | permissions: |
19 | - manage_memberships | 22 | - manage_memberships |
20 | four: | 23 | four: |
21 | id: 4 | 24 | id: 4 |
25 | + environment_id: 1 | ||
22 | name: 'admin' | 26 | name: 'admin' |
23 | permissions: | 27 | permissions: |
24 | - view_environment_admin_panel | 28 | - view_environment_admin_panel |
@@ -31,6 +35,7 @@ four: | @@ -31,6 +35,7 @@ four: | ||
31 | - perform_task | 35 | - perform_task |
32 | profile_admin: | 36 | profile_admin: |
33 | id: 5 | 37 | id: 5 |
38 | + environment_id: 1 | ||
34 | key: 'profile_admin' | 39 | key: 'profile_admin' |
35 | name: 'Profile Administrator' | 40 | name: 'Profile Administrator' |
36 | system: true | 41 | system: true |
@@ -43,6 +48,7 @@ profile_admin: | @@ -43,6 +48,7 @@ profile_admin: | ||
43 | - view_private_content | 48 | - view_private_content |
44 | profile_member: | 49 | profile_member: |
45 | id: 6 | 50 | id: 6 |
51 | + environment_id: 1 | ||
46 | key: 'profile_member' | 52 | key: 'profile_member' |
47 | name: 'Profile Member' | 53 | name: 'Profile Member' |
48 | system: true | 54 | system: true |
@@ -52,6 +58,7 @@ profile_member: | @@ -52,6 +58,7 @@ profile_member: | ||
52 | - manage_products | 58 | - manage_products |
53 | profile_moderator: | 59 | profile_moderator: |
54 | id: 7 | 60 | id: 7 |
61 | + environment_id: 1 | ||
55 | key: 'profile_moderator' | 62 | key: 'profile_moderator' |
56 | name: 'Profile Moderator' | 63 | name: 'Profile Moderator' |
57 | system: true | 64 | system: true |
@@ -60,6 +67,7 @@ profile_moderator: | @@ -60,6 +67,7 @@ profile_moderator: | ||
60 | - view_private_content | 67 | - view_private_content |
61 | environment_administrator: | 68 | environment_administrator: |
62 | id: 8 | 69 | id: 8 |
70 | + environment_id: 1 | ||
63 | key: 'environment_administrator' | 71 | key: 'environment_administrator' |
64 | name: 'Environment administrator' | 72 | name: 'Environment administrator' |
65 | system: true | 73 | system: true |
test/functional/cms_controller_test.rb
@@ -626,7 +626,7 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -626,7 +626,7 @@ class CmsControllerTest < Test::Unit::TestCase | ||
626 | 626 | ||
627 | should 'load communities for that the user belongs' do | 627 | should 'load communities for that the user belongs' do |
628 | c = Community.create!(:name => 'test comm', :identifier => 'test_comm') | 628 | c = Community.create!(:name => 'test comm', :identifier => 'test_comm') |
629 | - c.affiliate(profile, Profile::Roles.all_roles) | 629 | + c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) |
630 | a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') | 630 | a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') |
631 | 631 | ||
632 | get :publish, :profile => profile.identifier, :id => a.id | 632 | get :publish, :profile => profile.identifier, :id => a.id |
@@ -637,7 +637,7 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -637,7 +637,7 @@ class CmsControllerTest < Test::Unit::TestCase | ||
637 | 637 | ||
638 | should 'publish the article in the selected community if community is not moderated' do | 638 | should 'publish the article in the selected community if community is not moderated' do |
639 | c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => false) | 639 | c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => false) |
640 | - c.affiliate(profile, Profile::Roles.all_roles) | 640 | + c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) |
641 | a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') | 641 | a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') |
642 | 642 | ||
643 | assert_difference PublishedArticle, :count do | 643 | assert_difference PublishedArticle, :count do |
@@ -648,7 +648,7 @@ class CmsControllerTest < Test::Unit::TestCase | @@ -648,7 +648,7 @@ class CmsControllerTest < Test::Unit::TestCase | ||
648 | 648 | ||
649 | should 'create a task for article approval if community is moderated' do | 649 | should 'create a task for article approval if community is moderated' do |
650 | c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => true) | 650 | c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => true) |
651 | - c.affiliate(profile, Profile::Roles.all_roles) | 651 | + c.affiliate(profile, Profile::Roles.all_roles(c.environment.id)) |
652 | a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') | 652 | a = profile.articles.create!(:name => 'something intresting', :body => 'ruby on rails') |
653 | 653 | ||
654 | assert_no_difference PublishedArticle, :count do | 654 | assert_no_difference PublishedArticle, :count do |
test/functional/content_viewer_controller_test.rb
@@ -490,7 +490,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -490,7 +490,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
490 | person = create_user('test_user').person | 490 | person = create_user('test_user').person |
491 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 491 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
492 | intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) | 492 | intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) |
493 | - profile.affiliate(person, Profile::Roles.member) | 493 | + profile.affiliate(person, Profile::Roles.member(profile.environment.id)) |
494 | login_as('test_user') | 494 | login_as('test_user') |
495 | 495 | ||
496 | @request.stubs(:ssl?).returns(true) | 496 | @request.stubs(:ssl?).returns(true) |
@@ -503,7 +503,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -503,7 +503,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
503 | person = create_user('test_user').person | 503 | person = create_user('test_user').person |
504 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 504 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
505 | intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) | 505 | intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) |
506 | - profile.affiliate(person, Profile::Roles.moderator) | 506 | + profile.affiliate(person, Profile::Roles.moderator(profile.environment.id)) |
507 | login_as('test_user') | 507 | login_as('test_user') |
508 | 508 | ||
509 | @request.stubs(:ssl?).returns(true) | 509 | @request.stubs(:ssl?).returns(true) |
@@ -516,7 +516,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -516,7 +516,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
516 | person = create_user('test_user').person | 516 | person = create_user('test_user').person |
517 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 517 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
518 | intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) | 518 | intranet = Folder.create!(:name => 'my_intranet', :profile => profile, :public_article => false) |
519 | - profile.affiliate(person, Profile::Roles.admin) | 519 | + profile.affiliate(person, Profile::Roles.admin(profile.environment.id)) |
520 | login_as('test_user') | 520 | login_as('test_user') |
521 | 521 | ||
522 | @request.stubs(:ssl?).returns(true) | 522 | @request.stubs(:ssl?).returns(true) |
@@ -566,7 +566,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | @@ -566,7 +566,7 @@ class ContentViewerControllerTest < Test::Unit::TestCase | ||
566 | should 'not show link to publication on view if not on person profile' do | 566 | should 'not show link to publication on view if not on person profile' do |
567 | prof = Community.create!(:name => 'test comm', :identifier => 'test_comm') | 567 | prof = Community.create!(:name => 'test comm', :identifier => 'test_comm') |
568 | page = prof.articles.create!(:name => 'myarticle', :body => 'the body of the text') | 568 | page = prof.articles.create!(:name => 'myarticle', :body => 'the body of the text') |
569 | - prof.affiliate(profile, Profile::Roles.all_roles) | 569 | + prof.affiliate(profile, Profile::Roles.all_roles(prof.environment.id)) |
570 | login_as(profile.identifier) | 570 | login_as(profile.identifier) |
571 | 571 | ||
572 | get :view_page, :profile => prof.identifier, :page => ['myarticle'] | 572 | get :view_page, :profile => prof.identifier, :page => ['myarticle'] |
test/functional/memberships_controller_test.rb
@@ -148,7 +148,7 @@ class MembershipsControllerTest < Test::Unit::TestCase | @@ -148,7 +148,7 @@ class MembershipsControllerTest < Test::Unit::TestCase | ||
148 | 148 | ||
149 | should 'current user is added as admin after create new community' do | 149 | should 'current user is added as admin after create new community' do |
150 | post :new_community, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '} | 150 | post :new_community, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '} |
151 | - assert_equal Profile::Roles.admin, profile.find_roles(Community.find_by_identifier('my-shiny-new-community')).first.role | 151 | + assert_equal Profile::Roles.admin(profile.environment.id), profile.find_roles(Community.find_by_identifier('my-shiny-new-community')).first.role |
152 | end | 152 | end |
153 | 153 | ||
154 | should 'display button to create community' do | 154 | should 'display button to create community' do |
test/functional/profile_editor_controller_test.rb
@@ -13,7 +13,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | @@ -13,7 +13,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase | ||
13 | @request.stubs(:ssl?).returns(true) | 13 | @request.stubs(:ssl?).returns(true) |
14 | @response = ActionController::TestResponse.new | 14 | @response = ActionController::TestResponse.new |
15 | @profile = create_user('default_user').person | 15 | @profile = create_user('default_user').person |
16 | - Environment.default.affiliate(@profile, [Environment::Roles.admin] + Profile::Roles.all_roles) | 16 | + Environment.default.affiliate(@profile, [Environment::Roles.admin(Environment.default.id)] + Profile::Roles.all_roles(Environment.default.id)) |
17 | login_as('default_user') | 17 | login_as('default_user') |
18 | end | 18 | end |
19 | attr_reader :profile | 19 | attr_reader :profile |
test/functional/profile_members_controller_test.rb
@@ -63,8 +63,8 @@ class ProfileMembersControllerTest < Test::Unit::TestCase | @@ -63,8 +63,8 @@ class ProfileMembersControllerTest < Test::Unit::TestCase | ||
63 | 63 | ||
64 | should 'update roles' do | 64 | should 'update roles' do |
65 | ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'test enterprise') | 65 | ent = Enterprise.create!(:identifier => 'test_enterprise', :name => 'test enterprise') |
66 | - role1 = Role.create!(:name => 'member_role', :permissions => ['edit_profile']) | ||
67 | - role2 = Role.create!(:name => 'owner_role', :permissions => ['edit_profile', 'destroy_profile']) | 66 | + role1 = Role.create!(:name => 'member_role', :permissions => ['edit_profile'], :environment => ent.environment) |
67 | + role2 = Role.create!(:name => 'owner_role', :permissions => ['edit_profile', 'destroy_profile'], :environment => ent.environment) | ||
68 | 68 | ||
69 | member = create_user('test_member').person | 69 | member = create_user('test_member').person |
70 | member.add_role(role1, ent) | 70 | member.add_role(role1, ent) |
test/functional/tasks_controller_test.rb
@@ -78,19 +78,19 @@ class TasksControllerTest < Test::Unit::TestCase | @@ -78,19 +78,19 @@ class TasksControllerTest < Test::Unit::TestCase | ||
78 | end | 78 | end |
79 | 79 | ||
80 | should 'display member role checked if target has members' do | 80 | should 'display member role checked if target has members' do |
81 | - profile.affiliate(profile, Profile::Roles.admin) | 81 | + profile.affiliate(profile, Profile::Roles.admin(profile.environment.id)) |
82 | assert_equal 1, profile.members.size | 82 | assert_equal 1, profile.members.size |
83 | t = AddMember.create!(:person => profile, :organization => profile) | 83 | t = AddMember.create!(:person => profile, :organization => profile) |
84 | get :index, :profile => profile.identifier | 84 | get :index, :profile => profile.identifier |
85 | - assert_tag :tag => 'input', :attributes => { :name => 'task[roles][]', :checked => 'checked', :value => Profile::Roles.member.id } | 85 | + assert_tag :tag => 'input', :attributes => { :name => 'task[roles][]', :checked => 'checked', :value => Profile::Roles.member(profile.environment.id).id } |
86 | end | 86 | end |
87 | 87 | ||
88 | should 'display roles besides role member unchecked if target has members' do | 88 | should 'display roles besides role member unchecked if target has members' do |
89 | - profile.affiliate(profile, Profile::Roles.admin) | 89 | + profile.affiliate(profile, Profile::Roles.admin(profile.environment.id)) |
90 | assert_equal 1, profile.members.size | 90 | assert_equal 1, profile.members.size |
91 | t = AddMember.create!(:person => profile, :organization => profile) | 91 | t = AddMember.create!(:person => profile, :organization => profile) |
92 | get :index, :profile => profile.identifier | 92 | get :index, :profile => profile.identifier |
93 | - Role.find(:all).select{ |r| r.has_kind?('Profile') and r.id != Profile::Roles.member.id }.each do |i| | 93 | + Role.find(:all).select{ |r| r.has_kind?('Profile') and r.id != Profile::Roles.member(profile.environment.id).id }.each do |i| |
94 | assert_no_tag :tag => 'input', :attributes => { :name => 'task[roles][]', :checked => 'checked', :value => i.id } | 94 | assert_no_tag :tag => 'input', :attributes => { :name => 'task[roles][]', :checked => 'checked', :value => i.id } |
95 | end | 95 | end |
96 | end | 96 | end |
@@ -157,7 +157,7 @@ class TasksControllerTest < Test::Unit::TestCase | @@ -157,7 +157,7 @@ class TasksControllerTest < Test::Unit::TestCase | ||
157 | PublishedArticle.destroy_all | 157 | PublishedArticle.destroy_all |
158 | c = Community.create!(:name => 'test comm', :moderated_articles => false) | 158 | c = Community.create!(:name => 'test comm', :moderated_articles => false) |
159 | @controller.stubs(:profile).returns(c) | 159 | @controller.stubs(:profile).returns(c) |
160 | - c.affiliate(profile, Profile::Roles.all_roles) | 160 | + c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id)) |
161 | article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails') | 161 | article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails') |
162 | t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile) | 162 | t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile) |
163 | 163 | ||
@@ -170,7 +170,7 @@ class TasksControllerTest < Test::Unit::TestCase | @@ -170,7 +170,7 @@ class TasksControllerTest < Test::Unit::TestCase | ||
170 | c = Community.create!(:name => 'test comm', :moderated_articles => false) | 170 | c = Community.create!(:name => 'test comm', :moderated_articles => false) |
171 | @controller.stubs(:profile).returns(c) | 171 | @controller.stubs(:profile).returns(c) |
172 | folder = c.articles.create!(:name => 'test folder', :type => 'Folder') | 172 | folder = c.articles.create!(:name => 'test folder', :type => 'Folder') |
173 | - c.affiliate(profile, Profile::Roles.all_roles) | 173 | + c.affiliate(profile, Profile::Roles.all_roles(profile.environment.id)) |
174 | article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails') | 174 | article = profile.articles.create!(:name => 'something interesting', :body => 'ruby on rails') |
175 | t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile) | 175 | t = ApproveArticle.create!(:name => 'test name', :article => article, :target => c, :requestor => profile) |
176 | 176 |
test/unit/add_member_test.rb
@@ -76,7 +76,7 @@ class AddMemberTest < ActiveSupport::TestCase | @@ -76,7 +76,7 @@ class AddMemberTest < ActiveSupport::TestCase | ||
76 | p = create_user('testuser1').person | 76 | p = create_user('testuser1').person |
77 | c = Community.create!(:name => 'community_test') | 77 | c = Community.create!(:name => 'community_test') |
78 | 78 | ||
79 | - roles = [Profile::Roles.member, Profile::Roles.admin] | 79 | + roles = [Profile::Roles.member(c.environment.id), Profile::Roles.admin(c.environment.id)] |
80 | TaskMailer.stubs(:deliver_target_notification) | 80 | TaskMailer.stubs(:deliver_target_notification) |
81 | task = AddMember.create!(:roles => roles.map(&:id), :person => p, :organization => c) | 81 | task = AddMember.create!(:roles => roles.map(&:id), :person => p, :organization => c) |
82 | task.finish | 82 | task.finish |
test/unit/application_helper_test.rb
@@ -73,16 +73,16 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -73,16 +73,16 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
73 | end | 73 | end |
74 | 74 | ||
75 | should 'role color for admin role' do | 75 | should 'role color for admin role' do |
76 | - assert_equal 'blue', role_color(Profile::Roles.admin) | 76 | + assert_equal 'blue', role_color(Profile::Roles.admin(Environment.default.id), Environment.default.id) |
77 | end | 77 | end |
78 | should 'role color for member role' do | 78 | should 'role color for member role' do |
79 | - assert_equal 'green', role_color(Profile::Roles.member) | 79 | + assert_equal 'green', role_color(Profile::Roles.member(Environment.default.id), Environment.default.id) |
80 | end | 80 | end |
81 | should 'role color for moderator role' do | 81 | should 'role color for moderator role' do |
82 | - assert_equal 'gray', role_color(Profile::Roles.moderator) | 82 | + assert_equal 'gray', role_color(Profile::Roles.moderator(Environment.default.id), Environment.default.id) |
83 | end | 83 | end |
84 | should 'default role color' do | 84 | should 'default role color' do |
85 | - assert_equal 'black', role_color('none') | 85 | + assert_equal 'black', role_color('none', Environment.default.id) |
86 | end | 86 | end |
87 | 87 | ||
88 | should 'rolename for' do | 88 | should 'rolename for' do |
test/unit/article_test.rb
@@ -452,7 +452,7 @@ class ArticleTest < Test::Unit::TestCase | @@ -452,7 +452,7 @@ class ArticleTest < Test::Unit::TestCase | ||
452 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 452 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
453 | article = Article.create!(:name => 'test article', :profile => profile, :public_article => false) | 453 | article = Article.create!(:name => 'test article', :profile => profile, :public_article => false) |
454 | person = create_user('test_user').person | 454 | person = create_user('test_user').person |
455 | - profile.affiliate(person, Profile::Roles.member) | 455 | + profile.affiliate(person, Profile::Roles.member(profile.environment.id)) |
456 | 456 | ||
457 | assert !article.display_to?(person) | 457 | assert !article.display_to?(person) |
458 | end | 458 | end |
@@ -461,7 +461,7 @@ class ArticleTest < Test::Unit::TestCase | @@ -461,7 +461,7 @@ class ArticleTest < Test::Unit::TestCase | ||
461 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 461 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
462 | article = Article.create!(:name => 'test article', :profile => profile, :public_article => false) | 462 | article = Article.create!(:name => 'test article', :profile => profile, :public_article => false) |
463 | person = create_user('test_user').person | 463 | person = create_user('test_user').person |
464 | - profile.affiliate(person, Profile::Roles.admin) | 464 | + profile.affiliate(person, Profile::Roles.admin(profile.environment.id)) |
465 | 465 | ||
466 | assert article.display_to?(person) | 466 | assert article.display_to?(person) |
467 | end | 467 | end |
@@ -470,7 +470,7 @@ class ArticleTest < Test::Unit::TestCase | @@ -470,7 +470,7 @@ class ArticleTest < Test::Unit::TestCase | ||
470 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 470 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') |
471 | article = Article.create!(:name => 'test article', :profile => profile, :public_article => false) | 471 | article = Article.create!(:name => 'test article', :profile => profile, :public_article => false) |
472 | person = create_user('test_user').person | 472 | person = create_user('test_user').person |
473 | - profile.affiliate(person, Profile::Roles.moderator) | 473 | + profile.affiliate(person, Profile::Roles.moderator(profile.environment.id)) |
474 | 474 | ||
475 | assert article.display_to?(person) | 475 | assert article.display_to?(person) |
476 | end | 476 | end |
@@ -479,7 +479,7 @@ class ArticleTest < Test::Unit::TestCase | @@ -479,7 +479,7 @@ class ArticleTest < Test::Unit::TestCase | ||
479 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile', :public_profile => false) | 479 | profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile', :public_profile => false) |
480 | article = Article.create!(:name => 'test article', :profile => profile, :public_article => true) | 480 | article = Article.create!(:name => 'test article', :profile => profile, :public_article => true) |
481 | person1 = create_user('test_user1').person | 481 | person1 = create_user('test_user1').person |
482 | - profile.affiliate(person1, Profile::Roles.member) | 482 | + profile.affiliate(person1, Profile::Roles.member(profile.environment.id)) |
483 | person2 = create_user('test_user2').person | 483 | person2 = create_user('test_user2').person |
484 | 484 | ||
485 | assert !article.display_to?(nil) | 485 | assert !article.display_to?(nil) |
test/unit/enterprises_block_test.rb
@@ -56,8 +56,8 @@ class EnterprisesBlockTest < Test::Unit::TestCase | @@ -56,8 +56,8 @@ class EnterprisesBlockTest < Test::Unit::TestCase | ||
56 | 56 | ||
57 | should 'not list private enterprises in profile' do | 57 | should 'not list private enterprises in profile' do |
58 | person = create_user('test_user').person | 58 | person = create_user('test_user').person |
59 | - role = Profile::Roles.member | ||
60 | e1 = Enterprise.create!(:name => 'test1', :identifier => 'test1', :public_profile => true) | 59 | e1 = Enterprise.create!(:name => 'test1', :identifier => 'test1', :public_profile => true) |
60 | + role = Profile::Roles.member(e1.environment.id) | ||
61 | e1.affiliate(person, role) | 61 | e1.affiliate(person, role) |
62 | e2 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :public_profile => false) #private profile | 62 | e2 = Enterprise.create!(:name => 'test2', :identifier => 'test2', :public_profile => false) #private profile |
63 | e2.affiliate(person, role) | 63 | e2.affiliate(person, role) |
test/unit/environment_test.rb
@@ -308,8 +308,8 @@ class EnvironmentTest < Test::Unit::TestCase | @@ -308,8 +308,8 @@ class EnvironmentTest < Test::Unit::TestCase | ||
308 | end | 308 | end |
309 | 309 | ||
310 | should 'have admin role' do | 310 | should 'have admin role' do |
311 | - Role.expects(:find_by_key).with('environment_administrator').returns(Role.new) | ||
312 | - assert_kind_of Role, Environment::Roles.admin | 311 | + Role.expects(:find_by_key_and_environment_id).with('environment_administrator', Environment.default.id).returns(Role.new) |
312 | + assert_kind_of Role, Environment::Roles.admin(Environment.default.id) | ||
313 | end | 313 | end |
314 | 314 | ||
315 | should 'have products through enterprises' do | 315 | should 'have products through enterprises' do |
@@ -745,4 +745,22 @@ class EnvironmentTest < Test::Unit::TestCase | @@ -745,4 +745,22 @@ class EnvironmentTest < Test::Unit::TestCase | ||
745 | 745 | ||
746 | assert_equal [], e.portal_folders | 746 | assert_equal [], e.portal_folders |
747 | end | 747 | end |
748 | + | ||
749 | + should 'have roles with names independent of other environments' do | ||
750 | + e1 = Environment.create!(:name => 'a test environment') | ||
751 | + role1 = Role.create!(:name => 'test_role', :environment => e1) | ||
752 | + e2 = Environment.create!(:name => 'another test environment') | ||
753 | + role2 = Role.new(:name => 'test_role', :environment => e2) | ||
754 | + | ||
755 | + assert_valid role2 | ||
756 | + end | ||
757 | + | ||
758 | + should 'have roles with keys independent of other environments' do | ||
759 | + e1 = Environment.create!(:name => 'a test environment') | ||
760 | + role1 = Role.create!(:name => 'test_role', :environment => e1, :key => 'a_member') | ||
761 | + e2 = Environment.create!(:name => 'another test environment') | ||
762 | + role2 = Role.new(:name => 'test_role', :environment => e2, :key => 'a_member') | ||
763 | + | ||
764 | + assert_valid role2 | ||
765 | + end | ||
748 | end | 766 | end |
test/unit/profile_test.rb
@@ -337,18 +337,18 @@ class ProfileTest < Test::Unit::TestCase | @@ -337,18 +337,18 @@ class ProfileTest < Test::Unit::TestCase | ||
337 | end | 337 | end |
338 | 338 | ||
339 | should 'have administator role' do | 339 | should 'have administator role' do |
340 | - Role.expects(:find_by_key).with('profile_admin').returns(Role.new) | ||
341 | - assert_kind_of Role, Profile::Roles.admin | 340 | + Role.expects(:find_by_key_and_environment_id).with('profile_admin', Environment.default.id).returns(Role.new) |
341 | + assert_kind_of Role, Profile::Roles.admin(Environment.default.id) | ||
342 | end | 342 | end |
343 | 343 | ||
344 | should 'have member role' do | 344 | should 'have member role' do |
345 | - Role.expects(:find_by_key).with('profile_member').returns(Role.new) | ||
346 | - assert_kind_of Role, Profile::Roles.member | 345 | + Role.expects(:find_by_key_and_environment_id).with('profile_member', Environment.default.id).returns(Role.new) |
346 | + assert_kind_of Role, Profile::Roles.member(Environment.default.id) | ||
347 | end | 347 | end |
348 | 348 | ||
349 | should 'have moderator role' do | 349 | should 'have moderator role' do |
350 | - Role.expects(:find_by_key).with('profile_moderator').returns(Role.new) | ||
351 | - assert_kind_of Role, Profile::Roles.moderator | 350 | + Role.expects(:find_by_key_and_environment_id).with('profile_moderator', Environment.default.id).returns(Role.new) |
351 | + assert_kind_of Role, Profile::Roles.moderator(Environment.default.id) | ||
352 | end | 352 | end |
353 | 353 | ||
354 | should 'not have members by default' do | 354 | should 'not have members by default' do |
@@ -768,9 +768,9 @@ class ProfileTest < Test::Unit::TestCase | @@ -768,9 +768,9 @@ class ProfileTest < Test::Unit::TestCase | ||
768 | end | 768 | end |
769 | 769 | ||
770 | should 'not return nil members when a member is removed from system' do | 770 | should 'not return nil members when a member is removed from system' do |
771 | - p = Profile.create!(:name => 'test profile', :identifier => 'test_profile') | 771 | + p = Community.create!(:name => 'test community', :identifier => 'test_comm') |
772 | member = create_user('test_user').person | 772 | member = create_user('test_user').person |
773 | - p.affiliate(member, Profile::Roles.member) | 773 | + p.add_member(member) |
774 | 774 | ||
775 | member.destroy | 775 | member.destroy |
776 | p.reload | 776 | p.reload |
@@ -905,7 +905,7 @@ class ProfileTest < Test::Unit::TestCase | @@ -905,7 +905,7 @@ class ProfileTest < Test::Unit::TestCase | ||
905 | should 'remove member with many roles' do | 905 | should 'remove member with many roles' do |
906 | person = create_user('test_user').person | 906 | person = create_user('test_user').person |
907 | community = Community.create!(:name => 'Boca do Siri', :identifier => 'boca_do_siri') | 907 | community = Community.create!(:name => 'Boca do Siri', :identifier => 'boca_do_siri') |
908 | - community.affiliate(person, Profile::Roles.all_roles) | 908 | + community.affiliate(person, Profile::Roles.all_roles(community.environment.id)) |
909 | 909 | ||
910 | community.remove_member(person) | 910 | community.remove_member(person) |
911 | 911 | ||
@@ -1267,8 +1267,8 @@ class ProfileTest < Test::Unit::TestCase | @@ -1267,8 +1267,8 @@ class ProfileTest < Test::Unit::TestCase | ||
1267 | task1 = Task.create!(:requestor => person, :target => env) | 1267 | task1 = Task.create!(:requestor => person, :target => env) |
1268 | task2 = Task.create!(:requestor => person, :target => another) | 1268 | task2 = Task.create!(:requestor => person, :target => another) |
1269 | 1269 | ||
1270 | - another.affiliate(person, Environment::Roles.admin) | ||
1271 | - env.affiliate(person, Environment::Roles.admin) | 1270 | + another.affiliate(person, Environment::Roles.admin(another.id)) |
1271 | + env.affiliate(person, Environment::Roles.admin(env.id)) | ||
1272 | 1272 | ||
1273 | Person.any_instance.stubs(:is_admin?).returns(true) | 1273 | Person.any_instance.stubs(:is_admin?).returns(true) |
1274 | 1274 |
vendor/plugins/access_control/lib/role.rb
1 | class Role < ActiveRecord::Base | 1 | class Role < ActiveRecord::Base |
2 | 2 | ||
3 | has_many :role_assignments | 3 | has_many :role_assignments |
4 | + belongs_to :environment | ||
4 | serialize :permissions, Array | 5 | serialize :permissions, Array |
5 | validates_presence_of :name | 6 | validates_presence_of :name |
6 | - validates_uniqueness_of :name | ||
7 | - validates_uniqueness_of :key, :if => lambda { |role| !role.key.blank? } | 7 | + validates_uniqueness_of :name, :scope => :environment_id |
8 | + validates_uniqueness_of :key, :if => lambda { |role| !role.key.blank? }, :scope => :environment_id | ||
8 | 9 | ||
9 | def initialize(*args) | 10 | def initialize(*args) |
10 | super(*args) | 11 | super(*args) |