Module: Cassette::Rubycas::Helper

Extended by:
ActiveSupport::Concern
Includes:
UserFactory
Defined in:
lib/cassette/rubycas/helper.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from UserFactory

#from_session

Instance Method Details

#cas_logout(to = root_url) ⇒ Object


37
38
39
40
# File 'lib/cassette/rubycas/helper.rb', line 37

def cas_logout(to = root_url)
  session.destroy
  ::CASClient::Frameworks::Rails::Filter.logout(self, to)
end

#current_userObject


60
61
62
63
64
65
# File 'lib/cassette/rubycas/helper.rb', line 60

def current_user
  return fake_user if ENV['NOAUTH']
  return nil unless session[:cas_user]

  @current_user ||= from_session(session)
end

#customer_only_filterObject


32
33
34
35
# File 'lib/cassette/rubycas/helper.rb', line 32

def customer_only_filter
  return if ENV['NOAUTH'] || current_user.blank?
  fail Cassette::Errors::NotACustomer unless current_user.customer?
end

#employee_only_filterObject


27
28
29
30
# File 'lib/cassette/rubycas/helper.rb', line 27

def employee_only_filter
  return if ENV['NOAUTH'] || current_user.blank?
  fail Cassette::Errors::NotAnEmployee unless current_user.employee?
end

#fake_userObject


42
43
44
45
46
47
48
# File 'lib/cassette/rubycas/helper.rb', line 42

def fake_user
  Cassette::Authentication::User.new(login: 'fake.user',
                                     name: 'Fake User',
                                     email: '[email protected]',
                                     authorities: [],
                                     type: 'customer')
end

#validate_authentication_ticketObject


22
23
24
25
# File 'lib/cassette/rubycas/helper.rb', line 22

def validate_authentication_ticket
  return if ENV['NOAUTH']
  ::CASClient::Frameworks::Rails::Filter.filter(self)
end

#validate_raw_role!(role) ⇒ Object


55
56
57
58
# File 'lib/cassette/rubycas/helper.rb', line 55

def validate_raw_role!(role)
  return if ENV['NOAUTH']
  fail Cassette::Errors::Forbidden unless current_user.has_raw_role?(role)
end

#validate_role!(role) ⇒ Object


50
51
52
53
# File 'lib/cassette/rubycas/helper.rb', line 50

def validate_role!(role)
  return if ENV['NOAUTH']
  fail Cassette::Errors::Forbidden unless current_user.has_role?(role)
end