This file contains 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 Gatekeeper | |
def self.has_access?(user: user, context: context) | |
perms_1 = self.find_by_sql(" | |
select p.* | |
from user_permissions p | |
where p.context_id = #{context} | |
and p.user_id = #{user.id} | |
union | |
select p.* | |
from group_permissions g |
This file contains 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 Gatekeeper | |
attr_accessor :user, :contexts | |
def initialize(user, contexts) | |
self.user = user | |
self.contexts = Array.wrap(contexts) | |
end | |
def self.access?(user: user, contexts: contexts) | |
new(user, contexts).access? |
This file contains 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 Array | |
def each | |
for i in 0...length | |
yield(self.[](i)) | |
end | |
self | |
end | |
def map | |
ar = [] |