class Acl::Group

Overview

The Group is identified by a name and has permissions on a set of paths. It is used by Groups.

NOTE I did not used Hash().new(default) because it is annoying with passing the permissions in the constructor

Included Modules

Defined in:

lib/acl/group.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) #

[View source]
def self.new(name : String, permissions : Hash(String, Acl::Perm), default : Acl::Perm = Acl::Perm::None) #
guest = Acl::Group.new(name: "guest", default: Acl::Perm::None, permissions: {"/public" => Acl::Perm::Read})
user = Acl::Group.new(name: "user", default: Acl::Perm::Read, permissions: {"/protected" => Acl::Perm::None})
admin = Acl::Group.new(name: "admin", default: Acl::Perm::Write)

[View source]
def self.new(name : String, permissions : Hash(Acl::Path, Acl::Perm) = Hash(Acl::Path, Acl::Perm).new, default : Acl::Perm = Acl::Perm::None) #

Create a new named Group with optional parameters.

  • name is the name of the group (arbitrary String).
  • permissions is a hash of {Acl::Path.new("path") => `Perm`}.
  • default is the value used for every path not defined in the permissions.
guest = Acl::Group.new(name: "guest", default: Acl::Perm::None, permissions: {Acl::Path.new "/public" => Acl::Perm::Read})
user = Acl::Group.new(name: "user", default: Acl::Perm::Read, permissions: {Acl::Path.new "/protected" => Acl::Perm::None})
admin = Acl::Group.new(name: "admin", default: Acl::Perm::Write)

[View source]

Instance Method Detail

def [](path : String) : Acl::Perm #

Same than Path[String]? but returns the defaut value if not found


[View source]
def []=(path : String, acl : Acl::Perm) #

If a path exists, replace it with the given permission acl, else create it.


[View source]
def []?(path : String) : Acl::Perm | Nil #

Tries to find the exact path with the permissions of this group.


[View source]
def default : Acl::Perm #

[View source]
def default=(default : Acl::Perm) #

[View source]
def delete(path : String) #

Remove the permissions associated to the path


[View source]
def matching(path : String) : Acl::Perm #

Same than Path[String]? but returns the defaut value if not found


[View source]
def matching?(path : String) : Acl::Perm | Nil #

Tries to match the path with the permissions of this group. If select every matching path and get the maximum permission among them.


[View source]
def name : String #

[View source]
def name=(name : String) #

[View source]
def permissions : Hash(Acl::Path, Acl::Perm) #

[View source]
def permissions=(permissions : Hash(Acl::Path, Acl::Perm)) #

[View source]
def permitted?(path : String, access : Acl::Perm) : Bool #

Check if the group as the Acl::Perm required to have access to a given path.

  • path is the path that must be checked
  • access is the minimal Acl::Perm required for a given operation
guest = Acl::Group.new(name: "guest", default: Acl::Perm::None, permissions: {"/public" => Acl::Perm::Read})
guest.permitted "/public", Acl::Perm::Read  # => true
guest.permitted "/public", Acl::Perm::Write # => false
guest.permitted "/other", Acl::Perm::Read   # => false

[View source]