diff options
author | Marius Mathiesen <marius@gitorious.org> | 2013-01-02 10:02:49 (GMT) |
---|---|---|
committer | Marius Mathiesen <marius@gitorious.org> | 2013-01-02 10:02:49 (GMT) |
commit | 150012d8e5efbdb73c4b2cb9f344a989b81d2e8e (patch) | |
tree | 7d3bdcb5783de215e9c3af5a5ea26dfa3ee1c3db | |
parent | 61e82d2e9a080da2b3a95aae3f204a5d06580728 (diff) |
Upgrade existing permissions when changing owner of repository
This resolves issue #144.
-rw-r--r-- | app/models/repository.rb | 5 | ||||
-rw-r--r-- | test/unit/repository_test.rb | 9 |
2 files changed, 13 insertions, 1 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index f4eae10..4c0f987 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -369,7 +369,10 @@ class Repository < ActiveRecord::Base self.kind = KIND_USER_REPO end end - unless committerships.any?{|c|c.committer == another_owner} + if cs_to_upgrade = committerships.detect{|c|c.committer == another_owner} + cs_to_upgrade.build_permissions(:review, :commit, :admin) + cs_to_upgrade.save! + else committerships.create_for_owner!(self.owner) end save! diff --git a/test/unit/repository_test.rb b/test/unit/repository_test.rb index 3fe02c2..b448849 100644 --- a/test/unit/repository_test.rb +++ b/test/unit/repository_test.rb @@ -706,6 +706,15 @@ class RepositoryTest < ActiveSupport::TestCase end end + should "upgrade the permissions for the new owner when it already has access" do + new_owner = groups(:team_thunderbird) + repo = repositories(:johans) + committership = repo.committerships.create_with_permissions!({:committer => new_owner}, Committership::CAN_COMMIT) + + repo.change_owner_to!(new_owner) + assert committership.reload.admin? + end + should "downcases the name before validation" do repo = new_repos(:name => "FOOBAR") repo.save! |