Module: Card::Auth::Proxy
- Included in:
- Card::Auth
- Defined in:
- lib/card/auth/proxy.rb
Overview
mechanism for assuming permissions of another user.
Instance Method Summary collapse
-
#as(given_user) ⇒ Object
operate with the permissions of another "proxy" user.
-
#as_bot(&block) ⇒ Object
operate with the permissions of WagnBot (administrator).
-
#as_card ⇒ Card
proxy user card.
-
#as_id ⇒ Integer
id of proxy user.
-
#get_user_id(user) ⇒ Object
get card id from args of unknown type.
Instance Method Details
#as(given_user) ⇒ Object
operate with the permissions of another "proxy" user
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/card/auth/proxy.rb', line 6 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 |
#as_bot(&block) ⇒ Object
operate with the permissions of WagnBot (administrator)
26 27 28 |
# File 'lib/card/auth/proxy.rb', line 26 def as_bot &block as Card::WagnBotID, &block end |
#as_card ⇒ Card
proxy user card
38 39 40 41 42 43 44 |
# File 'lib/card/auth/proxy.rb', line 38 def as_card if @as_card && @as_card.id == as_id @as_card else @as_card = Card[as_id] end end |
#as_id ⇒ Integer
id of proxy user
32 33 34 |
# File 'lib/card/auth/proxy.rb', line 32 def as_id @as_id || current_id end |
#get_user_id(user) ⇒ Object
TODO:
replace with general mechanism, eg #quick_fetch
get card id from args of unknown type
48 49 50 51 52 53 54 55 |
# File 'lib/card/auth/proxy.rb', line 48 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 |