Module: Scat::Authorization

Includes:
Sinatra::Authorization
Defined in:
lib/scat/authorization.rb

Instance Method Summary collapse

Instance Method Details

#authorization_realmObject

Fix Sinatra::Authorization.authorization_realm per the (github.com/sr/sinatra-authorization)[https://github.com/sr/sinatra-authorization] patch.



38
39
40
# File 'lib/scat/authorization.rb', line 38

def authorization_realm
  settings.authorization_realm
end

#current_userCaTissue::User

Returns the user who is submitting this edit.

Returns:

  • (CaTissue::User)

    the user who is submitting this edit

Raises:

  • (ArgumentError)

    if there is no such caTissue user



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/scat/authorization.rb', line 17

def current_user
  # The caTissue login name is the user's email address.
  email = session[:email]
  raise ScatError.new("The caTissue login is not available in this web session.") unless email
  # the current caTissue User
  user = CaTissue::User.new(:email_address => email)
  # the cached caTissue User id
  user_id = session[:user_id]
  if user_id then
    user.identifier = user_id
  else
    # Fetch the User and cache the id.
    raise ScatError.new("User not found: #{user.email_address}") unless user.find
    session[:user_id] = user.identifier
  end
  user
end

#protect! { ... } ⇒ Object

Runs the given block in an HTTP basic authorization context. The session status is set to the result of performing the given block.

Yields:

  • perform the caTissue operation and return a status message



10
11
12
13
# File 'lib/scat/authorization.rb', line 10

def protect!(&block)
  
  session[:status] = perform!(session[:email], session[:password], &block)
end