I tried your function with the tweaks you suggested, but I'm still getting 
an error:

>>  change_project_owner('foo-project', 'username')
TypeError: wrong argument type nil (expected Module)
    from /var/www/gitorious/lib/gitorious/search.rb:41:in `extend'
    from /var/www/gitorious/lib/gitorious/search.rb:41:in `included'
    from /var/www/gitorious/app/models/repository.rb:32:in `include'
    from /var/www/gitorious/app/models/repository.rb:32
    from 
/var/www/gitorious/vendor/rails/activesupport/lib/active_support/dependencies.rb:158:in
 
`require'
    from 
/var/www/gitorious/vendor/rails/activesupport/lib/active_support/dependencies.rb:158:in
 
`require'
    from 
/var/www/gitorious/vendor/rails/activesupport/lib/active_support/dependencies.rb:265:in
 
`require_or_load'
    from 
/var/www/gitorious/vendor/rails/activesupport/lib/active_support/dependencies.rb:425:in
 
`load_missing_constant'
    from 
/var/www/gitorious/vendor/rails/activesupport/lib/active_support/dependencies.rb:80:in
 
`const_missing'
    from 
/var/www/gitorious/vendor/rails/activesupport/lib/active_support/dependencies.rb:92:in
 
`const_missing'
    from 
/var/www/gitorious/vendor/rails/activesupport/lib/active_support/dependencies.rb:437:in
 
`load_missing_constant'
    from 
/var/www/gitorious/vendor/rails/activesupport/lib/active_support/dependencies.rb:96:in
 
`const_missing'
    from /var/www/gitorious/app/models/user.rb:33
    from 
/var/www/gitorious/vendor/rails/activesupport/lib/active_support/dependencies.rb:158:in
 
`require'
    from 
/var/www/gitorious/vendor/rails/activesupport/lib/active_support/dependencies.rb:158:in
 
`require'
    from 
/var/www/gitorious/vendor/rails/activesupport/lib/active_support/dependencies.rb:265:in
 
`require_or_load'
    from 
/var/www/gitorious/vendor/rails/activesupport/lib/active_support/dependencies.rb:425:in
 
`load_missing_constant'
    from 
/var/www/gitorious/vendor/rails/activesupport/lib/active_support/dependencies.rb:80:in
 
`const_missing'
    from 
/var/www/gitorious/vendor/rails/activesupport/lib/active_support/dependencies.rb:92:in
 
`const_missing'
    from (irb):39:in `change_project_owner'
    from (irb):72>> 

I'm wondering if there is something wrong with my environment which causes 
my console not to properly load up all of the functionality of the models. 
I'm not very familiar with how ruby works.

--
Allan

On Friday, October 5, 2012 3:17:17 AM UTC-7, Peter Kjellerstedt wrote:
>
> I use the following function to change the ownership of a project to 
> another user:
>
>  
>
> def change_project_owner(project, owner, keep_old = true)
>
>   p = Project.find_by_title(project)
>
>   u = User.find_by_login(owner)
>
>   old_owner = p.owner
>
>  
>
>   return if u == old_owner
>
>  
>
>   p.repositories.mainlines.each do |r|
>
>     cs = r.committerships.find_by_committer_id_and_committer_type(u.id, 
> "User")
>
>     if cs
>
>       cs.destroy
>
>     end
>
>   end
>
>   p.change_owner_to(u).each do |r|
>
>     r.change_owner_to!(u)
>
>     r.user_id = u.id
>
>     r.save!
>
>     r.committerships.find_all_by_committer_type("User").each do |cs|
>
>       if cs.committer_id == u.id
>
>         cs.creator_id = nil
>
>         cs.save!
>
>       elsif cs.creator_id == old_owner.id
>
>         cs.creator_id = u.id
>
>         cs.save!
>
>       end
>
>     end
>
>     if keep_old
>
>       cs = r.committerships.create!(:committer => old_owner, :creator_id 
> => u.id)
>
>       cs.build_permissions(:review, :commit, :admin)
>
>       cs.save!
>
>     end
>
>   end
>
>   p.save!
>
> end
>
>  
>
> Note that I use Project.find_by_title() which you can easily change to 
> Project.find_by_slug(). I also do not know what will happen if there are 
> group committerships involved (we do not use groups). Set keep_old to true 
> if you want the old owner to retain his/her committerships after the owner 
> change.
>
>  
>
> //Peter
>
>  
>
> *From:* [email protected] <javascript:> [mailto:
> [email protected] <javascript:>] *On Behalf Of *Allan Caffee
> *Sent:* den 5 oktober 2012 02:15
> *To:* [email protected] <javascript:>
> *Subject:* [gitorious] Transferring ownership of a project and repository
>
>  
>
> I'm trying to transfer the ownership of a project and repository belonging 
> to someone whose account has been disabled. Since the account is disabled 
> I'm trying to use the ruby console to transfer ownership, but I'm getting a 
> NoMethodError using the methods defined on these models. I'm new to 
> ruby/rails so it's possible I'm overlooking something fairly obvious, but 
> here's what I'm doing:
>
> % env RAILS_ENV=production ruby script/console
> >> user = User.find_by_login('username')
> => #<User id: 23, ...>
> >> proj = Project.find_by_slug('foo-project)
> => #<Project id: 121, ...>
> >> proj.change_owner_to user
> NoMethodError: undefined method `change_owner_to' for 
> #<Project:0x7f8ad0202da0>
>     from 
> /var/www/gitorious/vendor/rails/activerecord/lib/active_record/attribute_methods.rb:260:in
>  
> `method_missing'
>     from (irb):32
>
>
> What am I missing here? Is there a better way to do this? I'm using 
> gitorious v2.1.1.
>
> Thanks,
> Allan
>
> -- 
> To post to this group, send email to [email protected]<javascript:>
> To unsubscribe from this group, send email to
> [email protected] <javascript:>
>

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]

Reply via email to