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
- #canvas_account_roles ⇒ Object
- #canvas_course_roles ⇒ Object
-
#canvas_permissions ⇒ Object
CanvasSync Domain.
- #canvas_roles ⇒ Object
- #canvas_root_account_roles ⇒ Object
- #canvas_super_user? ⇒ Boolean
- #canvas_user_id ⇒ Object
- #launch_account ⇒ Object
-
#launch_context ⇒ Object
Middle Domain.
- #panda_pal_session ⇒ Object
Instance Method Details
#canvas_account_roles ⇒ Object
54 55 56 |
# File 'lib/canvas_sync/concerns/ability_helper.rb', line 54 def canvas_account_roles canvas_roles.where(base_role_type: 'AccountMembership') end |
#canvas_course_roles ⇒ Object
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_permissions ⇒ Object
CanvasSync Domain
41 42 43 |
# File 'lib/canvas_sync/concerns/ability_helper.rb', line 41 def panda_pal_session[:canvas_permissions] ||= ::Role.(canvas_roles) end |
#canvas_roles ⇒ Object
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, launch_account) end |
#canvas_root_account_roles ⇒ Object
49 50 51 52 |
# File 'lib/canvas_sync/concerns/ability_helper.rb', line 49 def canvas_root_account_roles role_labels = panda_pal_session.canvas_account_role_labels('self') ::Role.for_labels(role_labels, ::Account.find_by(canvas_parent_account_id: nil)) end |
#canvas_super_user? ⇒ 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.canvas_account_role_labels(:root) & ["AccountAdmin", "Account Admin"]).present? end end |
#canvas_user_id ⇒ Object
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_account ⇒ Object
33 34 35 36 37 |
# File 'lib/canvas_sync/concerns/ability_helper.rb', line 33 def launch_account @launch_account ||= launch_context.respond_to?(:account) ? launch_context.account : ::Account.find_by(canvas_id: panda_pal_session.get_lti_cust_param('custom_canvas_account_id')) end |
#launch_context ⇒ Object
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_session ⇒ Object
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 |