Class: UserMembership

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/user_membership.rb

Class Method Summary collapse

Class Method Details

.promote(new_owner, organization) ⇒ Object

Will promote new_owner to admin and demote any other owners



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/models/user_membership.rb', line 15

def self.promote(new_owner, organization)

  @user_membership = UserMembership.where(:user_id => new_owner.id, :organization_id => organization.id).first

  return false if @user_membership.nil?

  @user_membership.transaction do
    UserMembership.where(:organization_id => organization.id).update_all(:owner => false)
    @user_membership.reload
    @user_membership.owner  = true
    return @user_membership.save
  end
end