Skip to content

Instantly share code, notes, and snippets.

@m3talsmith
Created June 27, 2011 21:47
Show Gist options
  • Save m3talsmith/1049927 to your computer and use it in GitHub Desktop.
Save m3talsmith/1049927 to your computer and use it in GitHub Desktop.
is admin through memberships
class Member
# ...
class << self
# ...
def is_admin?(organization, user)
member = first(:conditions => {:organization_id => organization.id, :user_id => user.id})
return false unless member
return member.role == 'admin'
end
# ...
end
# ...
end
class Organization
# ...
def user_is_admin?(user)
Member.is_admin?(self, user)
end
# ...
end
class User
# ...
def is_admin_of_organization?(organization)
Member.is_admin?(organization, self)
end
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment