Sha256: 875f8b080866ba86b97e11a0ee7c5b5a36a1e3a1060f8811e1c9f7a16a6bc8f0

Contents?: true

Size: 1.78 KB

Versions: 51

Compression:

Stored size: 1.78 KB

Contents

module CanvasSync::Concerns
  module Role
    module Base
      extend ActiveSupport::Concern

      DEFAULT_ROLE_LABELS = %w[TeacherEnrollment TaEnrollment StudentEnrollment DesignerEnrollment ObserverEnrollment].freeze

      CanvasSync::Record.define_feature self, default: true

      class_methods do
        def for_labels(labels, account)
          built_ins = []
          labels = labels.split(',') if labels.is_a?(String)
          custom_labels = Array(labels).reject do |l|
            if DEFAULT_ROLE_LABELS.include?(l)
              built_ins << l
            elsif l == 'Account Admin' || l == 'AccountAdmin'
              built_ins << 'AccountMembership'
            else
              next
            end
            true
          end

          account_ids = Rails.cache.fetch([self.class.name, "AccountAncestry", account.canvas_id], expires_in: 6.hours) do
            if account.respond_to?(:path_ids)
              account.path.pluck(:canvas_id)
            else
              [].tap do |pids|
                acc = account
                loop do
                  break unless acc
                  pids.unshift(acc.canvas_id)
                  acc = acc.canvas_parent
                end
              end
            end
          end

          where(workflow_state: 'built_in', base_role_type: built_ins)
            .or(where.not(workflow_state: 'built_in').where(label: custom_labels, canvas_account_id: account_ids))
        end

        def joined_permissions(roles)
          final = {}
          roles.each do |role|
            role.permissions.each do |perm_name, perm|
              final[perm_name] = false if final[perm_name].nil?
              final[perm_name] = true if perm['enabled'] == true
            end
          end
          final
        end
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
canvas_sync-0.22.6 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.22.5 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.22.4 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.22.3 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.22.2 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.22.1 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.22.0 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.22.0.beta8 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.22.0.beta7 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.22.0.beta6 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.22.0.beta5 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.22.0.beta4 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.22.0.beta3 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.22.0.beta2 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.22.0.beta1 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.21.1 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.21.1.beta1 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.21.0 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.21.0.beta5 lib/canvas_sync/concerns/role/base.rb
canvas_sync-0.21.0.beta4 lib/canvas_sync/concerns/role/base.rb