Skip to content

Commit

Permalink
Fixed bug preventing edition of logged-in group and public group names.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Sep 18, 2012
1 parent c9e1bed commit 4457cd3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
8 changes: 6 additions & 2 deletions app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ def user_ids
end

def user_ids=(list)
@defined_user_ids = list
if public_group? || site_group?
# ignore
else
@defined_user_ids = list
end
end

alias o_users users
Expand Down Expand Up @@ -92,7 +96,7 @@ def can_destroy?
# Public and admin groups are special. They cannot be destroyed.
def check_can_destroy
# do not destroy admin or public groups
raise Zena::AccessViolation.new("'admin', 'site' or 'public' groups cannot be destroyed") if visitor.site.protected_group_ids.include?( id )
raise Zena::AccessViolation.new("'admin', 'logged-in' or 'public' groups cannot be destroyed") if visitor.site.protected_group_ids.include?( id )
return can_destroy?
end

Expand Down
4 changes: 2 additions & 2 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def create_for_host(host, su_password, opts={})
editors.users << admin_user

# create site group
sgroup = site.send(:secure,Group) { Group.create( :name => 'site') }
raise Exception.new("Could not create site group for site [#{host}] (site#{site[:id]})\n#{sgroup.errors.map{|k,v| "[#{k}] #{v}"}.join("\n")}") if sgroup.new_record?
sgroup = site.send(:secure,Group) { Group.create( :name => 'logged-in') }
raise Exception.new("Could not create logged-in group for site [#{host}] (site#{site[:id]})\n#{sgroup.errors.map{|k,v| "[#{k}] #{v}"}.join("\n")}") if sgroup.new_record?

site.public_group_id = pub[:id]
site.site_group_id = sgroup[:id]
Expand Down
21 changes: 18 additions & 3 deletions test/unit/group_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,27 @@ def test_can_add_to_admin
assert groups(:admin).users.include?(users(:ant))
end

def test_cannot_update_site_or_public
def test_cannot_update_site_or_public_user_ids
login(:lion)
group = groups(:public)
assert !group.update_attributes(:user_ids=>[])
# ignores user_ids
assert group.update_attributes(:user_ids=>[])
assert_equal [users_id(:ant), users_id(:anon), users_id(:tiger), users_id(:lion)].sort, group.user_ids.sort
group = groups(:workers)
assert !group.update_attributes(:user_ids=>[])
# ignores user_ids
assert group.update_attributes(:user_ids=>[])
assert_equal [users_id(:ant), users_id(:tiger), users_id(:lion)].sort, group.user_ids.sort
end

def test_can_update_site_or_public_name
login(:lion)
group = groups(:public)
assert group.update_attributes(:name=>'pub')
assert_equal 'pub', groups(:public).name

group = groups(:workers)
assert group.update_attributes(:name=>'logged-in', :user_ids => [])
assert_equal 'logged-in', groups(:workers).name
end

def test_cannot_destroy_group_with_nodes
Expand Down

0 comments on commit 4457cd3

Please sign in to comment.