Sha256: ccd1f1906991479053d3cfe9c707f4a0057bcbe47a1cf392194279a0d4b9974a

Contents?: true

Size: 1.84 KB

Versions: 6

Compression:

Stored size: 1.84 KB

Contents

#module EnjuSubject
  class Ability
    include CanCan::Ability
        
    def initialize(user, ip_address = '0.0.0.0')
      case user.try(:role).try(:name)
      when 'Administrator'
        can :manage, [
          Classification,
          Subject,
          SubjectHasClassification,
          SubjectHeadingTypeHasSubject
        ]
        can :manage, WorkHasSubject
        if LibraryGroup.site_config.network_access_allowed?(ip_address)
          can [:read, :create, :update], ClassificationType
          can [:destroy, :delete], ClassificationType do |classification_type|
            classification_type.classifications.empty?
          end
          can :manage, [
            Classification,
            Subject,
            SubjectHasClassification,
            SubjectHeadingType,
            SubjectType
          ]
        else
          can :read, [
            ClassificationType,
            SubjectHeadingType,
            SubjectType
          ]
        end
        can :read, Manifestation
      when 'Librarian'
        can :manage, [
          SubjectHasClassification,
          WorkHasSubject
        ]
        can :read, [
          Classification,
          ClassificationType,
          Subject,
          SubjectType,
          SubjectHeadingType,
          SubjectHeadingTypeHasSubject
        ]
        can :read, Manifestation
      when 'User'
        can :read, [
          Classification,
          ClassificationType,
          Subject,
          SubjectHasClassification,
          SubjectHeadingType,
          WorkHasSubject
        ]
        can :read, Manifestation
      else
        can :read, [
          Classification,
          ClassificationType,
          Subject,
          SubjectHasClassification,
          SubjectHeadingType,
          WorkHasSubject
        ]
        can :read, Manifestation
      end
    end
  end
#end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
enju_subject-0.1.0.pre12 spec/dummy/app/models/ability.rb
enju_subject-0.1.0.pre11 spec/dummy/app/models/ability.rb
enju_subject-0.1.0.pre10 spec/dummy/app/models/ability.rb
enju_subject-0.1.0.pre9 spec/dummy/app/models/ability.rb
enju_subject-0.1.0.pre8 spec/dummy/app/models/ability.rb
enju_subject-0.1.0.pre7 spec/dummy/app/models/ability.rb