module Card::Auth::Proxy
mechanism for assuming permissions of another user.
Public Instance Methods
Source
# File 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
operate with the permissions of another “proxy” user
Source
# File lib/card/auth/proxy.rb, line 27 def as_bot &block as Card::WagnBotID, &block end
operate with the permissions of WagnBot (administrator)
Source
# File 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
proxy user card @return [Card]
Source
# File lib/card/auth/proxy.rb, line 33 def as_id @as_id || current_id end
id of proxy user @return [Integer]
Source
# File 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
@param auth_data [Integer|Hash] user id, user name, or a hash @option auth_data [Integer] current_id @option auth_data [Integer] as_id
Private Instance Methods
Source
# File lib/card/auth/proxy.rb, line 63 def temporarily tmp_current_id = current_id tmp_as_id = as_id tmp_current_card = @current_card tmp_as_card = @as_card tmp_current_roles = @current_roles yield ensure @current_id = tmp_current_id @as_id = tmp_as_id @current = tmp_current_card @as_card = tmp_as_card @current_roles = tmp_current_roles end