Sha256: f9474d59ba58867d6f6ab6fa8b4b50693aecf069ae9e5d6d3c12da862783de9d

Contents?: true

Size: 805 Bytes

Versions: 10

Compression:

Stored size: 805 Bytes

Contents

module Ddr
  module Auth
    class LegacyPermissions

      attr_reader :permissions

      LEGACY_PERMISSION_ROLE_MAP = {
        "discover" => "Viewer",
        "read" => "Viewer",
        "edit" => "Editor"
      }

      def initialize(permissions)
        @permissions = permissions
      end

      def to_resource_roles
        to_roles(:resource)
      end

      def to_policy_roles
        to_roles(:policy)
      end

      def to_roles(scope)
        permissions.map do |perm|
          Roles::Role.build(type: role_type(perm), agent: perm[:name], scope: scope)
        end
      end

      private

      def role_type(perm)
        LEGACY_PERMISSION_ROLE_MAP[perm[:access]]
      end

      def agent_type(perm)
        perm[:type] == "group" ? :group : :person
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

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