Sha256: 21f5e4252d9a6947fe0638b4804d25f7ce4d030601cd81b1722932b71baa1596

Contents?: true

Size: 1.59 KB

Versions: 8

Compression:

Stored size: 1.59 KB

Contents

require_relative 'workspace'

module Hippo

    module Access

        class << self

            def type_to_client(klass)
                klass.to_s.sub(/^(\w+).*?(\w+)$/,'\1.Models.\2')
            end

            def type_to_client_id(klass)
                ( klass.is_a?(Class) ? klass : klass.class ).to_s.demodulize.underscore
            end

            def for_user( user )
                {
                    :roles => user.roles.map{ | role |
                        {
                            type: type_to_client_id(role),
                            read: role.read_types.map{ |klass| type_to_client(klass) },
                            write: role.write_types.map{ |klass| type_to_client(klass) },
                            delete: role.delete_types.map{ |klass| type_to_client(klass) }
                        }
                    },
                    :locked_fields => LockedFields.definitions.map{ | klass, locks |
                        {
                            type: type_to_client(klass),
                            locks: locks.each_with_object({}) do |(field, grants), result|
                                result[field] = grants.map do |grant|
                                    { role: type_to_client_id(grant[:role]), only: grant[:only] }
                                end
                            end
                        }
                    }
                }
            end

        end
    end

end

require_relative 'access/locked_fields'
require_relative 'access/role'
require_relative 'access/role_collection'
require_relative 'access/track_modifications'

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hippo-fw-0.9.9 lib/hippo/access.rb
hippo-fw-0.9.8 lib/hippo/access.rb
hippo-fw-0.9.7 lib/hippo/access.rb
hippo-fw-0.9.6 lib/hippo/access.rb
hippo-fw-0.9.5 lib/hippo/access.rb
hippo-fw-0.9.4 lib/hippo/access.rb
hippo-fw-0.9.3 lib/hippo/access.rb
hippo-fw-0.9.2 lib/hippo/access.rb