Sha256: eb697185f09ddfdcff25a9ea82aefcb2e3f8e8bf7815427765d409ecea6855c3

Contents?: true

Size: 888 Bytes

Versions: 14

Compression:

Stored size: 888 Bytes

Contents

class UserMembership < ActiveRecord::Base
  # Be careful here!  :user needs to come out of this if we ever support update action on memberships controller
  attr_accessible :user, :organization_attributes

  belongs_to :user
  belongs_to :organization

  accepts_nested_attributes_for :organization

  validates :user_id, :uniqueness => {:scope => :organization_id}

  #
  # Will promote new_owner to admin and demote any other owners
  #
  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
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
artfully_ose-1.2.0 app/models/user_membership.rb
artfully_ose-1.2.0.beta.1 app/models/user_membership.rb
artfully_ose-1.2.0.alpha.2 app/models/user_membership.rb
artfully_ose-1.2.0.alpha.1 app/models/user_membership.rb
artfully_ose-1.2.0.pre.27 app/models/user_membership.rb
artfully_ose-1.2.0.pre.26 app/models/user_membership.rb
artfully_ose-1.2.0.pre.24 app/models/user_membership.rb
artfully_ose-1.2.0.pre.23 app/models/user_membership.rb
artfully_ose-1.2.0.pre.21 app/models/user_membership.rb
artfully_ose-1.2.0.pre.20 app/models/user_membership.rb
artfully_ose-1.2.0.pre.19 app/models/user_membership.rb
artfully_ose-1.2.0.pre.18 app/models/user_membership.rb
artfully_ose-1.2.0.pre.17 app/models/user_membership.rb
artfully_ose-1.2.0.pre.16 app/models/user_membership.rb