Module: Dokno::UserConcern

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController
Defined in:
app/controllers/dokno/user_concern.rb

Instance Method Summary collapse

Instance Method Details

#authorizeObject



36
37
38
# File 'app/controllers/dokno/user_concern.rb', line 36

def authorize
  return redirect_to root_path unless can_edit?
end

#can_edit?Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'app/controllers/dokno/user_concern.rb', line 28

def can_edit?
  # Allow editing by default if host app user object is not configured
  return true  unless sanitized_user_obj_string.present?
  return false unless user&.respond_to? Dokno.config.app_user_auth_method.to_sym

  user.send(Dokno.config.app_user_auth_method.to_sym)
end

#sanitized_user_obj_stringObject



20
21
22
# File 'app/controllers/dokno/user_concern.rb', line 20

def sanitized_user_obj_string
  Dokno.config.app_user_object.to_s.split(/\b/).first
end

#userObject



9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/dokno/user_concern.rb', line 9

def user
  # Attempt to eval the currently signed in 'user' object from the host app
  proc {
    $safe = 1
    eval sanitized_user_obj_string
  }.call

rescue NameError => _e
  nil
end

#usernameObject



24
25
26
# File 'app/controllers/dokno/user_concern.rb', line 24

def username
  user&.send(Dokno.config.app_user_name_method.to_sym).to_s
end