Sha256: 38bef944a3858ec17fdabc012c3c6b0ca66b09b1a1401f03fe90cfbf755e17f4

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 KB

Contents

module Reactor
  module Cm
    module Permissions
      def self.included(base)
        base.instance_eval do
          attribute :global_permissions, name: :globalPermissions, type: :list
        end
      end

      # Returns true, if a global permission with the given +name+ exists, false otherwise.
      def global_permission?(name)
        global_permissions.include?(name.to_s)
      end

      # Add the given +permissions+ to the current set of group permissions.
      def grant_global_permissions!(permissions)
        permissions = permissions.is_a?(Array) ? permissions : [permissions]
        permissions = global_permissions | permissions

        set_global_permissions!(permissions)
      end

      # Take away the given +permissions+ from the current set of group permissions.
      def revoke_global_permissions!(permissions)
        permissions = permissions.is_a?(Array) ? permissions : [permissions]
        permissions = global_permissions - permissions

        set_global_permissions(permissions)
      end

      # Set the group permissions to the given +permissions+.
      def set_global_permissions!(permissions)
        request = XmlRequest.prepare do |xml|
          xml.where_key_tag!(base_name, self.class.primary_key, name)
          xml.set_key_tag!(base_name, self.class.xml_attribute(:global_permissions).name, permissions)
        end

        request.execute!

        self.global_permissions = permissions
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
infopark_reactor-1.29.1 lib/reactor/cm/permissions.rb
infopark_reactor-1.29.0 lib/reactor/cm/permissions.rb
infopark_reactor-1.28.0 lib/reactor/cm/permissions.rb
infopark_reactor-1.27.0.rc10 lib/reactor/cm/permissions.rb
infopark_reactor-1.27.0.rc9 lib/reactor/cm/permissions.rb
infopark_reactor-1.27.0.rc8 lib/reactor/cm/permissions.rb
infopark_reactor-1.27.0.rc7 lib/reactor/cm/permissions.rb
infopark_reactor-1.27.0.rc4 lib/reactor/cm/permissions.rb