Created
June 27, 2011 21:47
-
-
Save m3talsmith/1049927 to your computer and use it in GitHub Desktop.
is admin through memberships
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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