Module: Card::Auth::Proxy
- Included in:
- Card::Auth
- Defined in:
- card/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.
-
#with(auth_data) ⇒ Object
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 24 |
# File 'card/lib/card/auth/proxy.rb', line 6 def as given_user tmp_id = @as_id tmp_card = @as_card @as_id = Card.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)
27 28 29 |
# File 'card/lib/card/auth/proxy.rb', line 27 def as_bot &block as Card::WagnBotID, &block end |
#as_card ⇒ Card
proxy user card
39 40 41 42 43 |
# File 'card/lib/card/auth/proxy.rb', line 39 def as_card return @as_card if @as_card&.id == as_id @as_card = Card[as_id] end |
#as_id ⇒ Integer
id of proxy user
33 34 35 |
# File 'card/lib/card/auth/proxy.rb', line 33 def as_id @as_id || current_id end |
#with(auth_data) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'card/lib/card/auth/proxy.rb', line 48 def with auth_data if auth_data.is_a?(Integer) || auth_data.is_a?(String) auth_data = { current_id: Card.id(auth_data) } end temporarily do # resets @as and @as_card self.current_id = auth_data[:current_id] @as_id = auth_data[:as_id] if auth_data[:as_id] yield end end |