Sha256: 4d2e1e0f00018074207a4d2f0e1d7a10b846dc5cd8f7447fcb9f7cdb931aa620
Contents?: true
Size: 1.32 KB
Versions: 11
Compression:
Stored size: 1.32 KB
Contents
class Card module Auth # mechanism for assuming permissions of another user. module Proxy # operate with the permissions of another "proxy" user def as given_user tmp_id = @as_id tmp_card = @as_card @as_id = get_user_id(given_user) @as_card = nil # we could go ahead and set as_card if given a card... @current_id = @as_id if @current_id.nil? return unless block_given? yield ensure if block_given? @as_id = tmp_id @as_card = tmp_card end end # operate with the permissions of WagnBot (administrator) def as_bot &block as Card::WagnBotID, &block end # id of proxy user # @return [Integer] def as_id @as_id || current_id end # proxy user card # @return [Card] def as_card if @as_card && @as_card.id == as_id @as_card else @as_card = Card[as_id] end end # get card id from args of unknown type # @todo replace with general mechanism, eg #quick_fetch def get_user_id user case user when NilClass then nil when Card then user.id when Fixnum then user else Card.fetch_id(user) end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems