Sha256: 0326d88b893f037d4293467ee01e5ca128b2ffc6d95325fbc6d2bef39e7d7251

Contents?: true

Size: 753 Bytes

Versions: 9

Compression:

Stored size: 753 Bytes

Contents

module Ddr
  module Auth
    module LegacyRoles
      extend ActiveSupport::Concern

      LEGACY_ROLES = [:administrator, :editor, :downloader, :contributor]

      def legacy_downloader_to_resource_roles
        principals(:downloader).map do |name|
          agent_type = (name =~ /@/ ? :person : :group)
          Roles::Role.build(:type=>:downloader, agent_type=>name, :scope=>:resource)
        end
      end

      def principal_has_role?(principal, role)
        ( principals(role) & Array(principal) ).any?
      end

      def principals(role)
        if LEGACY_ROLES.include?(role)
          adminMetadata.send(role)
        else
          raise ArgumentError, "#{role.inspect} is not a legacy role."
        end
      end

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ddr-models-1.17.1 lib/ddr/auth/legacy_roles.rb
ddr-models-1.17.0 lib/ddr/auth/legacy_roles.rb
ddr-models-1.16.2 lib/ddr/auth/legacy_roles.rb
ddr-models-1.16.1 lib/ddr/auth/legacy_roles.rb
ddr-models-1.16.0 lib/ddr/auth/legacy_roles.rb
ddr-models-1.15.0 lib/ddr/auth/legacy_roles.rb
ddr-models-1.14.2 lib/ddr/auth/legacy_roles.rb
ddr-models-1.14.1 lib/ddr/auth/legacy_roles.rb
ddr-models-1.14.0 lib/ddr/auth/legacy_roles.rb