Module: CanvasSync::Concerns::AbilityHelper

Extended by:
ActiveSupport::Concern
Includes:
PandaPal::Concerns::AbilityHelper
Defined in:
lib/canvas_sync/concerns/ability_helper.rb

Instance Method Summary collapse

Instance Method Details

#canvas_account_rolesObject



54
55
56
# File 'lib/canvas_sync/concerns/ability_helper.rb', line 54

def 
  canvas_roles.where(base_role_type: 'AccountMembership')
end

#canvas_course_rolesObject



58
59
60
# File 'lib/canvas_sync/concerns/ability_helper.rb', line 58

def canvas_course_roles
  canvas_roles.where.not(base_role_type: 'AccountMembership')
end

#canvas_permissionsObject

CanvasSync Domain



41
42
43
# File 'lib/canvas_sync/concerns/ability_helper.rb', line 41

def canvas_permissions
  panda_pal_session[:canvas_permissions] ||= ::Role.joined_permissions(canvas_roles)
end

#canvas_rolesObject



45
46
47
# File 'lib/canvas_sync/concerns/ability_helper.rb', line 45

def canvas_roles
  @canvas_roles ||= Role.for_labels(panda_pal_session.canvas_role_labels, )
end

#canvas_root_account_rolesObject



49
50
51
52
# File 'lib/canvas_sync/concerns/ability_helper.rb', line 49

def 
  role_labels = panda_pal_session.('self')
  ::Role.for_labels(role_labels, ::Account.find_by(canvas_parent_account_id: nil))
end

#canvas_super_user?Boolean

Returns:

  • (Boolean)


62
63
64
65
66
# File 'lib/canvas_sync/concerns/ability_helper.rb', line 62

def canvas_super_user?
  panda_pal_session.cache(:canvas_super_user?) do
    panda_pal_session.canvas_site_admin? || (panda_pal_session.(:root) & ["AccountAdmin", "Account Admin"]).present?
  end
end

#canvas_user_idObject



68
69
70
# File 'lib/canvas_sync/concerns/ability_helper.rb', line 68

def canvas_user_id
  user&.canvas_id || panda_pal_session.get_lti_cust_param('canvas_user_id')
end

#launch_accountObject



33
34
35
36
37
# File 'lib/canvas_sync/concerns/ability_helper.rb', line 33

def 
  @launch_account ||= launch_context.respond_to?(:account) ?
                        launch_context. :
                        ::Account.find_by(canvas_id: panda_pal_session.get_lti_cust_param('custom_canvas_account_id'))
end

#launch_contextObject

Middle Domain



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/canvas_sync/concerns/ability_helper.rb', line 21

def launch_context
  @launch_context ||= begin
    if panda_pal_session.lti_launch_placement == "global_navigation"
      :global
    elsif panda_pal_session.get_lti_cust_param('custom_canvas_course_id').present?
      ::Course.find_by(canvas_id: panda_pal_session.get_lti_cust_param('custom_canvas_course_id'))
    else
      ::Account.find_by(canvas_id: panda_pal_session.get_lti_cust_param('custom_canvas_account_id'))
    end
  end
end

#panda_pal_sessionObject



14
15
16
# File 'lib/canvas_sync/concerns/ability_helper.rb', line 14

def panda_pal_session
  raise "This feature was moved to PandaPal as of CanvasSync 0.20.0/PandaPal 5.9.9. You should update to PandaPal >= 5.9.9."
end