Class: Ddr::Auth::Groups

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/ddr/auth/groups.rb

Constant Summary collapse

Public =
Group.build("public")
Registered =
Group.build("registered")
DukeEppn =
Group.build("duke.all")
Superusers =
Group.build("superusers")
CollectionCreators =
Group.build("collection_creators")
ISMEMBEROF_RE =
Regexp.new('urn:mace:duke\.edu:groups:library:repository:ddr:[\w:]+')
DUKE_EPPN_RE =
Regexp.new('(?=@duke\.edu)')
AFFILIATION_RE =
Regexp.new('(%{a})(?=@duke\.edu)' % {a: Affiliation::VALUES.join("|")})

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, env = nil) ⇒ Groups

Returns a new instance of Groups.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ddr/auth/groups.rb', line 36

def initialize(user, env=nil)
  @user = user
  @env = env
  groups = [ Public ] # everybody 
  if user.persisted?
    groups << Registered 
    groups << DukeEppn if duke_eppn?
    groups.concat(remote)
    groups.concat(affiliation)
  end
  super(groups)
  self << Superusers if names.include?(Ddr::Auth.superuser_group)
  self << CollectionCreators if names.include?(Ddr::Auth.collection_creators_group)
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



34
35
36
# File 'lib/ddr/auth/groups.rb', line 34

def env
  @env
end

#userObject (readonly)

Returns the value of attribute user.



34
35
36
# File 'lib/ddr/auth/groups.rb', line 34

def user
  @user
end

Class Method Details

.allArray<Group>

Return the list of all groups available for use in the repository

Returns:

  • (Array<Group>)

    the groups



21
22
23
# File 'lib/ddr/auth/groups.rb', line 21

def all
  Affiliation.groups + remote + [Public, Registered, DukeEppn]
end

.grouperObject



29
30
31
# File 'lib/ddr/auth/groups.rb', line 29

def grouper
  Ddr::Auth.grouper_gateway.new
end

.remoteObject



25
26
27
# File 'lib/ddr/auth/groups.rb', line 25

def remote
  grouper.repository_group_names.map { |name| Group.build(name) }
end

Instance Method Details

#inspectObject



51
52
53
# File 'lib/ddr/auth/groups.rb', line 51

def inspect
  "#<#{self.class.name} user=\"#{user}\", env=#{env ? '[YES]' : '[NO]'}, groups=#{names.inspect}>"
end

#namesArray<String>

Return a list of the group names

Returns:

  • (Array<String>)

    the names



61
62
63
# File 'lib/ddr/auth/groups.rb', line 61

def names
  map(&:to_s)
end

#to_sObject



55
56
57
# File 'lib/ddr/auth/groups.rb', line 55

def to_s
  names.to_s
end