Module: DRCClient::HelperMethods

Defined in:
lib/drc_client.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



56
57
58
59
60
# File 'lib/drc_client.rb', line 56

def self.included(base)
  base.send :helper_method, :logged_in_drc?, :cas_is_pama_allowed?, :current_drc_user,
            :drc_user_has_local_user?, :login_with_drc, :drc_logout_url, :drc_login_url,
            :drc_top_bar, :clear_local_drc_session
end

Instance Method Details

#allowed_drc_user?Boolean

checks if DRC credentials have access to local application

Returns:

  • (Boolean)


76
77
78
79
80
81
82
# File 'lib/drc_client.rb', line 76

def allowed_drc_user?
  return false if !logged_in_drc?
  allowed = true # by default having a drc_user is enough
  allowed &&= drc_user_has_local_user? if DRCClient.config[:require_local_user]
  allowed &&= true if DRCClient.config[:require_access_level] # TODO
  return allowed
end

#clear_local_drc_sessionObject



66
67
68
# File 'lib/drc_client.rb', line 66

def clear_local_drc_session
  session[:cas_user] = nil
end

#current_drc_userObject



62
63
64
# File 'lib/drc_client.rb', line 62

def current_drc_user
  return session[:cas_user]
end

#drc_login_urlObject

returns login url to DRC server.



105
106
107
# File 'lib/drc_client.rb', line 105

def 
  return CASClient::Frameworks::Rails::Filter.(self)
end

#drc_logout_urlObject



109
110
111
# File 'lib/drc_client.rb', line 109

def drc_logout_url
  return DRCClient.config[:base_url]+"/logout" # TODO strip posible / at end of base_url
end

#drc_top_bar(local_logout_url = nil) ⇒ Object

helper for rendering top_bar



114
115
116
117
118
119
120
121
122
# File 'lib/drc_client.rb', line 114

def drc_top_bar(local_logout_url=nil)
  logout_href = (local_logout_url.nil?)? drc_logout_url : local_logout_url
  ret = "<div style='width: 100%; height: 12px; top: 0; border-bottom: 1px solid grey; margin-bottom: 5px; padding-bottom: 5px; vertical-align: middle; font-size: 12px;'>"
  ret << "<div style='text-align: left; float: left;'>DRC-Bar. (TODO: list available apps here)</div>"
  ret << "<div style='text-align: right; float: right;'><strong>#{current_drc_user}</strong> | "
  ret << "<a href='#{logout_href}'>#{I18n.t('logout', :default => "logout").capitalize}</a></div>"
  ret << "</div>"
  return ret
end

#drc_user_has_local_user?Boolean

checks if drc_user matches any local application user.

Returns:

  • (Boolean)


100
101
102
# File 'lib/drc_client.rb', line 100

def drc_user_has_local_user?
  return !get_local_user_id.nil?
end

#get_local_user_idObject

finds local user that matches logged in DRC user return user’s id or nil if none found



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/drc_client.rb', line 86

def get_local_user_id
  return nil if DRCClient.config[:user_model].nil?
  return nil unless logged_in_drc?
  user = DRCClient.config[:user_model].find(:first,
                                          :select => DRCClient.config[:local_user_id_column],
                                          :conditions => { DRCClient.config[:drc_user_column] => current_drc_user})
  if user
    return user[DRCClient.config[:local_user_id_column].to_sym]
  else
    return nil
  end
end

#logged_in_drc?Boolean

check if session has DRC credentials

Returns:

  • (Boolean)


71
72
73
# File 'lib/drc_client.rb', line 71

def logged_in_drc?
  return !current_drc_user.blank?
end